ChannelUserController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace App\Http\Controllers\Manage\Channel;
  3. use App\Http\Controllers\Manage\BaseController;
  4. use App\Http\Controllers\Manage\Channel\Transformers\ChannelUserTransformer;
  5. use App\Modules\Channel\Services\ChannelUserService;
  6. use App\Modules\Channel\Services\CompanyService;
  7. use Illuminate\Http\Request;
  8. /**
  9. * Class ChannelUserController 渠道
  10. * @package App\Http\Controllers\Manage\Channel
  11. */
  12. class ChannelUserController extends BaseController
  13. {
  14. /**
  15. * @apiDefine channel 渠道
  16. */
  17. /**
  18. * @apiVersion 1.0.0
  19. * @apiDescription 更新渠道信息新
  20. * @api {POST} channel/updateChannelUserInfo 更新渠道信息新
  21. * @apiGroup channel
  22. * @apiName channel/updateChannelUserInfo
  23. * @apiParam {Number} distribution_channel_id 渠道id
  24. * @apiParam {String} [name] 渠道名称
  25. * @apiParam {String} [nickname] 渠道昵称
  26. * @apiParam {Number} [pay_merchant_id] 渠道支付通道
  27. * @apiParam {Number} [distribution_manages_id] 渠道管理员
  28. * @apiParam {String} [phone] 渠道电话
  29. * @apiParam {String} [person_in_charge_name] 渠道负责人
  30. * @apiParam {String} [remark] 备注
  31. * @apiParam {Number} [is_enabled] 是否开通 0:未审核; 1:审核通过
  32. * @apiParam {Number} [company_id] 设置公司
  33. *
  34. * @apiSuccess {Number} id 渠道ID.
  35. * @apiSuccess {String} phone 手机号码.
  36. * @apiSuccess {String} name 渠道名称.
  37. * @apiSuccess {String} pay_merchant 支付商户.
  38. * @apiSuccess {String} nickname 昵称.
  39. * @apiSuccess {String} password 密码.
  40. * @apiSuccess {String} latest_login_time 最后登陆时间.
  41. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  42. * @apiSuccess {String} remark 备注.
  43. * @apiSuccess {String} register_ip 注册IP.
  44. * @apiSuccessExample {json} Success-Response:
  45. *
  46. * {
  47. * "code": 0,
  48. * "msg": "",
  49. * "data":
  50. * {
  51. * "id": 1,
  52. * "phone": "1586810210",
  53. * "name": "分销1",
  54. * "pay_merchant": "ALLINPAY_NALAN",
  55. * "nickname": "昵称",
  56. * "password": "34sdfsdfdsf23",
  57. * "latest_login_time": "2017-12-12 12:12:12",
  58. * "latest_login_ip": "56.3.21.2",
  59. * "remark": "啦啦啦",
  60. * "register_ip": "123.25.21.21",
  61. * }
  62. *
  63. * }
  64. */
  65. function updateChannelData(Request $request)
  66. {
  67. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  68. if (empty(ChannelUserService::getById($distribution_channel_id))) {
  69. return response()->error('PARAM_ERROR');
  70. }
  71. $distribution_channel_name = $request->has('distribution_channel_name') ? $request->input('distribution_channel_name') : '';
  72. $nickname = $request->has('nickname') ? $request->input('nickname') : '';
  73. $pay_merchant_id = $request->has('pay_merchant_id') ? $request->input('pay_merchant_id') : '';
  74. $phone = $request->has('phone') ? $request->input('phone') : '';
  75. $person_in_charge_name = $request->has('person_in_charge_name') ? $request->input('person_in_charge_name') : '';
  76. $remark = $request->has('remark') ? $request->input('remark') : '';
  77. $distribution_manages_id = $request->has('distribution_manages_id') ? $request->input('distribution_manages_id') : '';
  78. $isEnabled = $request->has('is_enabled') ? $request->input('is_enabled') : '';
  79. $params = [
  80. 'name' => $distribution_channel_name,
  81. 'nickname' => $nickname,
  82. 'pay_merchant_id' => $pay_merchant_id,
  83. 'phone' => $phone,
  84. 'person_in_charge_name' => $person_in_charge_name,
  85. 'distribution_manages_id' => $distribution_manages_id,
  86. 'remark' => $remark,
  87. 'is_enabled' => $isEnabled,
  88. ];
  89. $company_id = $request->has('company_id') ? $request->input('company_id') : '';
  90. if ($company_id) {
  91. $company = CompanyService::getCompany($company_id);
  92. if ($company) {
  93. $params['company_id'] = $company->id;
  94. $params['company_name'] = $company->name;
  95. }
  96. }
  97. $channel = ChannelUserService::updateChannelData($distribution_channel_id, $params);
  98. return response()->item(new ChannelUserTransformer(), $channel);
  99. }
  100. /**
  101. * @apiVersion 1.0.0
  102. * @apiDescription 获取渠道列表新
  103. * @api {GET} channel/getChannelUserList 获取渠道列表新
  104. * @apiGroup channel
  105. * @apiName channel/getChannelUserList
  106. * @apiParam {Number} [distribution_channel_id] 渠道id.(可不传,获取所有渠道)
  107. * @apiParam {String} [distribution_channel_name] 渠道名称.(可不传,获取所有渠道)
  108. * @apiParam {String} [search_name] 搜索名称
  109. * @apiParam {String} [phone] 搜索手机号码
  110. * @apiParam {String} [start_time] 开始时间(可不传)
  111. * @apiParam {String} [end_time] 结束时间(可不传)
  112. * @apiParam {Number} [is_enabled] 0:待审核; 1:已审核.(可不传)
  113. * @apiParam {Number} [distribution_manages_id] 管理员ID.(可不传)
  114. * @apiParam {Number} [company_id] 公司ID.(可不传)
  115. * @apiParam {Number} [is_important] 公司是否重要
  116. * @apiParam {String} [orderByDesc] 排序字段.(可不传)['nickname', 'phone', 'create_time', 'company_id']
  117. *
  118. * @apiSuccess {Number} id 渠道ID.
  119. * @apiSuccess {String} name 渠道名称.
  120. * @apiSuccess {String} phone 手机号码.
  121. * @apiSuccess {String} pay_merchant 支付商户.
  122. * @apiSuccess {String} nickname 昵称.
  123. * @apiSuccess {String} latest_login_time 最后登陆时间.
  124. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  125. * @apiSuccess {String} remark 备注.
  126. * @apiSuccess {String} register_ip 注册IP.
  127. * @apiSuccess {String} person_in_charge_name 负责人.
  128. * @apiSuccess {String} create_time 注册时间
  129. * @apiSuccess {Number} distribution_manages_id 管理员ID
  130. * @apiSuccess {String} distribution_manages_account 管理员
  131. * @apiSuccess {String} distribution_manages_number 管理员
  132. * @apiSuccess {String} distribution_manages_nickname 管理员昵称
  133. * @apiSuccessExample {json} Success-Response:
  134. *
  135. * {
  136. * "code": 0,
  137. * "msg": "",
  138. * "data": [
  139. * {
  140. * "id": 1,
  141. * "phone": "",
  142. * "name": "121",
  143. * "pay_merchant_id": 1,
  144. * "nickname": "是说",
  145. * "latest_login_time": "",
  146. * "latest_login_ip": "",
  147. * "is_enabled": 1,
  148. * "register_ip": "",
  149. * "remark": "",
  150. * "person_in_charge_name": "波哥帅",
  151. * "create_time": "2017-11-20 18:34:17",
  152. * "distribution_manages_id": 0,
  153. * "distribution_manages_account": null,
  154. * "distribution_manages_number": null,
  155. * "distribution_manages_nickname": null
  156. * }
  157. * ]
  158. * }
  159. */
  160. function getList(Request $request)
  161. {
  162. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  163. $distribution_channel_name = $request->has('distribution_channel_name') ? $request->input('distribution_channel_name') : '';
  164. $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? date('Ymd', strtotime($request->input('start_time'))) : '';
  165. $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Ymd', strtotime($request->input('end_time'))) : '';
  166. $distribution_manages_id = $request->has('distribution_manages_id') ? $request->input('distribution_manages_id') : '';
  167. $company_id = $request->has('company_id') ? $request->input('company_id') : '';
  168. $is_important = $request->input('is_important');
  169. $isEnabled = $request->has('is_enabled') ? $request->input('is_enabled') : '';
  170. $search_name = $request->has('search_name') ? $request->input('search_name') : '';
  171. $phone = $request->has('phone') ? $request->input('phone') : '';
  172. $orderByDesc = $request->has('orderByDesc') ? $request->input('orderByDesc') : '';
  173. //商务,只获取到当前商务下的渠道列表
  174. if ($this->getLoginUserRole() == "business") {
  175. $distribution_manages_id = $this->getLoginUserId();
  176. }
  177. $params = [
  178. 'channel_id' => $distribution_channel_id,
  179. 'channel_name' => $distribution_channel_name,
  180. 'start_date' => $start_time,
  181. 'end_date' => $end_time,
  182. 'distribution_manages_id' => $distribution_manages_id,
  183. 'is_enabled' => $isEnabled,
  184. 'search_name' => $search_name,
  185. 'phone' => $phone,
  186. 'orderByDesc' => $orderByDesc,
  187. 'company_id' => $company_id,
  188. 'is_important' => $is_important,
  189. ];
  190. $result = ChannelUserService::getChannelList($params);
  191. return response()->pagination(new ChannelUserTransformer(), $result);
  192. }
  193. /**
  194. * @apiVersion 1.0.0
  195. * @apiDescription 获取所有渠道列表新
  196. * @api {GET} channel/getChannelAllUserList 获取所有渠道列表新
  197. * @apiGroup channel
  198. * @apiName channel/getChannelAllUserList
  199. *
  200. * @apiSuccess {Number} id 渠道ID.
  201. * @apiSuccess {String} name 渠道名称.
  202. * @apiSuccess {String} phone 手机号码.
  203. * @apiSuccess {String} pay_merchant 支付商户.
  204. * @apiSuccess {String} nickname 昵称.
  205. * @apiSuccess {String} latest_login_time 最后登陆时间.
  206. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  207. * @apiSuccess {String} remark 备注.
  208. * @apiSuccess {String} register_ip 注册IP.
  209. * @apiSuccess {String} person_in_charge_name 负责人.
  210. * @apiSuccess {String} create_time 注册时间
  211. * @apiSuccess {Number} distribution_manages_id 管理员ID
  212. * @apiSuccess {String} distribution_manages_account 管理员
  213. * @apiSuccess {String} distribution_manages_number 管理员
  214. * @apiSuccess {String} distribution_manages_nickname 管理员昵称
  215. * @apiSuccessExample {json} Success-Response:
  216. *
  217. * {
  218. * "code": 0,
  219. * "msg": "",
  220. * "data": [
  221. * {
  222. * "id": 1,
  223. * "phone": "",
  224. * "name": "121",
  225. * "pay_merchant_id": 1,
  226. * "nickname": "是说",
  227. * "latest_login_time": "",
  228. * "latest_login_ip": "",
  229. * "is_enabled": 1,
  230. * "register_ip": "",
  231. * "remark": "",
  232. * "person_in_charge_name": "波哥帅",
  233. * "create_time": "2017-11-20 18:34:17",
  234. * "distribution_manages_id": 0,
  235. * "distribution_manages_account": null,
  236. * "distribution_manages_number": null,
  237. * "distribution_manages_nickname": null
  238. * }
  239. * ]
  240. * }
  241. */
  242. function getAllList(Request $request)
  243. {
  244. $isEnabled = 1;
  245. $params = [
  246. 'is_enabled' => $isEnabled,
  247. ];
  248. $result = ChannelUserService::getChannelList($params, true);
  249. return response()->collection(new ChannelUserTransformer(), $result);
  250. }
  251. }