UserController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Http\Controllers\WapAlipay\User;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\WapAlipay\BaseController;
  5. use App\Modules\Subscribe\Services\YearOrderService;
  6. use App\Modules\User\Services\UserService;
  7. use App\Modules\User\Services\UserSignService;
  8. use App\Http\Controllers\WapAlipay\User\Transformers\SignRecordTransformer;
  9. use Log;
  10. use Redis;
  11. use Cookie;
  12. use DB;
  13. class UserController extends BaseController
  14. {
  15. /**
  16. * @apiDefine User 用户
  17. */
  18. /**
  19. * @apiVersion 1.0.0
  20. * @apiDescription 获取用户信息
  21. * @api {GET} userinfo 获取用户信息
  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. if(!$this->checkUid()){
  59. return response()->error('NOT_LOGIN');
  60. }
  61. $data = UserService::getById($this->uid);
  62. $data['is_vip'] = 0;
  63. $data['vip_days'] = 0;
  64. $year_record = YearOrderService::getRecord($this->uid);
  65. if($year_record){
  66. $data['is_vip'] = 1;
  67. $time = strtotime($year_record['end_time'])-time();
  68. if($time>=86400){
  69. $data['vip_days'] = floor($time/86400).'天';
  70. }elseif ($time>3600) {
  71. $data['vip_days'] = floor($time/3600).'小时';
  72. }elseif ($time>60) {
  73. $data['vip_days'] = floor($time/60).'分钟';
  74. }else{
  75. $data['vip_days'] = $time.'秒';
  76. }
  77. }
  78. return response()->success($data);
  79. }
  80. /**
  81. * @apiVersion 1.0.0
  82. * @apiDescription 用户签到记录
  83. * @api {GET} user/sign_record 用户签到记录
  84. * @apiGroup User
  85. * @apiName signRecord
  86. * @apiSuccess {int} code 状态码
  87. * @apiSuccess {String} msg 信息
  88. * @apiSuccess {object} data 结果集
  89. * @apiSuccess {reward} data.reward 奖励金额.
  90. * @apiSuccess {sign_time} data.sign_time 签到时间.
  91. * @apiParam {page} page
  92. * @apiSuccessExample {json} Success-Response:
  93. *
  94. * {
  95. * code: 0,
  96. * msg: "",
  97. * data: {
  98. * list: [
  99. * {
  100. * reward: 50,
  101. * sign_time: "2018-03-20 13:43:11"
  102. * },
  103. * {
  104. * reward: 50,
  105. * sign_time: "2018-01-18 16:22:33"
  106. * },
  107. * ],
  108. * meta: {
  109. * total: 12,
  110. * per_page: 15,
  111. * current_page: 1,
  112. * last_page: 1,
  113. * next_page_url: "",
  114. * prev_page_url: ""
  115. * }
  116. * }
  117. * }
  118. */
  119. public function signRecord(Request $request){
  120. return response()->pagination(new SignRecordTransformer(),UserSignService::getUserSignRecord($this->uid));
  121. }
  122. public function getCoupons(Request $request){
  123. $activity_id = $request->input('activity_id');
  124. if(!DB::table('discount_coupons')->where('uid',$this->uid)->where('activity_id',$activity_id)->count()){
  125. DB::table('discount_coupons')->insert([
  126. 'uid'=>$this->uid,
  127. 'activity_id'=>$activity_id,
  128. 'created_at'=>date('Y-m-d H:i:s'),
  129. 'updated_at'=>date('Y-m-d H:i:s')
  130. ]);
  131. }
  132. return response()->success();
  133. }
  134. function logout()
  135. {
  136. setcookie(env('COOKIE_AUTH_WEB_WECHAT'), '', -1);
  137. setcookie('u', '', -1);
  138. return response('logout');
  139. }
  140. }