UserController.php 2.8 KB

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