UserController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace General\Controllers\CompanyAuth;
  3. use App\Http\Controllers\Controller;
  4. use General\Controllers\CompanyAuth\Transformers\SubScribeRecordTransformer;
  5. use General\Controllers\CompanyAuth\Transformers\UserTransformer;
  6. use General\Requests\CompanyAuth\ChannelQueryRequest;
  7. use General\Services\User\UserService;
  8. class UserController extends Controller
  9. {
  10. /**
  11. * @apiDefine User 用户信息
  12. */
  13. /**
  14. * @api {post} company/auth/users 用户信息
  15. * @apiVersion 1.0.0
  16. * @apiName users
  17. * @apiGroup User
  18. * @apiParam {String} channel_id 站点id
  19. * @apiParam {Int} page 分页页码
  20. * @apiParam {String} app_id 分配好的{app_id}
  21. * @apiParam {String} nonce_str 随机字符串
  22. * @apiParam {String} timestamp 时间戳
  23. * @apiParam {String} uid (可以不传) 用户uid,','分隔;最多不超过100个
  24. * @apiParam {String} start_time (可以不传) 开始时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
  25. * @apiParam {String} end_time (可以不传) 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
  26. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  27. * @apiSuccess {int} code 状态码
  28. * @apiSuccess {String} msg 信息
  29. * @apiSuccess {Object} data 结果集
  30. * @apiSuccess {Object} list 数据结果
  31. * @apiSuccess {Object} meta 分页信息
  32. * @apiSuccess {Int} total 分页总数
  33. * @apiSuccess {Int} id 用户id
  34. * @apiSuccess {Int} channel_id 站点ID
  35. * @apiSuccess {String} app_id 关注app_id
  36. * @apiSuccess {String} opend_id 关注open_id
  37. * @apiSuccess {String} register_openid 注册open_id
  38. * @apiSuccess {String} ua 用户user_agent
  39. * @apiSuccess {String} register_ip 注册IP
  40. * @apiSuccess {String} register_time 注册时间
  41. * @apiSuccess {String} subscribe_time 关注时间
  42. * @apiSuccess {String} is_subscribed 是否关注(1.已关注 0.未关注)
  43. * @apiSuccess {String} nickname 用户昵称
  44. * @apiSuccess {String} balance 总书币
  45. * @apiSuccess {String} sex 性别
  46. * @apiSuccessExample {json} Success-Response:
  47. * HTTP/1.1 200 OK
  48. *{
  49. * "code": 0,
  50. * "msg": "",
  51. * "data": {
  52. * "list": [
  53. * {
  54. * "id": 7475378,
  55. * "channel_id": 166,
  56. * "app_id": null,
  57. * "opend_id": "oq6ID0ovAjyxnWZRbm3YPz8Pz8nE",
  58. * "register_time": "2018-03-20 00:00:08",
  59. * "subscribe_time": "",
  60. * "nickname": "用户昵称"
  61. * }
  62. * ],
  63. * "meta": {
  64. * "total": 1,
  65. * "per_page": 100,
  66. * "current_page": 1,
  67. * "last_page": 1,
  68. * "next_page_url": "",
  69. * "prev_page_url": ""
  70. * }
  71. * }
  72. *}
  73. */
  74. public function users(ChannelQueryRequest $request)
  75. {
  76. $channel_id = $request->get('channel_id');
  77. $uid_str = $request->get('uid', '');
  78. $start_time = $request->get('start_time', '');
  79. $end_time = $request->get('end_time', '');
  80. $service = new UserService;
  81. if ($uid_str) {
  82. $uids = explode(',', $uid_str);
  83. $uids = count($uids) > 100 ? collect($uids)->take(100) : $uids;
  84. $result = $service->companyAuthUsers($channel_id, $start_time, $end_time, $uids);
  85. } else {
  86. $result = $service->companyAuthUsers($channel_id, $start_time, $end_time);
  87. }
  88. return response()->pagination(new UserTransformer, $result);
  89. }
  90. /**
  91. * @api {post} company/auth/users/subscribes 用户关注记录
  92. * @apiVersion 1.0.0
  93. * @apiName subscribeRecords
  94. * @apiGroup User
  95. * @apiParam {String} channel_id 站点id
  96. * @apiParam {String} uid 用户uid,','分隔;最多不超过100个
  97. * @apiParam {Int} page 分页页码
  98. * @apiParam {String} app_id 分配好的{app_id}
  99. * @apiParam {String} nonce_str 随机字符串
  100. * @apiParam {String} timestamp 时间戳
  101. * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
  102. * @apiSuccess {int} code 状态码
  103. * @apiSuccess {String} msg 信息
  104. * @apiSuccess {Object} data 结果集
  105. * @apiSuccess {Object} list 数据结果
  106. * @apiSuccess {Object} meta 分页信息
  107. * @apiSuccess {Int} total 分页总数
  108. * @apiSuccess {Int} uid 用户ID
  109. * @apiSuccess {Int} distribution_channel_id 站点ID
  110. * @apiSuccess {String} appid 关注app_id
  111. * @apiSuccess {String} openid 关注open_id
  112. * @apiSuccess {Int} is_subscribed 是否关注
  113. * @apiSuccess {String} subscribe_time 关注时间
  114. * @apiSuccess {String} unsubscribe_time 取关时间
  115. * @apiSuccessExample {json} Success-Response:
  116. * HTTP/1.1 200 OK
  117. *{
  118. * "code": 0,
  119. * "msg": "",
  120. * "data": {
  121. * "list": [
  122. * {
  123. * "id": 7475378,
  124. * "channel_id": 166,
  125. * "app_id": null,
  126. * "opend_id": "oq6ID0ovAjyxnWZRbm3YPz8Pz8nE",
  127. * "register_time": "2018-03-20 00:00:08",
  128. * "subscribe_time": ""
  129. * }
  130. * ],
  131. * "meta": {
  132. * "total": 1,
  133. * "per_page": 100,
  134. * "current_page": 1,
  135. * "last_page": 1,
  136. * "next_page_url": "",
  137. * "prev_page_url": ""
  138. * }
  139. * }
  140. *}
  141. */
  142. public function subscribeRecords(ChannelQueryRequest $request)
  143. {
  144. $uid_str = $request->get('uid', '');
  145. $channel_id = $request->get('channel_id');
  146. $result = [];
  147. if ($uid_str) {
  148. $uids = explode(',', $uid_str);
  149. $uids = count($uids) > 100 ? collect($uids)->take(100) : $uids;
  150. $service = new UserService;
  151. $result = $service->findSubscribeRecords($channel_id, $uids);
  152. }
  153. return response()->pagination(new SubScribeRecordTransformer, $result);
  154. }
  155. }