123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ChangeLog;
- use think\App;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Validate;
- //平台
- class Platform extends Base
- {
- public function create()
- {
- $param = $this->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]);
- }
- }
|