wugg hace 8 meses
padre
commit
5339ad014d

+ 11 - 11
app/api/controller/Good.php

@@ -15,7 +15,7 @@ use think\facade\Validate;
 
 class Good extends Base
 {
-	private $platform_id=37;
+	private $platform_id=[37,79];
 	private  $origin_img_host ='http://stock.api.wanyuhengtong.com';
     private  $ssl_img_host ='https://image.wanyuhengtong.com';
 	public function __construct(App $app) {
@@ -23,7 +23,7 @@ class Good extends Base
 	}
   	public function list(){
 		$param = $this->request->param(['page'=>1,'size'=>15,'good_name'=>''],'post','trim');
-		$where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','=',$this->platform_id],['b.exam_status',
+		$where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','in',$this->platform_id],['b.exam_status',
 		'=',6]];
 		$param['good_name']!=''??$where[]=['c.good_name','like',"%{$param['good_name']}%"];
 		$actUrl= new ActGoodurl();
@@ -31,7 +31,7 @@ class Good extends Base
 		->leftJoin('platform_youzan b','a.act_good_id=b.id')
 		->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
 		->where($where)
-		->field('b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,b.desc,
+		->field('b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,
 		            c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
 		            c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price')
 		->order('a.id desc')
@@ -52,7 +52,7 @@ class Good extends Base
 	    $param =$this->request->only(['skuCode'=>''],'post','trim');
 	    $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
 		if($valid->check($param)==false)$this->error($valid->getError());
-		$field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,b.desc,
+		$field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,
             a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
             a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
 		$youzan = new PlatformYouzan();
@@ -65,13 +65,13 @@ class Good extends Base
 
 	    if($info->isEmpty())  $this->error('商品数据未找到');
 	   
-        $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
-		$info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
-		$info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
-		$info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
-        $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
-        $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
-        $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
+	        $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
+			$info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
+			$info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
+			$info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
+	        $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
+	        $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
+	        $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
 	    
 	    $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
 	    $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);

+ 1 - 1
app/middleware.php

@@ -8,5 +8,5 @@ return [
     // Session初始化
     // \think\middleware\SessionInit::class
     //接口header校验
-        app\txx\middleware\CheckAuth::class
+//        app\txx\middleware\CheckAuth::class
 ];

+ 14 - 0
app/model/Brand.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Brand extends Model
+{
+    //
+}

+ 14 - 0
app/model/Cat.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Cat extends Model
+{
+    //
+}

+ 24 - 0
app/model/GoodBasic.php

@@ -0,0 +1,24 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodBasic extends Model
+{
+       public function brand(){
+        return $this->belongsTo(Brand::class,'brand_id','id')->bind(['brand_name']);
+    }
+
+    public function category(){
+        return $this->belongsTo(Cat::class,'cat_id','id')->bind(['cat_name','cat_search'=>'search']);
+    }
+
+    public function Unit(){
+        return $this->belongsTo(Unit::class,'good_unit','id')->bind(['unit_name'=>'unit']);
+    }
+}

+ 14 - 0
app/model/Platform.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Platform extends Model
+{
+    //
+}

+ 14 - 0
app/model/Unit.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Unit extends Model
+{
+    //
+}

+ 42 - 26
app/txx/controller/Act.php

@@ -3,22 +3,22 @@ declare (strict_types = 1);
 
 namespace app\txx\controller;
 
-use app\BaseController;
 use think\facade\Validate;
 use app\txx\model\Act as Actm;
 use think\App;
 
-class Act extends BaseController
+class Act extends Base
 {
 	protected $uid=0;
 	protected $uname='';
-		public function __construct(App $app) {
+	protected $model;
+    public function __construct(App $app) {
 		parent::__construct($app);
 		if($this->request->isCx==1){
 		    $this->uid=$this->request->uid;
 	        $this->uname=$this->request->uname;
 		}
-
+        $this->model=new Actm();
 	}
     /**
      * 显示资源列表
@@ -38,6 +38,7 @@ class Act extends BaseController
         "start"=>'',
         "end"=>'',
         "status"=>'',
+        'act_status'=>'',
       	],"post",'trim');
       $condition=[["is_del","=",0]];
       if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
@@ -48,12 +49,23 @@ class Act extends BaseController
       if($param['start']!='') $condition[]=["addtime",">=",$param["start"]." 00:00:00"];
       if($param['end']!='') $condition[]=["addtime","<=",$param["end"]." 23:59:59"];
       if($param['status']!='') $condition[]=["status","=",$param["status"]];
-      $actm=new Actm();
-      $count =$actm->where($condition)->count();
-      $total =ceil($count/$param['size']);
-      $page = $param['page']>= $total ?intval($total):intval($param['page']);
-      $list=$actm->where($condition)->page($page,intval($param['size']))->order("addtime desc")->select()->toArray();
-      return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+      if($param['act_status']!='') {
+          if($param['act_status']==1){
+              $condition[]=["startTime",">",date("Y-m-d H:i:s")];
+          }elseif($param['act_status']==2){
+             $condition[]=['startTime','<',date('Y-m-d H:i:s')];
+             $condition[]=['endTime','>',date('Y-m-d H:i:s')];
+          }elseif($param['act_status']==3){
+             $condition[]=['endTime','<',date('Y-m-d H:i:s')];
+          }
+      }
+
+      $list=$this->model->where($condition)
+      ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']])
+      ->each(function(&$item){
+        $item['act_status']=time()< strtotime($item['startTime'])?1:(time()> strtotime($item['endTime'])?3:2);
+      });
+      $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
     }
 
     /**
@@ -98,9 +110,9 @@ class Act extends BaseController
         	"addtime"=>date("Y-m-d H:i:s"),
         	"updatetime"=>date("Y-m-d H:i:s"),
         ];
-        $add =Actm::create($data);
-        return $add ?json_show(0,"活动新建成功",["actCode"=>$actCode]): json_show(1006,"活动新建失败");
-
+        $add =$this->model->create($data);
+        if($add->isEmpty())$this->error("活动添加失败");
+        $this->success("添加成功",["actCode"=>$actCode]);
     }
 
     /**
@@ -145,8 +157,9 @@ class Act extends BaseController
         	"web_url"=>$param['web_url']??"",
         	"updatetime"=>date("Y-m-d H:i:s"),
         ];
-        $add =$actm->update($data,["actCode"=>$param['actCode'],"is_del"=>0]);
-        return $add ?json_show(0,"活动编辑成功"): json_show(1006,"活动编辑失败");
+        $add =$info->save($data);
+        if($add==false)$this->error('活动修改失败');
+        $this->success('活动修改成功');
     }
 
     /**
@@ -160,10 +173,10 @@ class Act extends BaseController
     $param = $this->request->only(["actCode"=>''],"post","trim");
      $validate = Validate::rule([
             'actCode|活动编号' => 'require',]);
-      if($validate->check($param)==false)return  json_show(1004,$validate->getError());
-     $actm=new Actm();
-        $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find()->toArray();
-      return json_show(0,"获取成功",$info);
+      if($validate->check($param)==false)$this->error($validate->getError());
+      
+      $info = $this->model->with(["goodInfo"])->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+      $this->success("获取成功",$info);
     }
 
       /**
@@ -174,14 +187,17 @@ class Act extends BaseController
      */
     public function delete()
     {
-		$param = $this->request->only(["actCode"=>''],"post","trim");
+	    $param = $this->request->only(["actCode"=>''],"post","trim");
      $validate = Validate::rule([
             'actCode|活动编号' => 'require',]);
-      if($validate->check($param)==false)return  json_show(1004,$validate->getError());
-       $actm=new Actm();
-        $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
-      if($info==false) return json_show(1005,"活动不存在");
-      $isDel =$actm->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")],["actCode"=>$param['actCode'],"is_del"=>0]);
-       return $isDel?json_show(0,"活动删除成功"): json_show(1006,"活动删除失败");
+      if($validate->check($param)==false)$this->error($validate->getError());
+      ;
+        $info = $this->model->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+      if($info==false) $this->error("活动不存在");
+      $info->is_del=1;
+      $info->save();
+      $info->goodInfo()->update(["is_del"=>1]);
+      $this->success("删除成功");
+
     }
 }

+ 180 - 0
app/txx/controller/Activity.php

@@ -0,0 +1,180 @@
+<?php
+
+
+namespace app\txx\controller;
+
+
+use app\txx\model\ActGood;
+use app\txx\model\PlatformYouzan;
+use think\App;
+use think\facade\Validate;
+class Activity extends Base{
+    private $platform_id=[37,79];
+    private $model;
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ActGood();
+    }
+    public function goodList(){
+        $param = $this->request->param(["good_name"=>"","skuCode"=>'',"plat_code"=>'',"exam_status"=>"","page"=>1,"size"=>15],"post","trim");
+        $where=[["is_del","=",0],["platform_id",'in',$this->platform_id]];
+        if($param['good_name']!=="")$where[]=["good_name","like","%".$param['good_name']."%"];
+        if($param['skuCode']!=="")$where[]=["skuCode","like","%".$param['skuCode']."%"];
+        if($param['plat_code']!=="")$where[]=["plat_code","like","%".$param['plat_code']."%"];
+        if($param['exam_status']!==''){
+            $where[]=["exam_status","=",$param['exam_status']];
+        }
+        $list=PlatformYouzan::with(["good"=>["unit","category","brand"],"platform"])
+        ->where($where)->order("id desc")
+        ->field("plat_code,spuCode,skuCode,sale_price,final_price,exam_status,online_time,creater")
+        ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+    }
+
+    public function create(){
+        $param = $this->request->param(["snArr"=>"","actCode"=>""],"post","trim");
+        $valid = Validate::rule([
+            "snArr|选中的商品集合"=>"require|array",
+            "actCode|活动编码"=>"require|max:20"
+        ]);
+        if(!$valid->check($param)){
+            $this->error($valid->getError());
+        }
+        $skuCodeArr= array_column($param['snArr'],"skuCode");
+        $goodArr= PlatformYouzan::with(["yzGood"])->where(["skuCode"=>$skuCodeArr,"is_del"=>0])->select()->toArray();
+
+        if(count($goodArr)!==count($param['snArr'])){
+            $this->error("商品信息有误");
+        }
+        $yzGood = array_column($goodArr,"yzGood","skuCode");
+        $Act = \app\txx\model\Act::where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+        if($Act->isEmpty()){
+            $this->error("活动信息有误");
+        }
+        if($Act->status!==4){
+            $this->error("活动状态有误");
+        }
+        if(strtotime($Act->end_time)<time()){
+            $this->error("活动已结束");
+        }
+         if(strtotime($Act->start_time)<time()){
+            $this->error('活动已开始');
+        }
+         $valids= Validate::rule([
+            "skuCode|商品编码"=>"require|max:20",
+            "stock_num|库存数量"=>"require|integer",
+            "roundId|轮次"=>"integer",
+        ]);
+       $actArr=[];
+        foreach ($param['snArr'] as $k=>$v){
+                if(!$valids->check($v)){
+                    $this->error($valids->getError());
+                }
+                 if(!isset($yzGood[$v['skuCode']])|| isset($yzGood[$v['skuCode']]['status']))throw new \Exception('商品信息有误');
+                 if($yzGood[$v['skuCode']]['status']!==6)throw new \Exception($v['skuCode'].'有赞商品未上线');
+                 $temp=[
+					'actCode'=>$param['actCode'],
+					'yz_good_code'=>$v['skuCode'],
+					'stock_num'=>$v['stock_num'],
+					'used_num'=>0,
+					'balance_num'=>$v['stock_num'],
+					'roundId'=>$v['roundId']??'',
+					'good_url'=>$yzGood[$v['skuCode']]['detail_url']??'',
+					'origin_price'=>$yzGood[$v['skuCode']]['origin']??'',
+					'status'=>1,
+					];
+                 $actArr[]=$temp;
+             }
+        $this->model->startTrans();
+         try{
+             $add= $this->model->saveAll($actArr);
+             if($add->isEmpty()) throw new \Exception('添加失败');
+             $Act->save(["status"=>1]);
+             $this->model->commit();
+        }catch (\Exception $e){
+             $this->model->rollback();
+             $this->error($e->getMessage());
+        }
+      $this->success('添加成功');
+    }
+
+    public function list(){
+        $param=$this->request->param(["actCode"=>"","status"=>"","skuCode"=>"","roundId"=>"","page"=>1,"size"=>15],"post","trim");
+        $where=[["is_del","=",0]];
+        if($param['actCode']!==""){
+            $where[]=["actCode","like","%".$param['actCode']."%"];
+        }
+        if($param['status']!==""){
+            $where[]=["status","=",$param['status']];
+        }
+        if($param['skuCode']!==""){
+            $where[]=["yz_good_code","like","%".$param['skuCode']."%"];
+        }
+        if($param['roundId']!==""){
+            $where[]=["roundId","=",$param['roundId']];
+        }
+        $list= $this->model->with(["act","platformYz"=>["platform","good"],"promocode"])->where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $list->each(function($item,$key){
+            $item['status_cn']=ActGood::$statusCn[$item['status']]??"";
+            $item['act_status_cn']=\app\txx\model\Act::$statusCn[$item['act_status']]??"";
+            return $item;
+        });
+        $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+    }
+    public function info(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->with(["act","platformYz"=>["platform","good"],"promocode"])->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        $info['status_cn']=ActGood::$statusCn[$info['status']]??"";
+        $info['act_status_cn']=\app\txx\model\Act::$statusCn[$info['act_status']];
+        $this->success("获取成功",$info);
+    }
+    public function resetPromocode(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        if(!in_array($info->status,[4,5]))throw new \Exception("状态有误");
+        $info->status=1;
+        try{
+           if($info->promocode_id!==0){
+            $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id);
+            if($promocode->isEmpty())throw new \Exception('优惠券信息有误');
+            $promocode->save(['status'=>0]);
+
+        }else{
+            $info->promocode_id=0;
+        }
+        $save= $info->save();
+        if(!$save)throw new \Exception('重置失败');
+        }catch (\Exception $e){
+            $this->error($e->getMessage());
+        }
+        $this->success("重置成功");
+    }
+
+    public function delete(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        $info->is_del=1;
+        try{
+            $save= $info->save();
+            if(!$save)throw new \Exception('删除失败');
+            if($info->promocode_id!==0){
+                $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id);
+                if($promocode->isEmpty())throw new \Exception('优惠券信息有误');
+                $promocode->save(['is_del'=>1]);
+            }
+        }catch (\Exception $e){
+            $this->error($e->getMessage());
+        }
+        $this->success("删除成功");
+    }
+}

+ 60 - 0
app/txx/controller/Base.php

@@ -0,0 +1,60 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\controller;
+
+use app\BaseController;use think\App;
+use think\exception\HttpResponseException;
+use think\Response;
+
+
+class Base extends BaseController
+{
+	public $white=[];
+	public function __construct(App $app) {
+  	    parent::__construct($app);
+    }
+  
+   /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+    public function error($message='',$code=1003,$data=null){
+        $this->result($message,$data,$code);
+    }
+    /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+     public function success($message='',$data=null,$code=0){
+        $this->result($message,$data,$code);
+    }
+    
+     /**
+	* @param string $msg
+	* @param null $data
+	* @param int $code
+	* @param string|null $type
+	* @param array $header
+	* @param array $options
+	 */
+    private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array
+    $options = [])
+    {
+        $result = [
+            'code' => $code,
+            'message'  => $msg,
+            'data' => $data,
+        ];
+        $code = 200;
+        if (isset($header['statuscode'])) {
+            $code = $header['statuscode'];
+            unset($header['statuscode']);
+        }
+
+        $response = Response::create($result, $type, $code)->header($header)->options($options);
+         throw new HttpResponseException($response);
+    }
+}

+ 18 - 21
app/txx/controller/Good.php

@@ -18,7 +18,7 @@ class Good extends BaseController
 {
 	protected $uid=0;
 	protected $uname='';
-	protected $platformid=37;
+	protected $platformid=[37,79];
 	/**@param array snArr 商品编号sn数组
      * @param string actCode 活动编号
 	* @return \think\response\Json
@@ -39,26 +39,27 @@ class Good extends BaseController
 
     public function AddGood()
     {
-    	$post = $this->request->only(["snArr"=>[],"actCode"=>''],"post");
+    	$post = $this->request->only(["snArr"=>[],"actCode"=>''],"post","trim");
     	$snArr= $post['snArr'];
     	if(empty($snArr)) return  json_show(1004,"参数错误 snArr 不能为空");
     	$platformYouzan =new PlatformYouzan();
     	$skuCodes = array_column($snArr,"skuCode");
 		$goodArr = $platformYouzan->where(["skuCode"=>$skuCodes,"is_del"=>0])->select()->toArray();
 		if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
+		$goodArr = array_column($goodArr,"skuCode");
 		$actCode= $post['actCode']!=''? trim($post['actCode']):"";
 		if($actCode=='') return json_show(1004,"参数错误 actCode 不能为空");
 		$act =new Act();
 		$isActExit=$act->where(['actCode'=>$actCode,"is_del"=>0])->find();
-		if($isActExit==false) return json_show(1005,"未找到活动有效数据");
-
+		if($isActExit->isEmpty()) return json_show(1005,"未找到活动有效数据");
 		$actGood=new ActGood();
 		Db::startTrans();
 		try{
 			$data=[];
 			foreach ($snArr as $item){
-				$isExit = $actGood->find(["actCode"=>$actCode,"yz_good_code"=>$item['skuCode'],"roundId"=>$item['roundId']??"","is_del"=>0]);
-				if($isExit) throw new Exception("活动商品已添加",1006);
+			    if(!in_array($item['skuCode'],$goodArr)) throw new Exception("商品编号{$item['skuCode']}不存在",1006);
+				$isExit = $actGood->where(['actCode'=>$actCode,'yz_good_code'=>$item['skuCode'],'roundId'=>$item['roundId']??'','is_del'=>0])->findOrEmpty();
+				if(!$isExit->isEmpty()) throw new Exception("活动商品已添加",1006);
 				$temp=[
 					"actCode"=>$actCode,
 					"yz_good_code"=>$item['skuCode'],
@@ -68,6 +69,7 @@ class Good extends BaseController
 					"apply_id"=>$this->uid,
 					"apply_name"=>$this->uname,
 					"roundId"=>$item['roundId']??"",
+					"version"=>"2.0",
 					"status"=>1,
 					"addtime"=>date("Y-m-d H:i:s"),
 					"updatetime"=>date("Y-m-d H:i:s")
@@ -77,20 +79,19 @@ class Good extends BaseController
 			if (empty($data)){
 					throw new Exception("活动商品不能为空",1006);
 			}
-			$isAdd=ActGood::insertAll($data);
-			if ($isAdd==false){
-					throw new Exception("活动商品添加失败",1006);
-			}
+			$isAdd=$actGood->saveAll($data);
+			if ($isAdd->isEmpty())throw new Exception("活动商品添加失败",1006);
+
 			$up =$act->where($isActExit->toArray())->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
 			if ($up==false){
 				throw new Exception("活动商品添加失败",1006);
 			}
 			Db::commit();
-			return json_show(0,"活动商品添加成功");
 		}catch (\Exception $e){
 			Db::rollback();
 			return json_show(1008,$e->getMessage());
 		}
+		return json_show(0,'活动商品添加成功');
     }
 
     /**活动商品列表
@@ -145,11 +146,11 @@ class Good extends BaseController
        if($this->request->isCx==1){
        	$field="a.id,a.actCode,a.yz_good_code,a.apply_id,a.apply_name,a.stock_num,a.used_num,a.balance_num,a.status,
       a.addtime,a.updatetime,c.plat_code,b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,
-     c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,a.roundId,d.brand_id";
+     c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,a.roundId,d.brand_id,a.roundId,a.promocode_id";
        }else{
 		$field="a.id,a.actCode,a.yz_good_code,a.stock_num,a.used_num,a.balance_num,a.status,a.addtime,a.updatetime,
 		b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,c.final_price,c.desc,d.good_name,
-		d.good_unit,d.cat_id,d.brand_id,a.roundId";
+		d.good_unit,d.cat_id,d.brand_id,a.roundId,a.promocode_id";
        }
       $count =$actm->alias("a")
       ->leftJoin("act b","a.actCode=b.actCode")
@@ -204,16 +205,14 @@ class Good extends BaseController
     	$goodCode = array_column($snArr,"yz_good_code");
 		$goodArr = $platformYouzan->where(["skuCode"=>$goodCode,"is_del"=>0])->select()->toArray();
 		if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
-//	    $roundId= $post['roundId']!=''? trim($post['roundId']):"";
-//	    if($roundId=='') return json_show(1004,"参数错误 roundId 不能为空");
 		$actGood=new ActGood();
 		Db::startTrans();
 		try{
 			$data=[];
 			foreach ($snArr as $item){
 				$isExit = $actGood->where(["actCode"=>$item['actCode'],"yz_good_code"=>$item['yz_good_code'],
-				"is_del"=>0])->find();
-				if($isExit==false) throw new Exception("活动商品不存在",1006);
+				"is_del"=>0])->findOrEmpty();
+				if($isExit->isEmpty()) throw new Exception("活动商品不存在",1006);
 				$temp=[
 					"id"=>$isExit['id'],
 					"stock_num"=>$item['stock_num'],
@@ -226,9 +225,7 @@ class Good extends BaseController
 
 			}
 			$isAdd=$actGood->saveAll($data);
-			if ($isAdd==false){
-					throw new Exception("活动商品更新失败",1006);
-			}
+			if ($isAdd==false)throw new Exception("活动商品更新失败",1006);
 			Db::commit();
 			return json_show(0,"活动商品更新成功");
 		}catch (\Exception $e){
@@ -453,7 +450,7 @@ class Good extends BaseController
             'plat_code' => '',
             'exam_status' => '',
         ], 'post', 'trim');
-        $where = [["b.is_del", "=", 0],["b.platform_id","=",$this->platformid]];
+        $where = [["b.is_del", "=", 0],["b.platform_id","in",$this->platformid]];
         if ($param['good_name'] !== "") $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
         if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
         if ($param['plat_code'] !== '') $where[] = ["b.plat_code", "like", '%' . $param['plat_code'] . '%'];

+ 10 - 0
app/txx/middleware.php

@@ -0,0 +1,10 @@
+<?php
+// 全局中间件定义文件
+return [
+    // 全局请求缓存
+//    app\txx\middleware\CheckAuth::class
+    // 多语言加载
+    // \think\middleware\LoadLangPack::class,
+    // Session初始化
+    // \think\middleware\SessionInit::class
+];

+ 7 - 1
app/txx/model/Act.php

@@ -10,5 +10,11 @@ use think\Model;
  */
 class Act extends Model
 {
-    //
+    protected $createTime='addtime';
+    protected $updateTime="updatetime";
+     public static $statusCn=['待选择商品','待同步创建优惠券码','待同步优惠券码','待确认上传至活动主办方','已确认上传至活动主办方','券码创建失败','券码同步失败'];
+
+    public function goodInfo(){
+        return $this->hasMany(ActGood::class,'actCode','actCode')->where(['is_del'=>0])->with(['platformYz'=>["good","platform"]]);
+    }
 }

+ 16 - 11
app/txx/model/ActGood.php

@@ -3,24 +3,29 @@ declare (strict_types = 1);
 
 namespace app\txx\model;
 
-use think\Exception;use think\Model;
+;use think\Model;
 
 /**
  * @mixin \think\Model
  */
 class ActGood extends Model
 {
+    protected $createTime='addtime';
+    protected $updateTime='updatetime';    //
+     public static $statusCn=['无状态','待生成券码信息','待同步券码信息','已同步券码信息','券码生成失败','券码同步失败'];
     //
-    static function ActAdd(array $Good, string $actCode,array $userinfo=[]){
-    	if (empty($Good)) throw new Exception("参与活动商品不能为空",1006);
-    	self::startTrans();
-    	$data=[];
-    	foreach ($Good as $item ){
-			$temp=[
-				"actCode"=>$actCode,
-				"yz_good_id"=>$item['id'],
+    public function act(){
+        return $this->belongsTo(Act::class,'actCode','actCode')->bind(['act_anme','startTime','endTime','company_name','contactor','mobile','act_status'=>'status']);
+    }
+
+    public function Promocode(){
+        return $this->belongsTo(YzActivityPromoCode::class,'id','act_good_id')->bind(['title','code','fetch_url','promocode_status'=>'status','promocode_remark'=>'remark']);
+    }
+    public function yzGood(){
+        return $this->belongsTo(YzGood::class,'yz_good_code','item_no')->bind(['good_name'=>'title','detail_url']);
+    }
 
-			];
-    	}
+    public function platformYz(){
+        return $this->belongsTo(PlatformYouzan::class,'yz_good_code','skuCode')->bind(['plat_code','spuCode','sale_price','final_price','platform_name','good_name']);
     }
 }

+ 14 - 1
app/txx/model/PlatformYouzan.php

@@ -3,12 +3,25 @@ declare (strict_types = 1);
 
 namespace app\txx\model;
 
-use think\model;
+use app\model\GoodBasic;use app\model\Platform;use think\model;
 
 /**
  * @mixin \think\Model
  */
 class PlatformYouzan extends Model
 {
+    protected $createTime='addtime';
+    protected $updateTime='updatetime';
+    public function good(){
+        return $this->belongsTo(GoodBasic::class,'spuCode','spuCode')
+        ->bind(['good_name','cat_id','is_exclusive','brand_id','good_img','good_unit','unit_name','brand_name','cat_name','cat_search']);
+    }
 
+    public function platform(){
+        return $this->belongsTo(Platform::class,'platform_id','id')->bind(['platform_name']);
+    }
+
+    public function yzGood(){
+        return $this->belongsTo(YzGood::class,'skuCode','item_no')->bind(['origin_price'=>'origin','deatil_url','yz_status'=>'status']);
+    }
 }

+ 13 - 0
app/txx/model/YzActivityPromoCode.php

@@ -0,0 +1,13 @@
+<?php
+
+
+namespace app\txx\model;
+use think\Model;
+
+class YzActivityPromoCode  extends  Model{
+
+    protected $connection = 'mysql_yz';//切换连接参数
+    protected $table = 'yz_activity_promocode';
+    protected $pk = 'id';
+    protected $autoWriteTimestamp = false;
+}

+ 7 - 7
config/database.php

@@ -59,21 +59,21 @@ return [
 		],
 		//连接有赞对接项目的数据库
 		"mysql_yz" => [
-			'type' => env('database.type', 'mysql'),
+			'type' => env('mysql_yz.type', 'mysql'),
 			// 服务器地址
-			'hostname' => env('database.hostname', ''),
+			'hostname' => env('mysql_yz.hostname', ''),
 			// 数据库名
-			'database' => env('database.database1', ''),
+			'database' => env('mysql_yz.database', ''),
 			// 用户名
-			'username' => env('database.username', ''),
+			'username' => env('mysql_yz.username', ''),
 			// 密码
-			'password' => env('database.password', ''),
+			'password' => env('mysql_yz.password', ''),
 			// 端口
-			'hostport' => env('database.hostport', '3306'),
+			'hostport' => env('mysql_yz.hostport', '3306'),
 			// 数据库连接参数
 			'params' => [],
 			// 数据库编码默认采用utf8
-			'charset' => env('database.charset', 'utf8'),
+			'charset' => env('mysql_yz.charset', 'utf8'),
 			'prefix' => 'yz_',
 		],
 	],