ChannelsController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. namespace App\Http\Controllers\Manage\Channel;
  3. use App\Http\Controllers\Manage\BaseController;
  4. use App\Http\Controllers\Manage\Channel\Transformers\ChannelTransformer;
  5. use App\Modules\Channel\Models\Channel;
  6. use App\Modules\Channel\Services\ChannelService;
  7. use Illuminate\Http\Request;
  8. /**
  9. * Class ChannelsController 渠道
  10. * @package App\Http\Controllers\Manage\Channel
  11. */
  12. class ChannelsController extends BaseController
  13. {
  14. /**
  15. * @apiDefine channel 渠道
  16. */
  17. /**
  18. * @apiVersion 1.0.0
  19. * @apiDescription 获取所有渠道
  20. * @api {GET} channel/getChannelList 获取所有渠道
  21. * @apiGroup channel
  22. * @apiName getChannelList
  23. * @apiParam {Number} [channel_user_id] 账户ID
  24. * @apiSuccess {Number} id 渠道ID.
  25. * @apiSuccess {String} name 渠道名称.
  26. * @apiSuccess {String} phone 手机号码.
  27. * @apiSuccess {String} pay_merchant 支付商户.
  28. * @apiSuccess {String} nickname 昵称.
  29. * @apiSuccess {String} password 密码.
  30. * @apiSuccess {String} latest_login_time 最后登陆时间.
  31. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  32. * @apiSuccess {String} remark 备注.
  33. * @apiSuccess {String} register_ip 注册IP.
  34. * @apiSuccessExample {json} Success-Response:
  35. *
  36. * {
  37. * "code": 0,
  38. * "msg": "",
  39. * "data": [
  40. * {
  41. * "id": 1,
  42. * "name": "分销1",
  43. * "phone": "1586810210",
  44. * "pay_merchant": "ALLINPAY_NALAN",
  45. * "nickname": "昵称",
  46. * "password": "34sdfsdfdsf23",
  47. * "latest_login_time": "2017-12-12 12:12:12",
  48. * "latest_login_ip": "56.3.21.2",
  49. * "remark": "啦啦啦",
  50. * "register_ip": "123.25.21.21",
  51. * }
  52. * ]
  53. * }
  54. */
  55. function getChannelList(Request $request)
  56. {
  57. $channel_user_id = $request->has('channel_user_id') ? $request->input('channel_user_id') : '';
  58. $params = [
  59. 'channel_user_id' => $channel_user_id,
  60. ];
  61. $channelList = ChannelService::getAllChannels($params);
  62. return response()->collection(new ChannelTransformer(), $channelList);
  63. }
  64. /**
  65. * @apiVersion 1.0.0
  66. * @apiDescription 创建渠道
  67. * @api {POST} channel/createChannel 创建渠道
  68. * @apiGroup channel
  69. * @apiName createChannel
  70. * @apiSuccess {Number} id 渠道ID.
  71. * @apiParam {String} [name] 渠道名称.
  72. * @apiParam {String} [pay_merchant] 支付商户.
  73. * @apiParam {String} [nickname] 昵称.
  74. * @apiParam {String} phone 手机号码.
  75. * @apiParam {String} password 密码.
  76. * @apiParam {String} [latest_login_time] 最后登陆时间.
  77. * @apiParam {String} [latest_login_ip] 最后登陆IP.
  78. * @apiParam {String} [remark] 备注.
  79. * @apiParam {String} [register_ip] 注册IP.
  80. * @apiSuccess {String} name 渠道名称.
  81. * @apiSuccess {String} phone 手机号码.
  82. * @apiSuccess {String} pay_merchant 支付商户.
  83. * @apiSuccess {String} nickname 昵称.
  84. * @apiSuccess {String} password 密码.
  85. * @apiSuccess {String} latest_login_time 最后登陆时间.
  86. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  87. * @apiSuccess {String} remark 备注.
  88. * @apiSuccess {String} register_ip 注册IP.
  89. * @apiSuccessExample {json} Success-Response:
  90. *
  91. * {
  92. * "code": 0,
  93. * "msg": "",
  94. * "data":
  95. * {
  96. * "id": 1,
  97. * "phone": "1586810210",
  98. * "name": "分销1",
  99. * "pay_merchant": "ALLINPAY_NALAN",
  100. * "nickname": "昵称",
  101. * "password": "34sdfsdfdsf23",
  102. * "latest_login_time": "2017-12-12 12:12:12",
  103. * "latest_login_ip": "56.3.21.2",
  104. * "remark": "啦啦啦",
  105. * "register_ip": "123.25.21.21",
  106. * }
  107. *
  108. * }
  109. */
  110. function create(Request $request)
  111. {
  112. $name = $request->has('name') ? trim($request->input('name')) : '';
  113. $pay_type = $request->has('pay_type') ? trim($request->input('pay_type')) : 'ALLINPAY_NALAN';
  114. $phone = $request->has('phone') ? trim($request->input('phone')) : '';
  115. $password = $request->has('password') ? trim($request->input('password')) : '';
  116. $nickname = $request->has('nickname') ? trim($request->input('nickname')) : '';
  117. $latest_login_time = date("Y-m-d H:i:s");
  118. $remark = $request->has('remark') ? trim($request->input('remark')) : '';
  119. $latest_login_ip = $register_ip = $request->has('register_ip') ? trim($request->input('register_ip')) : '';
  120. if(!$phone || !$password) return response()->error('PARAM_ERROR');
  121. $password = md5($password."^-^zhuishuyun^_^");
  122. $channel = Channel::firstOrCreate(compact('phone'),compact('password','name','pay_type','nickname','latest_login_ip','latest_login_time','remark','register_ip'));
  123. return response()->item(new ChannelTransformer(), $channel);
  124. }
  125. /**
  126. * @apiVersion 1.0.0
  127. * @apiDescription 通过手机号码获取渠道
  128. * @api {GET} channel/getByPhone 通过手机号码获取渠道
  129. * @apiGroup channel
  130. * @apiName getByPhone
  131. * @apiParam {Number} phone 手机号码
  132. *
  133. * @apiSuccess {Number} id 渠道ID.
  134. * @apiSuccess {String} phone 手机号码.
  135. * @apiSuccess {String} name 渠道名称.
  136. * @apiSuccess {String} pay_merchant 支付商户.
  137. * @apiSuccess {String} nickname 昵称.
  138. * @apiSuccess {String} password 密码.
  139. * @apiSuccess {String} latest_login_time 最后登陆时间.
  140. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  141. * @apiSuccess {String} remark 备注.
  142. * @apiSuccess {String} register_ip 注册IP.
  143. * @apiSuccessExample {json} Success-Response:
  144. *
  145. * {
  146. * "code": 0,
  147. * "msg": "",
  148. * "data":
  149. * {
  150. * "id": 1,
  151. * "phone": "1586810210",
  152. * "name": "分销1",
  153. * "pay_merchant": "ALLINPAY_NALAN",
  154. * "nickname": "昵称",
  155. * "password": "34sdfsdfdsf23",
  156. * "latest_login_time": "2017-12-12 12:12:12",
  157. * "latest_login_ip": "56.3.21.2",
  158. * "remark": "啦啦啦",
  159. * "register_ip": "123.25.21.21",
  160. * }
  161. *
  162. * }
  163. */
  164. function getByPhone(Request $request)
  165. {
  166. $phone = $request->has('phone') ? trim($request->input('phone')) : '';
  167. if(!$phone) return response()->error('PARAM_ERROR');
  168. $channel = Channel::getByPhone($phone);
  169. return response()->item(new ChannelTransformer(), $channel);
  170. }
  171. /**
  172. * @apiVersion 1.0.0
  173. * @apiDescription 校验密码
  174. * @api {POST} checkPassword 校验密码
  175. * @apiGroup channel
  176. * @apiName checkPassword
  177. * @apiParam {String} phone 手机号码.
  178. * @apiParam {String} password 密码.
  179. * @apiSuccessExample {json} Success-Response:
  180. *
  181. * {
  182. * "code": 0,
  183. * "msg": "",
  184. * "data": {}
  185. * }
  186. */
  187. function checkPassword(Request $request)
  188. {
  189. $phone = $request->has('phone') ? trim($request->input('phone')) : '';
  190. $password = $request->has('password') ? trim($request->input('password')) : '';
  191. if(!$phone || !$password) return response()->error('PARAM_ERROR');
  192. $channel = Channel::getByPhone($phone);
  193. if($channel->password == md5($password."^-^zhuishuyun^_^"))
  194. {
  195. return response()->success();
  196. }else{
  197. return response()->error('LOGIN_VERIFY_ERROR');
  198. }
  199. }
  200. /**
  201. * @apiVersion 1.0.0
  202. * @apiDescription 通过id获取渠道
  203. * @api {GET} channel/getById 通过id获取渠道
  204. * @apiGroup channel
  205. * @apiName getById
  206. * @apiParam {Number} id 渠道id
  207. *
  208. * @apiSuccess {Number} id 渠道ID.
  209. * @apiSuccess {String} phone 手机号码.
  210. * @apiSuccess {String} name 渠道名称.
  211. * @apiSuccess {String} pay_merchant 支付商户.
  212. * @apiSuccess {String} nickname 昵称.
  213. * @apiSuccess {String} password 密码.
  214. * @apiSuccess {String} latest_login_time 最后登陆时间.
  215. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  216. * @apiSuccess {String} remark 备注.
  217. * @apiSuccess {String} register_ip 注册IP.
  218. * @apiSuccessExample {json} Success-Response:
  219. *
  220. * {
  221. * "code": 0,
  222. * "msg": "",
  223. * "data":
  224. * {
  225. * "id": 1,
  226. * "phone": "1586810210",
  227. * "name": "分销1",
  228. * "pay_merchant": "ALLINPAY_NALAN",
  229. * "nickname": "昵称",
  230. * "password": "34sdfsdfdsf23",
  231. * "latest_login_time": "2017-12-12 12:12:12",
  232. * "latest_login_ip": "56.3.21.2",
  233. * "remark": "啦啦啦",
  234. * "register_ip": "123.25.21.21",
  235. * }
  236. *
  237. * }
  238. */
  239. function getById(Request $request)
  240. {
  241. $id = $request->has('id') ? trim($request->input('id')) : '';
  242. if(!$id) return response()->error('PARAM_ERROR');
  243. $channel = ChannelService::getById($id);
  244. return response()->item(new ChannelTransformer(), $channel);
  245. }
  246. /**
  247. * @apiVersion 1.0.0
  248. * @apiDescription 通过id获取渠道名称
  249. * @api {GET} channel/getChannelNameById 通过id获取渠道
  250. * @apiGroup channel
  251. * @apiName getChannelNameById
  252. * @apiParam {Number} id 渠道id
  253. *
  254. * @apiSuccess {Number} id 渠道ID.
  255. * @apiSuccess {String} phone 手机号码.
  256. * @apiSuccess {String} name 渠道名称.
  257. * @apiSuccess {String} pay_merchant 支付商户.
  258. * @apiSuccess {String} nickname 昵称.
  259. * @apiSuccess {String} password 密码.
  260. * @apiSuccess {String} latest_login_time 最后登陆时间.
  261. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  262. * @apiSuccess {String} remark 备注.
  263. * @apiSuccess {String} register_ip 注册IP.
  264. * @apiSuccessExample {json} Success-Response:
  265. *
  266. * {
  267. * "code": 0,
  268. * "msg": "",
  269. * "data":
  270. * {
  271. * "name": "分销1",
  272. * }
  273. * }
  274. */
  275. function getChannelNameById(Request $request)
  276. {
  277. $id = $request->has('id') ? trim($request->input('id')) : '';
  278. if(!$id) return response()->error('PARAM_ERROR');
  279. $channelName = ChannelService::getChannelNameById($id);
  280. return response()->json($channelName);
  281. }
  282. /**
  283. * @apiVersion 1.0.0
  284. * @apiDescription 更新渠道信息
  285. * @api {POST} channel/updateInfo 更新渠道信息
  286. * @apiGroup channel
  287. * @apiName channel/updateInfo
  288. * @apiParam {Number} distribution_channel_id 渠道id
  289. * @apiParam {String} [name] 渠道名称
  290. * @apiParam {String} [nickname] 渠道昵称
  291. * @apiParam {Number} [pay_merchant_id] 渠道支付通道
  292. * @apiParam {Number} [distribution_manages_id] 渠道管理员
  293. * @apiParam {String} [phone] 渠道电话
  294. * @apiParam {String} [person_in_charge_name] 渠道负责人
  295. * @apiParam {String} [remark] 备注
  296. * @apiParam {Number} [is_enabled] 是否开通 0:未审核; 1:审核通过
  297. *
  298. * @apiSuccess {Number} id 渠道ID.
  299. * @apiSuccess {String} phone 手机号码.
  300. * @apiSuccess {String} name 渠道名称.
  301. * @apiSuccess {String} pay_merchant 支付商户.
  302. * @apiSuccess {String} nickname 昵称.
  303. * @apiSuccess {String} password 密码.
  304. * @apiSuccess {String} latest_login_time 最后登陆时间.
  305. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  306. * @apiSuccess {String} remark 备注.
  307. * @apiSuccess {String} register_ip 注册IP.
  308. * @apiSuccessExample {json} Success-Response:
  309. *
  310. * {
  311. * "code": 0,
  312. * "msg": "",
  313. * "data":
  314. * {
  315. * "id": 1,
  316. * "phone": "1586810210",
  317. * "name": "分销1",
  318. * "pay_merchant": "ALLINPAY_NALAN",
  319. * "nickname": "昵称",
  320. * "password": "34sdfsdfdsf23",
  321. * "latest_login_time": "2017-12-12 12:12:12",
  322. * "latest_login_ip": "56.3.21.2",
  323. * "remark": "啦啦啦",
  324. * "register_ip": "123.25.21.21",
  325. * }
  326. *
  327. * }
  328. */
  329. function updateChannelData(Request $request) {
  330. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  331. if(empty(ChannelService::getById($distribution_channel_id))) {
  332. return response()->error('PARAM_ERROR');
  333. }
  334. $distribution_channel_name = $request->has('distribution_channel_name') ? $request->input('distribution_channel_name') : '';
  335. $nickname = $request->has('nickname') ? $request->input('nickname') : '';
  336. $pay_merchant_id = $request->has('pay_merchant_id') ? $request->input('pay_merchant_id') : '';
  337. $phone = $request->has('phone') ? $request->input('phone') : '';
  338. $person_in_charge_name = $request->has('person_in_charge_name') ? $request->input('person_in_charge_name') : '';
  339. $remark = $request->has('remark') ? $request->input('remark') : '';
  340. $distribution_manages_id = $request->has('distribution_manages_id') ? $request->input('distribution_manages_id') : '';
  341. $isEnabled = $request->has('is_enabled') ? $request->input('is_enabled') : '';
  342. $params = [
  343. 'name'=>$distribution_channel_name,
  344. 'nickname'=>$nickname,
  345. 'pay_merchant_id'=>$pay_merchant_id,
  346. 'phone'=>$phone,
  347. 'person_in_charge_name'=>$person_in_charge_name,
  348. 'distribution_manages_id'=>$distribution_manages_id,
  349. 'remark'=>$remark,
  350. 'is_enabled'=>$isEnabled,
  351. ];
  352. $channel = ChannelService::updateChannelData($distribution_channel_id, $params);
  353. return response()->item(new ChannelTransformer(), $channel);
  354. }
  355. /**
  356. * @apiVersion 1.0.0
  357. * @apiDescription 获取渠道列表
  358. * @api {GET} channel/getList 获取渠道列表
  359. * @apiGroup channel
  360. * @apiName channel/getList
  361. * @apiParam {Number} [distribution_channel_id] 渠道id.(可不传,获取所有渠道)
  362. * @apiParam {String} [distribution_channel_name] 渠道名称.(可不传,获取所有渠道)
  363. * @apiParam {String} [search_name] 搜索名称
  364. * @apiParam {String} [start_time] 开始时间(可不传)
  365. * @apiParam {String} [end_time] 结束时间(可不传)
  366. * @apiParam {Number} [is_enabled] 0:待审核; 1:已审核.(可不传)
  367. * @apiParam {Number} [distribution_manages_id] 管理员ID.(可不传)
  368. * @apiSuccess {Number} id 渠道ID.
  369. * @apiSuccess {String} name 渠道名称.
  370. * @apiSuccess {String} phone 手机号码.
  371. * @apiSuccess {String} pay_merchant 支付商户.
  372. * @apiSuccess {String} nickname 昵称.
  373. * @apiSuccess {String} latest_login_time 最后登陆时间.
  374. * @apiSuccess {String} latest_login_ip 最后登陆IP.
  375. * @apiSuccess {String} remark 备注.
  376. * @apiSuccess {String} register_ip 注册IP.
  377. * @apiSuccess {String} person_in_charge_name 负责人.
  378. * @apiSuccess {String} create_time 注册时间
  379. * @apiSuccess {Number} distribution_manages_id 管理员ID
  380. * @apiSuccess {String} distribution_manages_account 管理员
  381. * @apiSuccess {String} distribution_manages_number 管理员
  382. * @apiSuccess {String} distribution_manages_nickname 管理员昵称
  383. * @apiSuccessExample {json} Success-Response:
  384. *
  385. * {
  386. * "code": 0,
  387. * "msg": "",
  388. * "data": [
  389. * {
  390. * "id": 1,
  391. * "phone": "",
  392. * "name": "121",
  393. * "pay_merchant_id": 1,
  394. * "nickname": "是说",
  395. * "latest_login_time": "",
  396. * "latest_login_ip": "",
  397. * "is_enabled": 1,
  398. * "register_ip": "",
  399. * "remark": "",
  400. * "person_in_charge_name": "波哥帅",
  401. * "create_time": "2017-11-20 18:34:17",
  402. * "distribution_manages_id": 0,
  403. * "distribution_manages_account": null,
  404. * "distribution_manages_number": null,
  405. * "distribution_manages_nickname": null
  406. * }
  407. * ]
  408. * }
  409. */
  410. function getList(Request $request) {
  411. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
  412. $distribution_channel_name = $request->has('distribution_channel_name') ? $request->input('distribution_channel_name') : '';
  413. $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? date('Ymd',strtotime($request->input('start_time'))) : '';
  414. $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Ymd',strtotime($request->input('end_time'))) : '';
  415. $distribution_manages_id = $request->has('distribution_manages_id') ? $request->input('distribution_manages_id') : '';
  416. $isEnabled = $request->has('is_enabled') ? $request->input('is_enabled') : '';
  417. $search_name = $request->has('search_name') ? $request->input('search_name') : '';
  418. //商务,只获取到当前商务下的渠道列表
  419. if($this->getLoginUserRole() == "business") {
  420. $distribution_manages_id = $this->getLoginUserId();
  421. }
  422. // dd($this->getLoginUserId());
  423. $params = [
  424. 'channel_id'=>$distribution_channel_id,
  425. 'channel_name'=>$distribution_channel_name,
  426. 'start_date'=>$start_time,
  427. 'end_date'=>$end_time,
  428. 'distribution_manages_id'=>$distribution_manages_id,
  429. 'is_enabled'=>$isEnabled,
  430. 'search_name'=>$search_name,
  431. ];
  432. $result = ChannelService::getChannelList($params);
  433. return response()->pagination(new ChannelTransformer(), $result);
  434. }
  435. }