UserController.php 3.4 KB

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