request->only([ 'platform_name', 'platform_type', 'use_type', 'is_select_pay_rate' => 0, 'desc' => '0', 'status' => 0, 'pay_list' => [] ], 'post', 'trim'); $val = Validate::rule([ 'platform_name|平台名称' => 'require|max:255', 'platform_type|对接平台' => 'require|number|in:0,1,2', 'use_type|对接类型' => 'require|number|in:0,1,2', 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1', 'desc|权重' => 'float', 'status|状态' => 'number|in:0,1', 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100' ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); $action_id = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : ""; $action_name = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; Db::startTrans(); try { $tmp = Db::name('platform') ->field('id') ->where(['is_del' => 0, 'platform_name' => $param['platform_name']]) ->findOrEmpty(); if (!empty($tmp)) throw new Exception('该平台名称已存在'); $date = date('Y-m-d H:i:s'); $platform_code = makeNo("PT"); $data = [ "platform_code" => $platform_code, "platform_name" => $param['platform_name'], "platform_type" => $param['platform_type'], "use_type" => $param['use_type'], "desc" => $param['desc'], "createrid" => $action_id, "creater" => $action_name, 'is_select_pay_rate' => $param['is_select_pay_rate'], // 'pay_title' => $param['pay_title'], "status" => $param['status'], "is_del" => 0, "addtime" => $date, "updatetime" => $date ]; $platform_id = Db::name("platform")->insertGetId($data); if (!$platform_id) throw new Exception(); //新增平台分类 $this->addPlat($platform_id); if ($param['is_select_pay_rate'] == 1) { $weight=0; foreach ($param['pay_list'] as $pay) { $insert_da[] = [ 'platform_id' => $platform_id, 'channel_id' => $pay['channel_id'], 'apply_id' => $this->uid, 'apply_name' => $this->uname, 'weight' => $weight++, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]; } if ($insert_da) Db::name('platform_channel')->insertAll($insert_da); } Db::commit(); return json_show(0, '新建成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '新建失败,' . $exception->getMessage()); } } public function list() { $param = $this->request->only([ 'page' => 1, 'size' => 10, 'platform_name' => '', 'platform_type' => '', 'status' => '', 'start' => '', 'end' => '', 'is_show' => 1, 'creater' => '' ], 'post', 'trim'); $where = [["p.is_del", "=", 0]]; if ($param['platform_name'] != "") $where[] = ['p.platform_name', "like", '%' . $param['platform_name'] . '%']; if ($param['platform_type'] !== "") $where[] = ['p.platform_type', "=", $param['platform_type']]; if ($param['status'] !== "") $where[] = ['p.status', "=", $param['status']]; if ($param['start'] !== "") $where[] = ['p.addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))]; if ($param['end'] !== "") $where[] = ['p.addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)]; if ($param['is_show'] == 1) { $role = $this->checkRole(); if (!empty($role['platform'])) $where[] = ["p.id", "in", $role['platform']]; } if ($param['creater'] != '') $where[] = ['p.creater', 'like', '%' . $param['creater'] . '%']; $count = Db::name('platform') ->alias('p') ->where($where) ->count('p.id'); $list = Db::name('platform') ->alias('p') ->where($where) ->page($param['page'], $param['size']) ->order(['p.desc' => 'desc', 'p.id' => 'desc']) ->select() ->toArray(); $createrid = array_column($list, 'createrid'); $company = get_company_name_by_uid($createrid); foreach ($list as &$value) { $value['company_name'] = $company[$value['createrid']] ?? ''; } return app_show(0, "获取成功", ['list' => $list, 'count' => $count]); } public function edit() { $param = $this->request->only([ 'id', 'platform_name', 'platform_type', 'use_type', 'is_select_pay_rate' => 0, 'desc' => 0, 'status' => 0, 'pay_list' => [] ], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', 'platform_name|平台名称' => 'require|max:255', 'platform_type|对接平台' => 'require|number|in:0,1,2', 'use_type|对接类型' => 'require|number|in:0,1,2', 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1', 'desc|排序权重' => 'float', 'status|状态' => 'number|in:0,1', 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100' ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); Db::startTrans(); try { $info = Db::name('platform') ->where(['is_del' => 0, 'id' => $param['id']]) ->findOrEmpty(); if (empty($info)) throw new Exception('未找到数据'); $tmp = Db::name('platform') ->field('id') ->where(['is_del' => 0, 'platform_name' => $param['platform_name']]) ->where('id', '<>', $param['id']) ->findOrEmpty(); if (!empty($tmp)) throw new Exception('平台名称已存在'); $date = date('Y-m-d H:i:s'); $data = [ "platform_name" => $param['platform_name'], "platform_type" => $param['platform_type'], "use_type" => $param['use_type'], "desc" => $param['desc'], 'is_select_pay_rate' => $param['is_select_pay_rate'], "status" => $param['status'], "updatetime" => $date ]; Db::name("platform")->where(['is_del' => 0, 'id' => $param['id']])->update($data); $temp = array_diff($data, $info); $json = json_encode($temp, JSON_UNESCAPED_UNICODE); $jsp = json_encode($info, JSON_UNESCAPED_UNICODE); ChangeLog::logAdd(8, $info['platform_code'], $jsp, $json, ['id' => $this->uid, 'nickname' => $this->uname]); if ($param['is_select_pay_rate'] == 1) { $weight = 0; foreach ($param['pay_list'] as $pay) { $insert_da = [ "id"=>$pay["id"]??null, 'platform_id' => $info['id'], 'channel_id' => $pay['channel_id'], 'apply_id' => $this->uid, 'apply_name' => $this->uname, 'weight' => $weight++, 'is_del' => $pay['is_del']??0, "addtime" => $date, "updatetime" => $date ]; $up =Db::name("platform_channel")->save($insert_da); if($up==false) throw new \Exception("平台渠道信息更新失败"); } } Db::commit(); return json_show(0, '更新成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '更新失败,' . $exception->getMessage()); } } public function info() { $id = $this->request->filter('trim')->post('id/d', 0); $info = Db::name('platform') ->where(['id' => $id, 'is_del' => 0]) ->find(); if (empty($info)) return error_show(1004, '未找到数据'); else { $info['pay_list'] = Db::name('platform_channel')->alias("a") ->leftJoin("channel b","a.channel_id=b.id") ->field('a.id,b.companyNo,b.companyName,b.channel_name,a.channel_id,a.is_del') ->where(['a.platform_id' => $info['id'], 'a.is_del' => 0,"b.is_del"=>0]) ->order(['weight' => 'desc']) ->select() ->toArray(); return app_show(0, "获取成功", $info); } } public function del() { $id = $this->request->filter('trim')->post('id/d', 0); Db::startTrans(); try { $rs = Db::name("platform") ->where(['is_del' => 0, 'id' => $id]) ->update([ 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s"), ]); if ($rs == 0) throw new Exception('该平台不存在'); Db::commit(); return json_show(0, '删除成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '删除失败,' . $exception->getMessage()); } } public function status() { $param = $this->request->only(['id', 'status'], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1', ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); Db::startTrans(); try { $rs = Db::name("platform") ->where(['is_del' => 0, 'id' => $param['id']]) ->where('status', '<>', $param['status']) ->update([ 'status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s"), ]); if ($rs == 0) throw new Exception('该平台不存在或重复操作'); Db::commit(); return json_show(0, '操作成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '操作失败,' . $exception->getMessage()); } } /** 平台添加分类 **/ private function addPlat($plat_id) { $tmp = Db::name('cat_plat') ->where(["platform_id" => $plat_id, "is_del" => 0]) ->column('id', 'cat_id'); $cat = Db::name("cat") ->where(["status" => 1, "is_del" => 0]) ->cursor(); $insert_data = []; $date = date("Y-m-d H:i:s"); foreach ($cat as $value) { $temp = [ 'cat_id' => $value['id'], 'platform_id' => $plat_id, 'fund_code' => $value['fund_code'], 'status' => $value['status'], 'apply_id' => $value['createrid'], 'apply_name' => $value['creater'], 'addtime' => $date, 'updatetime' => $date, ]; if (isset($tmp[$value['id']])) { unset($temp['cat_id']); unset($temp['addtime']); Db::name("cat_plat") ->where(["id" => $tmp[$value['id']], "is_del" => 0]) ->update($temp); } else $insert_data[] = $temp; } if ($insert_data) Db::name("cat_plat")->insertAll($insert_data); } //获取当前账号所能看到平台 public function getPlatformListByUid() { $param = $this->request->only(['page' => 1, 'size' => 10, 'platform_code' => '', 'platform_name' => '', 'platform_type' => '', 'use_type' => ''], 'post', 'trim'); $where = [['is_del', '=', 0]]; if ($param['platform_code'] !== '') $where[] = ['platform_code', 'like', '%' . $param['platform_code'] . '%']; if ($param['platform_name'] !== '') $where[] = ['platform_name', 'like', '%' . $param['platform_name'] . '%']; if ($param['platform_type'] !== '') $where[] = ['platform_type', '=', $param['platform_type']]; if ($param['use_type'] !== '') $where[] = ['use_type', '=', $param['use_type']]; if ($this->level == 2) { $ids = Db::name('user_platform') ->where(['uid' => $this->uid, 'is_del' => 0]) ->value('platform'); $where[] = ['id', 'in', $ids]; } $count = Db::name('platform') ->where($where) ->count('id'); $list = Db::name('platform') ->field('id,platform_code,platform_name,platform_type,use_type,status') ->where($where) ->order(['desc' => 'desc', 'id' => 'desc']) ->page($param['page'], $param['size']) ->select() ->toArray(); return json_show(0, '获取成功', ['count' => $count, 'list' => $list]); } public function platformSourceCreate(){ $param=$this->request->param(["platform_id","source"],"post","trim"); $valid=Validate::rule(["platform_id|平台id"=>"require|number|gt:0","source|渠道名称"=>"require|max:255"]); if($valid->check($param)==false)$this->error($valid->getError()); $data=["platform_id"=>$param["platform_id"],"source"=>$param["source"],"apply_id"=>$this->uid, "apply_name"=>$this->uname]; Db::name("platform_source")->save($data); $this->success("创建成功"); } public function platformSourceDelete(){ $param=$this->request->param(['id'],'post','trim'); $info =Db::name("platform_source")->findOrEmpty($param['id']); if(empty($info))$this->error("未找到数据"); $info["is_del"]=1; $info["updatetime"]=date("Y-m-d H:i:s"); Db::name('platform_source')->save($info); $this->success('删除成功'); } }