|
@@ -0,0 +1,302 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+
|
|
|
+use app\admin\model\PlatformSource;use app\admin\model\UserPlatform;use think\App;use think\facade\Validate;
|
|
|
+class Platform extends Base{
|
|
|
+ public function __construct(App $app) {
|
|
|
+ parent::__construct($app);
|
|
|
+ $this->model=new \app\admin\model\Platform();
|
|
|
+ }
|
|
|
+ /**@param platform_name 平台名称
|
|
|
+ * @param use_type 对接平台
|
|
|
+ * @param platform_type 对接平台
|
|
|
+ * 0:无
|
|
|
+ * 1:有赞平台
|
|
|
+ * 2:其他
|
|
|
+ * @param is_select_pay_rate 是否开启支付渠道
|
|
|
+ * @param desc 权重
|
|
|
+ * @param status 状态
|
|
|
+ * @param pay_list 渠道配置
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function create(){
|
|
|
+ $param =$this->request->only([
|
|
|
+ 'platform_name'=>'',
|
|
|
+ 'platform_type'=>'',
|
|
|
+ 'use_type'=>'',
|
|
|
+ 'is_select_pay_rate'=>'',
|
|
|
+ 'desc'=>'',
|
|
|
+ "status"=>0,
|
|
|
+ 'is_del'=>'0',
|
|
|
+ 'pay_list' => []
|
|
|
+ ],'post','trim');
|
|
|
+ $valid = Validate::rule([
|
|
|
+ 'platform_name|平台名称' => 'require|max:255|unique:app\admin\model\Platform,platform_name^is_del',
|
|
|
+ '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(!$valid->check($param)) return error($valid->getError());
|
|
|
+ $channelArr=[];
|
|
|
+ if($param['is_select_pay_rate']==1){
|
|
|
+ $pay_list = $param['pay_list'];
|
|
|
+ foreach ($pay_list as $k=>$v){
|
|
|
+ $channelArr[]=[
|
|
|
+ "channel_id"=>$v['channel_id'],
|
|
|
+ "platform_id"=>0,
|
|
|
+ 'apply_id' => $this->uid,
|
|
|
+ 'apply_name' => $this->uname,
|
|
|
+ 'weight' => $k++,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->model->startTrans();
|
|
|
+ try{
|
|
|
+ $platCode=makeNo("PT");
|
|
|
+ $param['platform_code']=$platCode;
|
|
|
+ $param['createrid']=$this->uid;
|
|
|
+ $param['creater']=$this->uname;
|
|
|
+ $plat=$this->model->create($param);
|
|
|
+ if($plat===false)throw new \Exception("创建失败");
|
|
|
+ if($param['is_select_pay_rate']==1){
|
|
|
+ $channelModel=new \app\admin\model\PlatformChannel();
|
|
|
+ $channelArr=array_map(function($v)use($plat){
|
|
|
+ $v['platform_id']=$plat->id;
|
|
|
+ return $v;
|
|
|
+ },$channelArr);
|
|
|
+ $channle= $channelModel->saveAll($channelArr);
|
|
|
+ if($channle===false)throw new \Exception("创建失败");
|
|
|
+ }
|
|
|
+ $this->model->commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->model->rollback();
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success("创建成功");
|
|
|
+ }
|
|
|
+ /**@param platform_name 平台名称
|
|
|
+ * @param platform_type 对接平台
|
|
|
+ * 0:无
|
|
|
+ * 1:有赞平台
|
|
|
+ * 2:其他
|
|
|
+ * @param is_select_pay_rate 是否开启支付渠道
|
|
|
+ * @param desc 权重
|
|
|
+ * @param status 状态
|
|
|
+ * @param pay_list 渠道配置 **/
|
|
|
+ public function save(){
|
|
|
+ $param =$this->request->only([
|
|
|
+ 'id'=>'',
|
|
|
+ 'platform_name'=>'',
|
|
|
+ 'platform_type'=>'',
|
|
|
+ 'use_type'=>'',
|
|
|
+ 'is_select_pay_rate'=>'',
|
|
|
+ 'desc'=>'',
|
|
|
+ "status"=>0,
|
|
|
+ 'is_del'=>'0',
|
|
|
+ 'pay_list' => []
|
|
|
+ ],'post','trim');
|
|
|
+ $valid = Validate::rule([
|
|
|
+ 'id|平台id' => 'require|number',
|
|
|
+ 'platform_name|平台名称' => 'require|max:255|unique:app\admin\model\Platform,platform_name^is_del',
|
|
|
+ '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(!$valid->check($param)) return error($valid->getError());
|
|
|
+ $info=$this->model->findOrEmpty($param['id']);
|
|
|
+ if($info->isEmpty())return error("平台不存在");
|
|
|
+ if($info->is_del==1)return error("平台已删除");
|
|
|
+ $channelArr=[];
|
|
|
+ if($param['is_select_pay_rate']==1){
|
|
|
+ $pay_list = $param['pay_list'];
|
|
|
+ foreach ($pay_list as $k=>$v){
|
|
|
+ $channelArr[]=[
|
|
|
+ "id"=>$v["id"]??null,
|
|
|
+ 'platform_id' => $info->id,
|
|
|
+ 'channel_id' => $v['channel_id'],
|
|
|
+ 'apply_id' => $v['apply_id']??$this->uid,
|
|
|
+ 'apply_name' => $v['apply_name']??$this->uname,
|
|
|
+ 'weight' => $weight++,
|
|
|
+ 'is_del' => $pay['is_del']??0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->model->startTrans();
|
|
|
+ try{
|
|
|
+ $plat=$info->save($param);
|
|
|
+ if($plat===false)throw new \Exception("修改失败");
|
|
|
+ if($param['is_select_pay_rate']==1){
|
|
|
+ $channelModel=new \app\admin\model\PlatformChannel();
|
|
|
+ $channel = $channelModel->saveAll($channelArr);
|
|
|
+ if($channel===false)throw new \Exception("修改失败");
|
|
|
+ }
|
|
|
+ $this->model->commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->model->rollback();
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ return success("修改成功");
|
|
|
+ }
|
|
|
+ /**@param platform_name 平台名称
|
|
|
+ * @param platform_type 对接平台
|
|
|
+ * 0:无
|
|
|
+ * 1:有赞平台
|
|
|
+ * 2:其他
|
|
|
+ *@param status 状态
|
|
|
+ * 0:禁用
|
|
|
+ * 1:启用
|
|
|
+ * @param createrid 创建人id
|
|
|
+ * @param start 开始时间
|
|
|
+ * @param end 结束时间
|
|
|
+ */
|
|
|
+ public function list(){
|
|
|
+ $param =$this->request->only([
|
|
|
+ 'platform_name'=>'',
|
|
|
+ 'platform_type'=>'',
|
|
|
+ "status"=>0,
|
|
|
+ 'start'=>'',
|
|
|
+ 'end'=>'',
|
|
|
+ "createrid"=>"",
|
|
|
+ "is_show"=>1,
|
|
|
+ 'page'=>1,
|
|
|
+ 'size'=>10
|
|
|
+ ],'post','trim');
|
|
|
+ $where=[["is_del","=",0]];
|
|
|
+ if($param['platform_name']!=="") $where[]=["platform_name","like","%".$param['platform_name']."%"];
|
|
|
+ if($param['platform_type']!=="") $where[]=["platform_type","=",$param['platform_type']];
|
|
|
+ if($param['status']!=="") $where[]=["status","=",$param['status']];
|
|
|
+ if($param['createrid']!=="") $where[]=["createrid","=",$param['createrid']];
|
|
|
+ if($param['start']!=="" && $param['end']!==""){
|
|
|
+ $where[]=["createtime","between",[startTime($param['start']),endTime($param['end'])]];
|
|
|
+ }elseif($param['start']!==""){
|
|
|
+ $where[]=["createtime",">=",startTime($param['start'])];
|
|
|
+ }elseif($param['end']!==""){
|
|
|
+ $where[]=["createtime","<=",endTime($param['end'])];
|
|
|
+ }
|
|
|
+ if($param['is_show']==1){
|
|
|
+ $role = $this->checkRole();
|
|
|
+ if (!empty($role['platform'])) $where[] = ['id', 'in', $role['platform']];
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->model->where($where)->order(["weight"=>"desc",'id' => 'desc'])
|
|
|
+ ->paginate(["page"=>$param['page'],"list_rows"=>$param['size']]);
|
|
|
+ return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function info(){
|
|
|
+ $id = $this->request->param('id','', 'int');
|
|
|
+ if(empty($id)) return error("参数错误");
|
|
|
+ $info = $this->model->with(["platChannel"=>"channel"])->findOrEmpty($id);
|
|
|
+ if($info->isEmpty()) return error("平台不存在");
|
|
|
+ if($info->is_del==1) return error("平台已删除");
|
|
|
+ return success("获取成功",$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function delete(){
|
|
|
+ $id = $this->request->param('id','', 'int');
|
|
|
+ if(empty($id)) return error("参数错误");
|
|
|
+ $info = $this->model->findOrEmpty($id);
|
|
|
+ if($info->isEmpty()) return error("平台不存在");
|
|
|
+ if($info->is_del==1) return error("平台已删除");
|
|
|
+ $info->is_del=1;
|
|
|
+ if($info->save()===false) return error("删除失败");
|
|
|
+ return success("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function status(){
|
|
|
+ $param =$this->request->only([
|
|
|
+ 'id'=>'',
|
|
|
+ 'status'=>'',
|
|
|
+ ],'post','trim');
|
|
|
+ $valid = Validate::rule([
|
|
|
+ 'id|平台id' => 'require|number',
|
|
|
+ 'status|状态' => 'require|number|in:0,1',
|
|
|
+ ]);
|
|
|
+ if(!$valid->check($param))return error($valid->getError());
|
|
|
+ $info = $this->model->findOrEmpty($param['id']);
|
|
|
+ if($info->isEmpty()) return error("平台不存在");
|
|
|
+ if($info->is_del==1) return error("平台已删除");
|
|
|
+ $info->status=$param['status'];
|
|
|
+ if($info->save()===false) return error("修改失败");
|
|
|
+ return success("修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**@param platform_id 平台id
|
|
|
+ * @param source 渠道名称
|
|
|
+ * **/
|
|
|
+ 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];
|
|
|
+ $create=PlatformSource::create($data);
|
|
|
+ if($create->isEmpty())return error('创建失败');
|
|
|
+ return success('创建成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function platformSourceDelete(){
|
|
|
+ $param=$this->request->param(['id'],'post','trim');
|
|
|
+ $info =PlatformSource::where('id',$param['id'])->findOrEmpty();
|
|
|
+ if($info->isEmpty())return error('未找到数据');
|
|
|
+ $info['is_del']=1;
|
|
|
+ $info['updatetime']=date('Y-m-d H:i:s');
|
|
|
+ if($info->save()===false)return error('删除失败');
|
|
|
+ return success('删除成功');
|
|
|
+ }
|
|
|
+ public function platformSourceList(){
|
|
|
+ $param=$this->request->param(['platform_id'],'post','trim');
|
|
|
+ $valid=Validate::rule(['platform_id|平台id'=>'require|number|gt:0']);
|
|
|
+ if($valid->check($param)==false)$this->error($valid->getError());
|
|
|
+ $list=PlatformSource::where('platform_id',$param['platform_id'])->where('is_del',0)->select();
|
|
|
+ return success('获取成功',$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function platformList(){
|
|
|
+ $param = $this->request->param(['platform_name'=>"",'platform_type'=>'','platform_code'=>'','page'=>'1','size'=>'10','use_type'=>''],'post','trim');
|
|
|
+ $where=[['is_del','=',0]];
|
|
|
+ if($param['platform_name']!=="") $where[]=["platform_name","like","%".$param['platform_name']."%"];
|
|
|
+ if($param['platform_type']!=="") $where[]=["platform_type","=",$param['platform_type']];
|
|
|
+ if($param['platform_code']!=="") $where[]=["platform_code","like","%".$param['platform_code']."%"];
|
|
|
+ if($param['use_type']!=="") $where[]=["use_type","=",$param['use_type']];
|
|
|
+ if($this->level==2){
|
|
|
+ $platrform = UserPlatform::where(["uid"=>$this->uid,"is_del"=>0])->findOrEmpty();
|
|
|
+ $where[]=['id','in',$platrform->platform??[]];
|
|
|
+ }
|
|
|
+ $list = $this->model->where($where)->order(["weight"=>"desc",'id' => 'desc'])
|
|
|
+ ->paginate(["page"=>$param['page'],"list_rows"=>$param['size']]);
|
|
|
+ return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function platformCreate(){
|
|
|
+ $param = $this->request->only(['uid', 'platform_id'], 'post', 'trim');
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'uid|用户ID' => 'require|number|gt:0',
|
|
|
+ 'platform_id|平台id集合' => 'require|array|max:9999'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($val->check($param) == false) return error($val->getError());
|
|
|
+ $platform = $this->model->where('id', 'in', $param['platform_id'])->where('is_del',0)->select();
|
|
|
+ if ($platform->isEmpty()) return error('平台不存在');
|
|
|
+ $info = UserPlatform::where(['uid' => $param['uid'], 'is_del' => 0])->findOrEmpty();
|
|
|
+ $info->platform = array_column($platform,"id");
|
|
|
+ if($info->save()) return error('创建失败');
|
|
|
+ return success('创建成功');
|
|
|
+ }
|
|
|
+}
|