request->only([ 'platform_name', 'platform_type', 'use_type', 'is_select_pay_rate' => 0, 'desc' => '', 'status' => 0, 'pay_title' => '', 'pay_list' => [] ], 'post', 'trim'); $val = Validate::rule([ 'platform_name|平台名称' => 'require|max:255', 'platform_type|对接平台' => 'require|number|in:0,1', 'use_type|对接类型' => 'require|number|in:0,1,2', 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1', 'desc|描述' => 'max:255', 'status|状态' => 'number|in:0,1', 'pay_title|渠道名称' => 'requireIf:is_select_pay_rate,1|max:255', 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100' ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); // $platform_code = makeNo("PT"); // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):""; // if($platform_name==""){ // return error_show(1003,"参数platform_name不能为空"); // // } // $is_exit= Db::name("platform")->where(["platform_name"=>$platform_name])->find(); // if($is_exit){ // return error_show(1003,"平台名称已存在"); // } // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !=="" ? intval($this->post['platform_type']):""; // if($platform_type===""){ // return error_show(1002,"参数platform_type不能为空"); // } // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):""; // if($use_type===""){ // return error_show(1002,"参数use_type不能为空"); // } // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):""; // if($token==''){ // return error_show(105,"参数token不能为空"); // } // $user =GetUserInfo($token); // if(empty($user)||$user['code']!=0){ // return error_show(1002,"创建人数据不存在"); // } $action_id = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : ""; $action_name = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; // $desc=isset($this->post['desc']) && $this->post['desc'] !=="" ? trim($this->post['desc']):""; // $status= isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"0"; 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) { $userCommon = \app\admin\common\User::getIns(); // if (!isset($company_names['code']) || $company_names['code'] != 0) throw new Exception($company_names['message']); $weight = 0; $insert_da = [[ 'platform_id' => $platform_id, 'companyNo' => 'GYS', 'companyName' => '供应商', 'supplierName' => '', 'supplierNo' => '', 'rate' => 0, 'is_cgd' => 0, 'is_qrd' => 1, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]]; foreach ($param['pay_list'] as $pay) { $company_names = $userCommon->handle('hqInfo', ['code' =>$pay['companyNo']]); $insert_da[] = [ 'platform_id' => $platform_id, 'companyNo' => $pay['companyNo'], 'companyName' => $company_names['data']['name'] ?? '', 'supplierName' => $company_names['data']['relation_name'] ?? '', 'supplierNo' => $company_names['data']['relation_code'] ?? '', 'rate' => $pay['rate'], 'is_cgd' => 1, 'is_qrd' => 1, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]; } $insert_da[] = [ 'platform_id' => $platform_id, 'companyNo' => 'KH', 'companyName' => '客户', 'supplierName' => '', 'supplierNo' => '', 'rate' => 0, 'is_cgd' => 0, 'is_qrd' => 0, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]; if ($insert_da) Db::name('platform_pay_rate')->insertAll($insert_da); } // return error_show(0,"新建成功"); // }else{ // return error_show(1003,"新建失败"); // } 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' => '', // 'use_type' => '', 'status' => '', 'start' => '', 'end' => '', 'is_show' => 1, 'creater' => '' // 'company_name' => '', ], 'post', 'trim'); // $page = isset($this->post['page']) && $this->post['page']!=="" ? intval($this->post['page']):"1"; // $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10"; $where = [["p.is_del", "=", 0]]; // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !=="" ? trim($this->post['platform_name']):""; if ($param['platform_name'] != "") $where[] = ['p.platform_name', "like", '%' . $param['platform_name'] . '%']; // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !=="" ? intval($this->post['platform_type']):""; // if ($param['platform_type'] !== "") $where[] = ['p.platform_type', "=", $param['platform_type']]; // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):""; // if ($param['use_type'] !== "") $where[] = ['p.use_type', "=", $param['use_type']]; // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :""; if ($param['status'] !== "") $where[] = ['p.status', "=", $param['status']]; // $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:""; if ($param['start'] !== "") $where[] = ['p.addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))]; // $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:""; if ($param['end'] !== "") $where[] = ['p.addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)]; // $is_show=isset($this->post['is_show']) && $this->post['is_show']!=="" ? intval($this->post['is_show']):"1"; if ($param['is_show'] == 1) { $role = $this->checkRole(); if (!empty($role['platform'])) $where[] = ["p.id", "in", $role['platform']]; } // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : ""; // if ($param['company_name'] !== "") $where[] = ["p.createrid", 'in', get_company_item_user_by_name($param['company_name'])]; if ($param['creater'] != '') $where[] = ['p.creater', 'like', '%' . $param['creater'] . '%']; $count = Db::name('platform') ->alias('p') ->where($where) ->count('p.id'); // $total = ceil($count / $size); // $page = $page >= $total ? $total : $page; $list = Db::name('platform') ->alias('p') // ->leftJoin("depart_user u", "u.uid=p.createrid AND u.is_del=0") ->where($where) ->page($param['page'], $param['size']) ->order(['p.addtime' => 'desc', 'p.id' => 'desc']) // ->append(['company_name']) // ->withAttr('company_name',function ($val,$data){ // return implode('/', array_column(GetPart($data['itemid']), 'name')); // }) ->select() ->toArray(); $createrid = array_column($list, 'createrid'); $company = get_company_name_by_uid($createrid); foreach ($list as &$value) { $value['company_name'] = $company[$value['createrid']] ?? ''; // $value['pay_list'] = Db::name('platform_pay_rate') // ->where(['platform_id' => $value['id'], 'is_del' => 0]) // ->select() // ->toArray(); } 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' => '', 'status' => 0, 'pay_title' => '', 'pay_list' => [] ], 'post', 'trim'); $val = Validate::rule([ 'id' => 'require|number|gt:0', 'platform_name|平台名称' => 'require|max:255', 'platform_type|对接平台' => 'require|number|in:0,1', 'use_type|对接类型' => 'require|number|in:0,1,2', 'is_select_pay_rate|是否开启支付渠道' => 'require|number|in:0,1', 'desc|描述' => 'max:255', 'status|状态' => 'number|in:0,1', 'pay_title|渠道名称' => 'requireIf:is_select_pay_rate,1|max:255', 'pay_list|渠道配置' => 'requireIf:is_select_pay_rate,1|array|max:100' ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : ""; // if ($id == "") { // return error_show(1002, "参数id不能为空"); // } // $info = Db::name("platform")->where(['id' => $id, "is_del" => 0])->find(); // if ($info == "") { // return error_show(1002, "未找到数据"); // } // $platform_code = makeNo("PT"); // $platform_name = isset($this->post['platform_name']) && $this->post['platform_name'] !== "" ? trim($this->post['platform_name']) : ""; // if ($platform_name == "") { // return error_show(1002, "参数platform_name不能为空"); // } // $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !== "" ? intval($this->post['platform_type']) :""; // if($platform_type===""){ // return error_show(1002,"参数platform_type不能为空"); // } // $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):""; // if($use_type===""){ // return error_show(1002,"参数use_type不能为空"); // } // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : ""; // if ($token == '') { // return error_show(1005, "参数token不能为空"); // } // $is_exit= Db::name("platform")->where([["platform_name","=",$platform_name],["id","<>",$id]])->find(); // if($is_exit){ // return error_show(1003,"平台名称已存在"); // } // $user = GetUserInfo($token); // if (empty($user) || $user['code'] != 0) { // return error_show(102, "创建人数据不存在"); // } // $action_id = isset($user["data"]['id']) ? $user["data"]['id'] : ""; // $action_name = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : ""; // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; // $desc = isset($this->post['desc']) && $this->post['desc'] !== "" ? trim($this->post['desc']) : ""; 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'); $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 ]; 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) { $userCommon = \app\admin\common\User::getIns(); $company_names = $userCommon->handle('getCodeAndName', ['code' => array_column($param['pay_list'], 'companyNo')]); Db::name('platform_pay_rate') ->where(['is_del' => 0, 'platform_id' => $param['id']]) ->update(['is_del' => 1, 'updatetime' => $date]); $weight = 0; $insert_da = [[ 'platform_id' => $param['id'], 'companyNo' => 'GYS', 'companyName' => '供应商', 'supplierName' => '', 'supplierNo' => '', 'rate' => 0, 'is_cgd' => 0, 'is_qrd' => 1, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]]; foreach ($param['pay_list'] as $pay) { $company_names = $userCommon->handle('hqInfo', ['code' =>$pay['companyNo']]); $insert_da[] = [ 'platform_id' => $param['id'], 'companyNo' => $pay['companyNo'], 'companyName' => $company_names['data']['name'] ?? '', 'supplierName' => $company_names['data']['relation_name'] ?? '', 'supplierNo' => $company_names['data']['relation_code'] ?? '', 'rate' => $pay['rate'], 'is_cgd' => 1, 'is_qrd' => 1, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]; } $insert_da[] = [ 'platform_id' => $param['id'], 'companyNo' => 'KH', 'companyName' => '客户', 'supplierName' => '', 'supplierNo' => '', 'rate' => 0, 'is_cgd' => 0, 'is_qrd' => 0, 'weight' => $weight++, 'status' => 1, 'is_del' => 0, "addtime" => $date, "updatetime" => $date ]; if ($insert_da) Db::name('platform_pay_rate')->insertAll($insert_da); } Db::commit(); return json_show(0, '更新成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '更新失败,' . $exception->getMessage()); } // $data = [ // "id" => $id, // "platform_code" => $platform_code, // "platform_name" => $platform_name, // "platform_type" => $platform_type, // "use_type"=>$use_type, //// "createrid" => $action_id, //// "creater" => $action_name, // "desc" => $desc, // "status" => $status, // "is_del" => 0, // "updatetime" => date("Y-m-d H:i:s") // ]; // $datainfo = Db::name('platform')->save($data); // $temp = array_diff($data,$info); // $json = json_encode($temp,JSON_UNESCAPED_UNICODE); // $jsp = json_encode($info,JSON_UNESCAPED_UNICODE); // if ($datainfo) { // ChangeLog::logAdd(8,$info['platform_code'],$jsp,$json,$this->post['token'],$this->post); // return error_show(0, "更新成功"); // } else { // return error_show(1002, "更新失败"); // } } public function info() { $id = $this->request->filter('trim')->post('id/d', 0); // $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :""; // if($id==""){ // return error_show(1002,"参数id不能为空"); // } $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_pay_rate') ->field('id,companyNo,companyName,rate,status') ->where(['platform_id' => $info['id'], '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); // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):""; // if($id==""){ // return error_show(1002,"参数id不能为空"); // } // $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find(); // if(empty($info)){ // return error_show(1002,"未找到数据"); // } // $end = Db::name('platform') // ->where(['id'=>$id,'is_del'=>0]) // ->update(['is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]); // if($end){ // return $end?app_show(0,"删除成功"):error_show(1002,"删除失败"); // }else{ // return error_show(1002,"删除失败"); // } 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::name('platform_pay_rate') ->where(['is_del' => 0, 'platform_id' => $id]) ->update([ 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s"), ]); 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()); // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):""; // if($id==""){ // return error_show(1002,"参数id不能为空"); // } // $info = Db::name("platform")->where(['id'=>$id,'is_del'=>0])->find(); // if(empty($info)){ // return error_show(1002,"未找到数据"); // } // $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):""; // if($status===""){ // return error_show(1002,"参数status不能为空"); // } // if(!in_array($status,[0,1])){ // return error_show(1002,"参数status无效"); // } 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::name('platform_pay_rate') ->where(['is_del' => 0, 'platform_id' => $param['id']]) ->where('status', '<>', $param['status']) ->update([ 'status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s"), ]); Db::commit(); return json_show(0, '操作成功'); } catch (Exception $exception) { Db::rollback(); return json_show(1004, '操作失败,' . $exception->getMessage()); } // $info['status']=$status; // $info['updatetime']=date("Y-m-d H:i:s"); // $msg = $status==1?"启用":"禁用"; // $update = Db::name("platform")->save($info); // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败"); } /** 平台添加分类 **/ 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(); // if (empty($cat)){ // return ''; // } $insert_data = []; $date = date("Y-m-d H:i:s"); foreach ($cat as $value) { // $temp=[]; // $temp['cat_id']=$value['id']; // $temp['platform_id']=$plat_id; // $temp['fund_code']=$value['fund_code']; // $temp['status']=$value['status']; // $temp['apply_id']=$value['createrid']; // $temp['apply_name']=$value['creater']; // $temp['addtime']=date("Y-m-d H:i:s"); // $temp['updatetime']=date("Y-m-d H:i:s"); $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, ]; // $isT = Db::name("cat_plat") // ->where(["cat_id"=>$value['id'],"platform_id"=>$plat_id,"is_del"=>0]) // ->find(); if (isset($tmp[$value['id']])) { // $data= $temp; 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('id', 'desc') ->page($param['page'], $param['size']) ->select() ->toArray(); return json_show(0, '获取成功', ['count' => $count, 'list' => $list]); } }