Platform.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ChangeLog;
  4. use think\App;
  5. use think\Exception;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //平台
  9. class Platform extends Base
  10. {
  11. public function create()
  12. {
  13. $param = $this->request->only([
  14. 'platform_name',
  15. 'platform_type',
  16. 'use_type',
  17. 'is_select_pay_rate' => 0,
  18. 'desc' => '',
  19. 'status' => 0,
  20. 'pay_title' => '',
  21. 'pay_list' => []
  22. ], 'post', 'trim');
  23. $val = Validate::rule([
  24. 'platform_name|平台名称' => 'require|max:255',
  25. 'platform_type|对接平台' => 'require|number|in:0,1',
  26. 'use_type|对接类型' => 'require|number|in:0,1,2',
  27. 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1',
  28. 'desc|描述' => 'max:255',
  29. 'status|状态' => 'number|in:0,1',
  30. 'pay_title|渠道名称' => 'requireIf:is_select_pay_rate,1|max:255',
  31. 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100'
  32. ]);
  33. if ($val->check($param) == false) return json_show(1004, $val->getError());
  34. // $platform_code = makeNo("PT");
  35. // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):"";
  36. // if($platform_name==""){
  37. // return error_show(1003,"参数platform_name不能为空");
  38. //
  39. // }
  40. // $is_exit= Db::name("platform")->where(["platform_name"=>$platform_name])->find();
  41. // if($is_exit){
  42. // return error_show(1003,"平台名称已存在");
  43. // }
  44. // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !=="" ? intval($this->post['platform_type']):"";
  45. // if($platform_type===""){
  46. // return error_show(1002,"参数platform_type不能为空");
  47. // }
  48. // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):"";
  49. // if($use_type===""){
  50. // return error_show(1002,"参数use_type不能为空");
  51. // }
  52. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  53. // if($token==''){
  54. // return error_show(105,"参数token不能为空");
  55. // }
  56. // $user =GetUserInfo($token);
  57. // if(empty($user)||$user['code']!=0){
  58. // return error_show(1002,"创建人数据不存在");
  59. // }
  60. $action_id = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  61. $action_name = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  62. // $desc=isset($this->post['desc']) && $this->post['desc'] !=="" ? trim($this->post['desc']):"";
  63. // $status= isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"0";
  64. Db::startTrans();
  65. try {
  66. $tmp = Db::name('platform')
  67. ->field('id')
  68. ->where(['is_del' => 0, 'platform_name' => $param['platform_name']])
  69. ->findOrEmpty();
  70. if (!empty($tmp)) throw new Exception('该平台名称已存在');
  71. $date = date('Y-m-d H:i:s');
  72. $platform_code = makeNo("PT");
  73. $data = [
  74. "platform_code" => $platform_code,
  75. "platform_name" => $param['platform_name'],
  76. "platform_type" => $param['platform_type'],
  77. "use_type" => $param['use_type'],
  78. "desc" => $param['desc'],
  79. "createrid" => $action_id,
  80. "creater" => $action_name,
  81. 'is_select_pay_rate' => $param['is_select_pay_rate'],
  82. 'pay_title' => $param['pay_title'],
  83. "status" => $param['status'],
  84. "is_del" => 0,
  85. "addtime" => $date,
  86. "updatetime" => $date
  87. ];
  88. $platform_id = Db::name("platform")->insertGetId($data);
  89. if (!$platform_id) throw new Exception();
  90. //新增平台分类
  91. $this->addPlat($platform_id);
  92. if ($param['is_select_pay_rate'] == 1) {
  93. $userCommon = \app\admin\common\User::getIns();
  94. // if (!isset($company_names['code']) || $company_names['code'] != 0) throw new Exception($company_names['message']);
  95. $weight = 0;
  96. $insert_da = [[
  97. 'platform_id' => $platform_id,
  98. 'companyNo' => 'GYS',
  99. 'companyName' => '供应商',
  100. 'supplierName' => '',
  101. 'supplierNo' => '',
  102. 'rate' => 0,
  103. 'is_cgd' => 0,
  104. 'is_qrd' => 1,
  105. 'weight' => $weight++,
  106. 'status' => 1,
  107. 'is_del' => 0,
  108. "addtime" => $date,
  109. "updatetime" => $date
  110. ]];
  111. foreach ($param['pay_list'] as $pay) {
  112. $company_names = $userCommon->handle('hqInfo', ['code' =>$pay['companyNo']]);
  113. $insert_da[] = [
  114. 'platform_id' => $platform_id,
  115. 'companyNo' => $pay['companyNo'],
  116. 'companyName' => $company_names['data']['name'] ?? '',
  117. 'supplierName' => $company_names['data']['relation_name'] ?? '',
  118. 'supplierNo' => $company_names['data']['relation_code'] ?? '',
  119. 'rate' => $pay['rate'],
  120. 'is_cgd' => 1,
  121. 'is_qrd' => 1,
  122. 'weight' => $weight++,
  123. 'status' => 1,
  124. 'is_del' => 0,
  125. "addtime" => $date,
  126. "updatetime" => $date
  127. ];
  128. }
  129. $insert_da[] = [
  130. 'platform_id' => $platform_id,
  131. 'companyNo' => 'KH',
  132. 'companyName' => '客户',
  133. 'supplierName' => '',
  134. 'supplierNo' => '',
  135. 'rate' => 0,
  136. 'is_cgd' => 0,
  137. 'is_qrd' => 0,
  138. 'weight' => $weight++,
  139. 'status' => 1,
  140. 'is_del' => 0,
  141. "addtime" => $date,
  142. "updatetime" => $date
  143. ];
  144. if ($insert_da) Db::name('platform_pay_rate')->insertAll($insert_da);
  145. }
  146. // return error_show(0,"新建成功");
  147. // }else{
  148. // return error_show(1003,"新建失败");
  149. // }
  150. Db::commit();
  151. return json_show(0, '新建成功');
  152. } catch (Exception $exception) {
  153. Db::rollback();
  154. return json_show(1004, '新建失败,' . $exception->getMessage());
  155. }
  156. }
  157. public function list()
  158. {
  159. $param = $this->request->only([
  160. 'page' => 1,
  161. 'size' => 10,
  162. 'platform_name' => '',
  163. // 'platform_type' => '',
  164. // 'use_type' => '',
  165. 'status' => '',
  166. 'start' => '',
  167. 'end' => '',
  168. 'is_show' => 1,
  169. 'creater' => ''
  170. // 'company_name' => '',
  171. ], 'post', 'trim');
  172. // $page = isset($this->post['page']) && $this->post['page']!=="" ? intval($this->post['page']):"1";
  173. // $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  174. $where = [["p.is_del", "=", 0]];
  175. // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):"";
  176. if ($param['platform_name'] != "") $where[] = ['p.platform_name', "like", '%' . $param['platform_name'] . '%'];
  177. // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !=="" ? intval($this->post['platform_type']):"";
  178. // if ($param['platform_type'] !== "") $where[] = ['p.platform_type', "=", $param['platform_type']];
  179. // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):"";
  180. // if ($param['use_type'] !== "") $where[] = ['p.use_type', "=", $param['use_type']];
  181. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  182. if ($param['status'] !== "") $where[] = ['p.status', "=", $param['status']];
  183. // $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  184. if ($param['start'] !== "") $where[] = ['p.addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
  185. // $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  186. if ($param['end'] !== "") $where[] = ['p.addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  187. // $is_show=isset($this->post['is_show']) && $this->post['is_show']!=="" ? intval($this->post['is_show']):"1";
  188. if ($param['is_show'] == 1) {
  189. $role = $this->checkRole();
  190. if (!empty($role['platform'])) $where[] = ["p.id", "in", $role['platform']];
  191. }
  192. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  193. // if ($param['company_name'] !== "") $where[] = ["p.createrid", 'in', get_company_item_user_by_name($param['company_name'])];
  194. if ($param['creater'] != '') $where[] = ['p.creater', 'like', '%' . $param['creater'] . '%'];
  195. $count = Db::name('platform')
  196. ->alias('p')
  197. ->where($where)
  198. ->count('p.id');
  199. // $total = ceil($count / $size);
  200. // $page = $page >= $total ? $total : $page;
  201. $list = Db::name('platform')
  202. ->alias('p')
  203. // ->leftJoin("depart_user u", "u.uid=p.createrid AND u.is_del=0")
  204. ->where($where)
  205. ->page($param['page'], $param['size'])
  206. ->order(['p.addtime' => 'desc', 'p.id' => 'desc'])
  207. // ->append(['company_name'])
  208. // ->withAttr('company_name',function ($val,$data){
  209. // return implode('/', array_column(GetPart($data['itemid']), 'name'));
  210. // })
  211. ->select()
  212. ->toArray();
  213. $createrid = array_column($list, 'createrid');
  214. $company = get_company_name_by_uid($createrid);
  215. foreach ($list as &$value) {
  216. $value['company_name'] = $company[$value['createrid']] ?? '';
  217. // $value['pay_list'] = Db::name('platform_pay_rate')
  218. // ->where(['platform_id' => $value['id'], 'is_del' => 0])
  219. // ->select()
  220. // ->toArray();
  221. }
  222. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  223. }
  224. public function edit()
  225. {
  226. $param = $this->request->only([
  227. 'id',
  228. 'platform_name',
  229. 'platform_type',
  230. 'use_type',
  231. 'is_select_pay_rate' => 0,
  232. 'desc' => '',
  233. 'status' => 0,
  234. 'pay_title' => '',
  235. 'pay_list' => []
  236. ], 'post', 'trim');
  237. $val = Validate::rule([
  238. 'id' => 'require|number|gt:0',
  239. 'platform_name|平台名称' => 'require|max:255',
  240. 'platform_type|对接平台' => 'require|number|in:0,1',
  241. 'use_type|对接类型' => 'require|number|in:0,1,2',
  242. 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1',
  243. 'desc|描述' => 'max:255',
  244. 'status|状态' => 'number|in:0,1',
  245. 'pay_title|渠道名称' => 'requireIf:is_select_pay_rate,1|max:255',
  246. 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100'
  247. ]);
  248. if ($val->check($param) == false) return json_show(1004, $val->getError());
  249. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  250. // if ($id == "") {
  251. // return error_show(1002, "参数id不能为空");
  252. // }
  253. // $info = Db::name("platform")->where(['id' => $id, "is_del" => 0])->find();
  254. // if ($info == "") {
  255. // return error_show(1002, "未找到数据");
  256. // }
  257. // $platform_code = makeNo("PT");
  258. // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !== "" ? trim($this->post['platform_name']) : "";
  259. // if ($platform_name == "") {
  260. // return error_show(1002, "参数platform_name不能为空");
  261. // }
  262. // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !== "" ? intval($this->post['platform_type']) :"";
  263. // if($platform_type===""){
  264. // return error_show(1002,"参数platform_type不能为空");
  265. // }
  266. // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):"";
  267. // if($use_type===""){
  268. // return error_show(1002,"参数use_type不能为空");
  269. // }
  270. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  271. // if ($token == '') {
  272. // return error_show(1005, "参数token不能为空");
  273. // }
  274. // $is_exit= Db::name("platform")->where([["platform_name","=",$platform_name],["id","<>",$id]])->find();
  275. // if($is_exit){
  276. // return error_show(1003,"平台名称已存在");
  277. // }
  278. // $user = GetUserInfo($token);
  279. // if (empty($user) || $user['code'] != 0) {
  280. // return error_show(102, "创建人数据不存在");
  281. // }
  282. // $action_id = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  283. // $action_name = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  284. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  285. // $desc = isset($this->post['desc']) && $this->post['desc'] !== "" ? trim($this->post['desc']) : "";
  286. Db::startTrans();
  287. try {
  288. $info = Db::name('platform')
  289. ->where(['is_del' => 0, 'id' => $param['id']])
  290. ->findOrEmpty();
  291. if (empty($info)) throw new Exception('未找到数据');
  292. $tmp = Db::name('platform')
  293. ->field('id')
  294. ->where(['is_del' => 0, 'platform_name' => $param['platform_name']])
  295. ->where('id', '<>', $param['id'])
  296. ->findOrEmpty();
  297. if (!empty($tmp)) throw new Exception('平台名称已存在');
  298. $date = date('Y-m-d H:i:s');
  299. $platform_code = makeNo("PT");
  300. $data = [
  301. "platform_code" => $platform_code,
  302. "platform_name" => $param['platform_name'],
  303. "platform_type" => $param['platform_type'],
  304. "use_type" => $param['use_type'],
  305. "desc" => $param['desc'],
  306. // "createrid" => $action_id,
  307. // "creater" => $action_name,
  308. 'is_select_pay_rate' => $param['is_select_pay_rate'],
  309. 'pay_title' => $param['pay_title'],
  310. "status" => $param['status'],
  311. // "is_del" => 0,
  312. // "addtime" => $date,
  313. "updatetime" => $date
  314. ];
  315. Db::name("platform")->where(['is_del' => 0, 'id' => $param['id']])->update($data);
  316. $temp = array_diff($data, $info);
  317. $json = json_encode($temp, JSON_UNESCAPED_UNICODE);
  318. $jsp = json_encode($info, JSON_UNESCAPED_UNICODE);
  319. ChangeLog::logAdd(8, $info['platform_code'], $jsp, $json, ['id' => $this->uid, 'nickname' => $this->uname]);
  320. if ($param['is_select_pay_rate'] == 1) {
  321. $userCommon = \app\admin\common\User::getIns();
  322. $company_names = $userCommon->handle('getCodeAndName', ['code' => array_column($param['pay_list'], 'companyNo')]);
  323. Db::name('platform_pay_rate')
  324. ->where(['is_del' => 0, 'platform_id' => $param['id']])
  325. ->update(['is_del' => 1, 'updatetime' => $date]);
  326. $weight = 0;
  327. $insert_da = [[
  328. 'platform_id' => $param['id'],
  329. 'companyNo' => 'GYS',
  330. 'companyName' => '供应商',
  331. 'supplierName' => '',
  332. 'supplierNo' => '',
  333. 'rate' => 0,
  334. 'is_cgd' => 0,
  335. 'is_qrd' => 1,
  336. 'weight' => $weight++,
  337. 'status' => 1,
  338. 'is_del' => 0,
  339. "addtime" => $date,
  340. "updatetime" => $date
  341. ]];
  342. foreach ($param['pay_list'] as $pay) {
  343. $company_names = $userCommon->handle('hqInfo', ['code' =>$pay['companyNo']]);
  344. $insert_da[] = [
  345. 'platform_id' => $param['id'],
  346. 'companyNo' => $pay['companyNo'],
  347. 'companyName' => $company_names['data']['name'] ?? '',
  348. 'supplierName' => $company_names['data']['relation_name'] ?? '',
  349. 'supplierNo' => $company_names['data']['relation_code'] ?? '',
  350. 'rate' => $pay['rate'],
  351. 'is_cgd' => 1,
  352. 'is_qrd' => 1,
  353. 'weight' => $weight++,
  354. 'status' => 1,
  355. 'is_del' => 0,
  356. "addtime" => $date,
  357. "updatetime" => $date
  358. ];
  359. }
  360. $insert_da[] = [
  361. 'platform_id' => $param['id'],
  362. 'companyNo' => 'KH',
  363. 'companyName' => '客户',
  364. 'supplierName' => '',
  365. 'supplierNo' => '',
  366. 'rate' => 0,
  367. 'is_cgd' => 0,
  368. 'is_qrd' => 0,
  369. 'weight' => $weight++,
  370. 'status' => 1,
  371. 'is_del' => 0,
  372. "addtime" => $date,
  373. "updatetime" => $date
  374. ];
  375. if ($insert_da) Db::name('platform_pay_rate')->insertAll($insert_da);
  376. }
  377. Db::commit();
  378. return json_show(0, '更新成功');
  379. } catch (Exception $exception) {
  380. Db::rollback();
  381. return json_show(1004, '更新失败,' . $exception->getMessage());
  382. }
  383. // $data = [
  384. // "id" => $id,
  385. // "platform_code" => $platform_code,
  386. // "platform_name" => $platform_name,
  387. // "platform_type" => $platform_type,
  388. // "use_type"=>$use_type,
  389. //// "createrid" => $action_id,
  390. //// "creater" => $action_name,
  391. // "desc" => $desc,
  392. // "status" => $status,
  393. // "is_del" => 0,
  394. // "updatetime" => date("Y-m-d H:i:s")
  395. // ];
  396. // $datainfo = Db::name('platform')->save($data);
  397. // $temp = array_diff($data,$info);
  398. // $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  399. // $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
  400. // if ($datainfo) {
  401. // ChangeLog::logAdd(8,$info['platform_code'],$jsp,$json,$this->post['token'],$this->post);
  402. // return error_show(0, "更新成功");
  403. // } else {
  404. // return error_show(1002, "更新失败");
  405. // }
  406. }
  407. public function info()
  408. {
  409. $id = $this->request->filter('trim')->post('id/d', 0);
  410. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  411. // if($id==""){
  412. // return error_show(1002,"参数id不能为空");
  413. // }
  414. $info = Db::name('platform')
  415. ->where(['id' => $id, 'is_del' => 0])
  416. ->find();
  417. if (empty($info)) return error_show(1004, '未找到数据');
  418. else {
  419. $info['pay_list'] = Db::name('platform_pay_rate')
  420. ->field('id,companyNo,companyName,rate,status')
  421. ->where(['platform_id' => $info['id'], 'is_del' => 0])
  422. ->order(['weight' => 'desc'])
  423. ->select()
  424. ->toArray();
  425. return app_show(0, "获取成功", $info);
  426. }
  427. }
  428. public function del()
  429. {
  430. $id = $this->request->filter('trim')->post('id/d', 0);
  431. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  432. // if($id==""){
  433. // return error_show(1002,"参数id不能为空");
  434. // }
  435. // $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find();
  436. // if(empty($info)){
  437. // return error_show(1002,"未找到数据");
  438. // }
  439. // $end = Db::name('platform')
  440. // ->where(['id'=>$id,'is_del'=>0])
  441. // ->update(['is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  442. // if($end){
  443. // return $end?app_show(0,"删除成功"):error_show(1002,"删除失败");
  444. // }else{
  445. // return error_show(1002,"删除失败");
  446. // }
  447. Db::startTrans();
  448. try {
  449. $rs = Db::name("platform")
  450. ->where(['is_del' => 0, 'id' => $id])
  451. ->update([
  452. 'is_del' => 1,
  453. 'updatetime' => date("Y-m-d H:i:s"),
  454. ]);
  455. if ($rs == 0) throw new Exception('该平台不存在');
  456. Db::name('platform_pay_rate')
  457. ->where(['is_del' => 0, 'platform_id' => $id])
  458. ->update([
  459. 'is_del' => 1,
  460. 'updatetime' => date("Y-m-d H:i:s"),
  461. ]);
  462. Db::commit();
  463. return json_show(0, '删除成功');
  464. } catch (Exception $exception) {
  465. Db::rollback();
  466. return json_show(1004, '删除失败,' . $exception->getMessage());
  467. }
  468. }
  469. public function status()
  470. {
  471. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  472. $val = Validate::rule([
  473. 'id' => 'require|number|gt:0',
  474. 'status|状态' => 'require|number|in:0,1',
  475. ]);
  476. if ($val->check($param) == false) return json_show(1004, $val->getError());
  477. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  478. // if($id==""){
  479. // return error_show(1002,"参数id不能为空");
  480. // }
  481. // $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find();
  482. // if(empty($info)){
  483. // return error_show(1002,"未找到数据");
  484. // }
  485. // $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
  486. // if($status===""){
  487. // return error_show(1002,"参数status不能为空");
  488. // }
  489. // if(!in_array($status,[0,1])){
  490. // return error_show(1002,"参数status无效");
  491. // }
  492. Db::startTrans();
  493. try {
  494. $rs = Db::name("platform")
  495. ->where(['is_del' => 0, 'id' => $param['id']])
  496. ->where('status', '<>', $param['status'])
  497. ->update([
  498. 'status' => $param['status'],
  499. 'updatetime' => date("Y-m-d H:i:s"),
  500. ]);
  501. if ($rs == 0) throw new Exception('该平台不存在或重复操作');
  502. Db::name('platform_pay_rate')
  503. ->where(['is_del' => 0, 'platform_id' => $param['id']])
  504. ->where('status', '<>', $param['status'])
  505. ->update([
  506. 'status' => $param['status'],
  507. 'updatetime' => date("Y-m-d H:i:s"),
  508. ]);
  509. Db::commit();
  510. return json_show(0, '操作成功');
  511. } catch (Exception $exception) {
  512. Db::rollback();
  513. return json_show(1004, '操作失败,' . $exception->getMessage());
  514. }
  515. // $info['status']=$status;
  516. // $info['updatetime']=date("Y-m-d H:i:s");
  517. // $msg = $status==1?"启用":"禁用";
  518. // $update = Db::name("platform")->save($info);
  519. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  520. }
  521. /** 平台添加分类 **/
  522. private function addPlat($plat_id)
  523. {
  524. $tmp = Db::name('cat_plat')
  525. ->where(["platform_id" => $plat_id, "is_del" => 0])
  526. ->column('id', 'cat_id');
  527. $cat = Db::name("cat")
  528. ->where(["status" => 1, "is_del" => 0])
  529. ->cursor();
  530. // if (empty($cat)){
  531. // return '';
  532. // }
  533. $insert_data = [];
  534. $date = date("Y-m-d H:i:s");
  535. foreach ($cat as $value) {
  536. // $temp=[];
  537. // $temp['cat_id']=$value['id'];
  538. // $temp['platform_id']=$plat_id;
  539. // $temp['fund_code']=$value['fund_code'];
  540. // $temp['status']=$value['status'];
  541. // $temp['apply_id']=$value['createrid'];
  542. // $temp['apply_name']=$value['creater'];
  543. // $temp['addtime']=date("Y-m-d H:i:s");
  544. // $temp['updatetime']=date("Y-m-d H:i:s");
  545. $temp = [
  546. 'cat_id' => $value['id'],
  547. 'platform_id' => $plat_id,
  548. 'fund_code' => $value['fund_code'],
  549. 'status' => $value['status'],
  550. 'apply_id' => $value['createrid'],
  551. 'apply_name' => $value['creater'],
  552. 'addtime' => $date,
  553. 'updatetime' => $date,
  554. ];
  555. // $isT = Db::name("cat_plat")
  556. // ->where(["cat_id"=>$value['id'],"platform_id"=>$plat_id,"is_del"=>0])
  557. // ->find();
  558. if (isset($tmp[$value['id']])) {
  559. // $data= $temp;
  560. unset($temp['cat_id']);
  561. unset($temp['addtime']);
  562. Db::name("cat_plat")
  563. ->where(["id" => $tmp[$value['id']], "is_del" => 0])
  564. ->update($temp);
  565. } else $insert_data[] = $temp;
  566. }
  567. if ($insert_data) Db::name("cat_plat")->insertAll($insert_data);
  568. }
  569. //获取当前账号所能看到平台
  570. public function getPlatformListByUid()
  571. {
  572. $param = $this->request->only(['page' => 1, 'size' => 10, 'platform_code' => '', 'platform_name' => '', 'platform_type' => '', 'use_type' => ''], 'post', 'trim');
  573. $where = [['is_del', '=', 0]];
  574. if ($param['platform_code'] !== '') $where[] = ['platform_code', 'like', '%' . $param['platform_code'] . '%'];
  575. if ($param['platform_name'] !== '') $where[] = ['platform_name', 'like', '%' . $param['platform_name'] . '%'];
  576. if ($param['platform_type'] !== '') $where[] = ['platform_type', '=', $param['platform_type']];
  577. if ($param['use_type'] !== '') $where[] = ['use_type', '=', $param['use_type']];
  578. if ($this->level == 2) {
  579. $ids = Db::name('user_platform')
  580. ->where(['uid' => $this->uid, 'is_del' => 0])
  581. ->value('platform');
  582. $where[] = ['id', 'in', $ids];
  583. }
  584. $count = Db::name('platform')
  585. ->where($where)
  586. ->count('id');
  587. $list = Db::name('platform')
  588. ->field('id,platform_code,platform_name,platform_type,use_type,status')
  589. ->where($where)
  590. ->order('id', 'desc')
  591. ->page($param['page'], $param['size'])
  592. ->select()
  593. ->toArray();
  594. return json_show(0, '获取成功', ['count' => $count, 'list' => $list]);
  595. }
  596. }