UserController.php 3.2 KB

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