|
@@ -3,268 +3,580 @@
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\admin\model\ChangeLog;
|
|
|
-use app\BaseController;
|
|
|
use think\App;
|
|
|
+use think\Exception;
|
|
|
use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
//平台
|
|
|
class Platform extends Base
|
|
|
{
|
|
|
- public function __construct(App $app)
|
|
|
+ public function create()
|
|
|
{
|
|
|
- parent::__construct($app);
|
|
|
+ $param = $this->request->only([
|
|
|
+ 'platform_name',
|
|
|
+ 'platform_type',
|
|
|
+ 'use_type',
|
|
|
+ 'is_select_pay_rate' => 0,
|
|
|
+ 'desc' => '',
|
|
|
+ 'status' => 0,
|
|
|
+ 'pay_title' => '',
|
|
|
+ 'pay_list' => []
|
|
|
+ ], 'post', 'trim');
|
|
|
|
|
|
- }
|
|
|
- public function create(){
|
|
|
- $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不能为空");
|
|
|
+ $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) {
|
|
|
+
|
|
|
+ $insert_da = [];
|
|
|
+ foreach ($param['pay_list'] as $pay) {
|
|
|
+ $insert_da[] = [
|
|
|
+ 'platform_id' => $platform_id,
|
|
|
+ 'companyNo' => $pay['companyNo'],
|
|
|
+ 'rate' => $pay['rate'],
|
|
|
+ '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());
|
|
|
}
|
|
|
- $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= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
- $action_name= 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";
|
|
|
- $data=[
|
|
|
- "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,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $info = Db::name("platform")->insert($data,true);
|
|
|
- if($info>0){
|
|
|
- $this->addPlat($info);
|
|
|
- return error_show(0,"新建成功");
|
|
|
- }else{
|
|
|
- return error_show(1003,"新建失败");
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
- public function list(){
|
|
|
- $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($platform_name!=""){
|
|
|
- $where[]=['p.platform_name',"like","%$platform_name%"];
|
|
|
- }
|
|
|
- $platform_type = isset($this->post['platform_type']) && $this->post['platform_type'] !=="" ? intval($this->post['platform_type']):"";
|
|
|
- if($platform_type !=""){
|
|
|
- $where[]=['p.platform_type',"=",$platform_type];
|
|
|
- }
|
|
|
- $use_type = isset($this->post['use_type']) && $this->post['use_type'] !=="" ? intval($this->post['use_type']):"";
|
|
|
- if($use_type !=""){
|
|
|
- $where[]=['p.use_type',"=",$use_type];
|
|
|
- }
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
|
|
|
- :"";
|
|
|
- if($status!==""){
|
|
|
- $where[]=['p.status',"=",$status];
|
|
|
- }
|
|
|
- $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
|
|
|
- if($start!==""){
|
|
|
- $where[]=['p.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
|
|
|
- }
|
|
|
- $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
|
|
|
- if($end!==""){
|
|
|
- $where[]=['p.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
|
|
|
+
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->only([
|
|
|
+ 'page' => 1,
|
|
|
+ 'size' => 10,
|
|
|
+ 'platform_name' => '',
|
|
|
+ 'platform_type' => '',
|
|
|
+ 'use_type' => '',
|
|
|
+ 'status' => '',
|
|
|
+ 'start' => '',
|
|
|
+ 'end' => '',
|
|
|
+ 'is_show' => 1,
|
|
|
+ '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']];
|
|
|
}
|
|
|
- $is_show=isset($this->post['is_show']) && $this->post['is_show']!=="" ? intval($this->post['is_show']):"1";
|
|
|
- if($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 ($company_name !== "") $where[] = ["p.createrid", 'in', get_company_item_user_by_name($company_name)];
|
|
|
-
|
|
|
- $count = Db::name('platform')->alias('p')->where($where)->count();
|
|
|
- $total = ceil($count / $size);
|
|
|
- $page = $page >= $total ? $total : $page;
|
|
|
+// $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'])];
|
|
|
+
|
|
|
+ $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')
|
|
|
- ->field('p.*,u.itemid')
|
|
|
- ->leftJoin("depart_user u", "u.uid=p.createrid AND u.is_del=0")
|
|
|
+// ->leftJoin("depart_user u", "u.uid=p.createrid AND u.is_del=0")
|
|
|
->where($where)
|
|
|
- ->page($page,$size)
|
|
|
- ->order("addtime desc")
|
|
|
- ->append(['company_name'])
|
|
|
- ->withAttr('company_name',function ($val,$data){
|
|
|
- return implode('/', array_column(GetPart($data['itemid']), 'name'));
|
|
|
- })
|
|
|
+ ->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();
|
|
|
- return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
|
|
|
+
|
|
|
+ $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()
|
|
|
{
|
|
|
- $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,"平台名称已存在");
|
|
|
- }
|
|
|
+
|
|
|
+ $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']) : "";
|
|
|
- $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, "更新失败");
|
|
|
+// $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], $param);
|
|
|
+
|
|
|
+ if ($param['is_select_pay_rate'] == 1) {
|
|
|
+
|
|
|
+ Db::name('platform_pay_rate')
|
|
|
+ ->where(['is_del' => 0, 'platform_id' => $param['id']])
|
|
|
+ ->update(['is_del' => 1, 'updatetime' => $date]);
|
|
|
+
|
|
|
+ $insert_da = [];
|
|
|
+ foreach ($param['pay_list'] as $pay) {
|
|
|
+ $insert_da[] = [
|
|
|
+ 'platform_id' => $param['id'],
|
|
|
+ 'companyNo' => $pay['companyNo'],
|
|
|
+ 'rate' => $pay['rate'],
|
|
|
+ '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 = 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,'未找到数据');
|
|
|
+
|
|
|
+ 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')
|
|
|
+ ->where(['platform_id' => $info['id'], 'is_del' => 0])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ return app_show(0, "获取成功", $info);
|
|
|
}
|
|
|
-// $info['use_type'] = $info['use_type'] !=0 ? $info['use_type'] :"";
|
|
|
- return app_show(0,"获取成功",$info);
|
|
|
+
|
|
|
}
|
|
|
- public function del(){
|
|
|
- $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')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
|
|
|
- if($end){
|
|
|
- return error_show(0,"删除成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"删除失败");
|
|
|
+
|
|
|
+ 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(){
|
|
|
- $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无效");
|
|
|
+
|
|
|
+ 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}失败");
|
|
|
+
|
|
|
+// $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){
|
|
|
- $cat =Db::name("cat")->where(["status"=>1,"is_del"=>0])->select()->toArray();
|
|
|
- if (empty($cat)){
|
|
|
- return '';
|
|
|
- }
|
|
|
- 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");
|
|
|
- $isT = Db::name("cat_plat")->where(["cat_id"=>$value['id'],"platform_id"=>$plat_id,"is_del"=>0])->find();
|
|
|
- if($isT){
|
|
|
- $data= $temp;
|
|
|
- unset($data['cat_id']);
|
|
|
- unset($data['addtime']);
|
|
|
- Db::name("cat_plat")->where(["cat_id"=>$value['id'],"platform_id"=>$plat_id,"is_del"=>0])->update($data);
|
|
|
- }else{
|
|
|
- Db::name("cat_plat")->save($temp);
|
|
|
- }
|
|
|
+ /** 平台添加分类 **/
|
|
|
+ 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);
|
|
|
+
|
|
|
}
|
|
|
}
|