UserController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $data = UserService::getById($this->uid);
  58. if(!$data->head_img){
  59. $data->head_img = 'https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/defaulthead.png';
  60. }
  61. $data['is_vip'] = 0;
  62. $data['vip_days'] = 0;
  63. $year_record = YearOrderService::getRecord($this->uid);
  64. if($year_record){
  65. $data['is_vip'] = 1;
  66. $time = strtotime($year_record['end_time'])-time();
  67. if($time>=86400){
  68. $data['vip_days'] = floor($time/86400).'天';
  69. }elseif ($time>3600) {
  70. $data['vip_days'] = floor($time/3600).'小时';
  71. }elseif ($time>60) {
  72. $data['vip_days'] = floor($time/60).'分钟';
  73. }else{
  74. $data['vip_days'] = $time.'秒';
  75. }
  76. }
  77. return response()->success($data);
  78. }
  79. function logout()
  80. {
  81. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  82. setcookie('u', '', -1);
  83. return response('logout');
  84. }
  85. }