wugg 2 years ago
parent
commit
2ab3b45c23
1 changed files with 10 additions and 6 deletions
  1. 10 6
      app/admin/controller/Channel.php

+ 10 - 6
app/admin/controller/Channel.php

@@ -39,6 +39,8 @@ class Channel extends Base{
 			"companyNo|业务公司"=>"require|max:255"
 			]);
 		if($valid->check($param)==false) return error_show(1006,$valid->getError());
+		$info=Db::name("channel")->where([["id","=",$param['id']]])->findOrEmpty();
+		if(empty($info)) return error_show(1006,"渠道信息未找到");
 		$ist=Db::name("channel")->where([["channel_name","=",$param['channel_name']],["id","<>",$param['id']]])->findOrEmpty();
 		if(!empty($ist)) return error_show(1006,"渠道名称已存在");
 		$company = \app\admin\common\User::getIns()->handle("getCodeAndName",["code"=>$param['companyNo']]);
@@ -50,7 +52,7 @@ class Channel extends Base{
 			"companyNo"=>$param['companyNo'],
 			"updatetime"=>date("Y-m-d H:i:s")
 			];
-		$int= Db::name("channel")->where($ist)->update($data);
+		$int= Db::name("channel")->where($info)->update($data);
 		if($int==false) return error_show(1004,"渠道编辑失败");
 		return app_show(0,"渠道编辑成功");
 	}
@@ -94,13 +96,15 @@ class Channel extends Base{
 	public function channelCatList(){
 		$param =$this->request->only(["channel_id"=>"0","cat_id"=>'',"cat_name"=>"","page"=>1,"size"=>15],"post","trim");
 		$where=[["is_del","=",0]];
-		if($param['channel_id']!=='') $where[]=["channel_id","=",$param['channel_id']];
 		if($param['cat_id']!=='') $where[]=["cat_id","=",$param['cat_id']];
 		if($param['cat_name']!=='') $where[]=["cat_name","=",$param['cat_name']];
-		$list =Db::name("channel_cat")->alias("a")
-		->rightJoin("cat b","a.cat_id=b.cid")
-		->field("b.id as cat_id,b.cat_name,ifnull(a.channel_id,{$param['channel_id']}) channel_id,ifnull(a.rate,0) rate,ifnull(a.is_del,0) is_del")
-		->having($where)
+		$list =Db::name("cat")
+		->field("id as cat_id,cat_name,{$param['channel_id']} channel_id,0 rate")
+		->where($where)
+		->withAttr("rate",
+		function ($value,$data){
+			return Db::name("channel_cat")->where(["channel_id"=>$data['channel_id'],"cat_id"=>$data['cat_id'],"is_del"=>0])->value("rate",0);
+		})
 		->select();
 		return app_show(0,"获取成功",$list);
 	}