UserController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\User;
  3. use App\Http\Controllers\QuickApp\BaseController;
  4. use App\Modules\Subscribe\Services\YearOrderService;
  5. use App\Modules\User\Transformers\YearOrderTransformer;
  6. use App\Modules\User\Services\UserService;
  7. use Log;
  8. use Redis;
  9. use Cookie;
  10. use GuzzleHttp\Psr7\Request;
  11. class UserController extends BaseController
  12. {
  13. /**
  14. * @apiDefine User 用户
  15. */
  16. /**
  17. * @apiVersion 1.0.0
  18. * @apiDescription 获取用户信息
  19. * @api {GET} userinfo 获取用户信息
  20. * @apiParam {String} [token] token
  21. * @apiHeader {String} [Authorization] token 两个token任选其一
  22. * @apiGroup User
  23. * @apiName index
  24. * @apiSuccess {Number} id 用户ID.
  25. * @apiSuccess {String} openid 微信openid.
  26. * @apiSuccess {String} unionid 微信unionid.
  27. * @apiSuccess {Number} distribution_channel_id 分销渠道ID.
  28. * @apiSuccess {String} province 省份.
  29. * @apiSuccess {String} city 城市.
  30. * @apiSuccess {String} country 国家.
  31. * @apiSuccess {String} headimgurl 头像地址.
  32. * @apiSuccess {Number} send_order_id 派单ID.
  33. * @apiSuccess {Number=0,1} sex 性别.
  34. * @apiSuccess {String} balance 书币余额.
  35. * @apiSuccess {Int} is_vip 是否vip
  36. * @apiSuccess {String} vip_days 364天.
  37. * @apiSuccessExample {json} Success-Response:
  38. *
  39. * {
  40. * "code": 0,
  41. * "msg": "",
  42. * "data": {
  43. * "id": 56,
  44. * "openid": "sdfs34ssdfdsf",
  45. * "unionid": "SDFSD3343S",
  46. * "distribution_channel_id": 1212,
  47. * "province": "浙江省",
  48. * "city": "杭州",
  49. * "country": "中国",
  50. * "headimgurl": "http://.."
  51. * "send_order_id": 323
  52. * "balance": 8956
  53. * "register_time": "2017-12-12 12:12:12"
  54. * }
  55. * }
  56. */
  57. public function index()
  58. {
  59. $data = $this->user_info;
  60. if (!$data->head_img) {
  61. $data->head_img = 'https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/defaulthead.png';
  62. }
  63. $data['is_vip'] = 0;
  64. $data['vip_days'] = 0;
  65. $year_record = YearOrderService::getRecord($this->uid);
  66. if ($year_record) {
  67. $data['is_vip'] = 1;
  68. $time = strtotime($year_record['end_time']) - time();
  69. if ($time >= 86400) {
  70. $data['vip_days'] = floor($time / 86400) . '天';
  71. } elseif ($time > 3600) {
  72. $data['vip_days'] = floor($time / 3600) . '小时';
  73. } elseif ($time > 60) {
  74. $data['vip_days'] = floor($time / 60) . '分钟';
  75. } else {
  76. $data['vip_days'] = $time . '秒';
  77. }
  78. }
  79. return response()->success($data);
  80. }
  81. public function sign(Request $request)
  82. {
  83. }
  84. }