UserController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Http\Controllers\KuaiYingYong\User;
  3. use App\Http\Controllers\KuaiYingYong\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. if(!$this->checkUid()){
  58. return response()->error('XCX_NOT_LOGIN');
  59. }
  60. $data = UserService::getById($this->uid);
  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. function logout()
  83. {
  84. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  85. setcookie('u', '', -1);
  86. return response('logout');
  87. }
  88. }