UserController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 App\Modules\User\Services\UserSignService;
  8. use Log;
  9. use Redis;
  10. use Cookie;
  11. use GuzzleHttp\Psr7\Request;
  12. class UserController extends BaseController
  13. {
  14. /**
  15. * @apiDefine User 用户
  16. */
  17. /**
  18. * @apiVersion 1.0.0
  19. * @apiDescription 获取用户信息
  20. * @api {GET} userinfo 获取用户信息
  21. * @apiHeader {String} [Authorization] 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. /**
  82. * @apiVersion 1.0.0
  83. * @apiDescription 用户签到
  84. * @api {GET} sign 用户签到
  85. * @apiHeader {String} [Authorization] token
  86. * @apiGroup User
  87. * @apiName sign
  88. * @apiSuccessExample {json} Success-Response:
  89. *
  90. * {
  91. * "code": 0,
  92. * "msg": "",
  93. * "data": {
  94. * }
  95. * }
  96. */
  97. public function sign(Request $request)
  98. {
  99. if (UserSignService::isSign($this->uid)) {
  100. return response()->error('QAPP_CHECKED_IN');
  101. }
  102. if (UserSignService::signV2($this->uid, date('Y-m-d'))) {
  103. return response()->success();
  104. }
  105. return response()->error('QAPP_SYS_ERROR');
  106. }
  107. }