소스 검색

Merge branch 'dev' of wugg/txx2023 into master

wugg 5 달 전
부모
커밋
e3d3e75b6a

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

@@ -9,13 +9,13 @@ use app\api\model\Cat;
 use app\api\model\GoodSpec;
 use app\api\model\PlatformYouzan;
 use app\api\model\Unit;
-use app\model\Good as YzGood;
+use app\txx\model\YzGood;
 use think\App;
 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();

+ 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
+{
+    //
+}

+ 74 - 32
app/txx/controller/Act.php

@@ -3,22 +3,22 @@ declare (strict_types = 1);
 
 namespace app\txx\controller;
 
-use app\BaseController;
+use app\txx\model\ActGood;
 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;
+	protected static $ActStatusCn=["无状态",'活动未开始','活动进行中',"活动已结束"];
+    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,8 +38,9 @@ class Act extends BaseController
         "start"=>'',
         "end"=>'',
         "status"=>'',
+        'act_status'=>'',
       	],"post",'trim');
-      $condition=[["is_del","=",0]];
+      $condition=[["is_del","=",0],["version","=","2.0"]];
       if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
       if($param['actCode']!='') $condition[]=["actCode","like","%{$param['actCode']}%"];
       if($param['company_name']!='') $condition[]=["company_name","like","%{$param['company_name']}%"];
@@ -48,12 +49,24 @@ 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)->order("id desc")
+      ->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);
+        $item['act_status_cn'] = self::$ActStatusCn[$item['act_status']];
+      });
+      $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
     }
 
     /**
@@ -66,11 +79,13 @@ class Act extends BaseController
        $param = $this->request->only([
        	"act_name"=>"",
        	"company_name"=>'',
+       	"depart"=>"",
        	"contactor"=>'',
        	"mobile"=>'',
        	"web_url"=>'',
        	"start"=>'',
        	"end"=>'',
+       	"settle_time"=>"",
        	"act_type"=>1,
        	],"post","trim");
 
@@ -79,8 +94,10 @@ class Act extends BaseController
             'company_name|活动公司名称' => 'require',
             'contactor|联系人' => 'require|max:255',
             'mobile|联系电话' => 'require',
+            "depart|部门"=>"require",
+            "settle_time|结算时间"=>"require",
         ]);
-        if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+        if($validate->check($param)==false)$this->error($validate->getError());
         $actCode=makeNo("ACE");
         $data=[
         	"actCode"=>$actCode,
@@ -88,19 +105,22 @@ class Act extends BaseController
         	"company_name"=>$param['company_name'],
         	"contactor"=>$param['contactor'],
         	"mobile"=>$param['mobile'],
+        	"depart"=>$param['depart'],
         	"act_type"=>$param['act_type'],
         	"startTime"=>$param['start']==''?null : $param['start'],
         	"endTime"=>$param['end']==''?null : $param['end'],
         	"web_url"=>$param['web_url']??"",
+        	"settle_time"=>date("Y-m-d H:i:s",strtotime($param['settle_time'])),
         	"status"=>0,
+        	"version"=>"2.0",
         	"apply_id"=>$this->uid,
         	"apply_name"=>$this->uname,
         	"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]);
     }
 
     /**
@@ -116,10 +136,12 @@ class Act extends BaseController
        	"company_name"=>'',
        	"contactor"=>'',
        	"mobile"=>'',
+       	"depart"=>"",
        	"web_url"=>'',
        	"start"=>'',
        	"end"=>'',
        	"actCode"=>'',
+       	'settle_time'=>'',
        	"act_type"=>1,
        	],"post","trim");
 
@@ -129,24 +151,31 @@ class Act extends BaseController
             'company_name|活动公司名称' => 'require',
             'contactor|联系人' => 'require|max:255',
             'mobile|联系电话' => 'require',
+            'depart|部门'=>'require',
+            'settle_time|结算时间'=>'require',
         ]);
-        if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+        if($validate->check($param)==false)$this->error($validate->getError());
          $actm=new Actm();
         $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
-        if($info==false) return json_show(1005,"活动不存在");
+        if($info->isEmpty())$this->error("活动不存在");
+        if($info->status==1)$this->error("活动已发布,不能编辑");
+
         $data=[
         	"act_name"=>$param['act_name'],
         	"company_name"=>$param['company_name'],
         	"contactor"=>$param['contactor'],
         	"mobile"=>$param['mobile'],
         	"act_type"=>$param['act_type'],
+        	"depart"=>$param['depart'],
+        	"settle_time"=>date("Y-m-d H:i:s",strtotime($param['settle_time'])),
         	"startTime"=>$param['start']==''?null : $param['start'],
         	"endTime"=>$param['end']==''?null : $param['end'],
         	"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 +189,19 @@ 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();
+      if($info->isEmpty()) $this->error("活动不存在");
+      $info['act_status']=time()< strtotime($info['startTime'])?1:(time()> strtotime($info['endTime'])?3:2);
+      $info['goodInfo']->each(function(&$item){
+          $item['status_cn']=ActGood::$statusCn[$item['status']]??'';
+      });
+      $info['statusCn'] = \app\txx\model\Act::$statusCn[$info['status']]??'';
+      $info['act_status_cn']=self::$ActStatusCn[$info['act_status']];
+      $info['goodInfo']->visible(['id','actCode','yz_good_code','stock_num','status','addtime','updatetime',
+        'sale_price','good_name','unit_name','cat_name','brand_name','fetch_url','roundId','status_cn']);;
+      $this->success("获取成功",$info);
     }
 
       /**
@@ -174,14 +212,18 @@ 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("删除成功");
+
     }
+
 }

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

@@ -0,0 +1,210 @@
+<?php
+
+
+namespace app\txx\controller;
+
+
+use app\api\model\GoodSpec;
+use app\txx\model\ActGood;
+use app\txx\model\PlatformYouzan;
+use app\txx\model\YzActivityPromoCode;use think\App;
+use think\facade\Validate;
+class Activity extends Base{
+    private $platform_id=[37,79];
+    private $model;
+    private $origin_img_host ='http://stock.api.caixiao365.com';
+    private  $ssl_img_host ='https://image.caixiao365.com';
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ActGood();
+    }
+    public function goodList(){
+        $param = $this->request->param(["good_name"=>"","skuCode"=>'',"plat_code"=>'',"page"=>1,"size"=>15],"post","trim");
+        $where=[["is_del","=",0],["platform_id",'in',$this->platform_id],['exam_status','=',6]];
+        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']."%"];
+
+        $list=PlatformYouzan::with(["good"=>["unit","category","brand"],"platform"])
+        ->where($where)->order("id desc")
+        ->field("id,plat_code,spuCode,skuCode,sale_price,final_price,exam_status,online_time,creater")
+        ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $list->each(function (&$item) {
+            $item->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_img);
+       	    $item->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_info_img);
+       	    $item->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$item->good_thumb_img);
+            $item['spec_info'] =GoodSpec::where(['spuCode' => $item['spuCode'], 'is_del' => 0])->with(['spec',
+          			'Spec_info'])->field('spec_id,spec_value_id')->select();
+        });
+        $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();
+        if(count($goodArr->toArray())!==count($param['snArr'])){
+            $this->error("商品信息有误");
+        }
+        $yzGood = array_column($goodArr->toArray(),"yzGood","skuCode");
+        $Act = \app\txx\model\Act::where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+        if($Act->isEmpty()){
+            $this->error("活动信息有误");
+        }
+        if($Act->status!==0){
+            $this->error("活动状态有误");
+        }
+        if(strtotime($Act->endTime)<time()){
+            $this->error("活动已结束");
+        }
+         if(strtotime($Act->startTime)<time()){
+            $this->error('活动已开始');
+        }
+         $valids= Validate::rule([
+            "skuCode|商品编码"=>"require|max:20",
+            "stock_num|库存数量"=>"require|integer",
+            "awards_type|商品类型"=>"require|max:255",
+            "roundId|轮次"=>"integer",
+        ]);
+       $actArr=[];
+        foreach ($param['snArr'] as $k=>$v){
+                if(!$valids->check($v)){
+                    $this->error($valids->getError());
+                }
+
+                if(!isset($yzGood[$v['skuCode']]))  $this->error('商品信息有误');
+                 if($yzGood[$v['skuCode']]['status']!==6)  $this->error($v['skuCode'].'有赞商品未上线');
+                 $temp=[
+					'actCode'=>$param['actCode'],
+					'yz_good_code'=>$v['skuCode'],
+					'goodName'=>$yzGood[$v['skuCode']]['title']??'',
+					'stock_num'=>$v['stock_num'],
+					"awards_type"=>$v['awards_type'],
+					'used_num'=>0,
+					"version"=>"2.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],['version',"=","2.0"]];
+        if($param['actCode']!==""){
+            $where[]=["actCode","like","%".$param['actCode']."%"];
+        }
+        if($param['status']!==""){
+            $where[]=["status","=",$param['status']];
+            if($param['status']==3) $where[]=["used_num",">=",$param['stock_num']];
+        }
+        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"=>["unit","brand","category"]],"promocode"])
+        ->where($where)->order("id desc")
+        ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $list->visible(['id',"actCode","yz_good_code","stock_num","awards_type","status","addtime","updatetime","act_name",
+        "company_name","contactor","mobile","startTime","endTime","act_status","sale_price","good_name","unit_name","cat_name",
+        "brand_name","fetch_url","roundId","status_cn","ActStatus_cn","awards_order_num"]);
+        $list->each(function (&$item){
+            $item['status_cn']=ActGood::$statusCn[$item['status']]??"";
+            $item['ActStatus_cn']=\app\txx\model\Act::$statusCn[$item['act_status']];
+            if($item['act_status']!==4){
+                $item['fetch_url']=null;
+            }
+            $item['awards_order_num']=YzActivityPromoCode::GetOrderNumById($item['id']);
+        });
+        $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"=>['unit','brand','category']],"promocode"])->where(["is_del"=>0])->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+         $info->visible(['id','actCode','yz_good_code','awards_type','stock_num','status','addtime','updatetime','act_name',
+        'company_name','contactor','mobile','startTime','endTime','act_status','final_price','good_name','unit_name','cat_name',
+        'brand_name','fetch_url','roundId','status_cn','act_status_cn']);
+        $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("状态有误");
+
+        try{
+           if($info->promocode_id!==0){
+            $promocode= \app\youzan\model\YzActivityPromoCode::where(["is_del"=>0,"id"=>$info->promocode_id])->findOrEmpty();
+            if($promocode->isEmpty()){
+                 $info->promocode_id=0;
+                 $info->status=1;
+            }else {
+                $promocode->save(['status'=>0]);
+                $info->remark="重试生成券码";
+            }
+
+        }else{
+            $info->promocode_id=0;
+            $info->status=1;
+        }
+        $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::where(['is_del'=>0,'id'=>$info->promocode_id])->findOrEmpty();
+                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
+];

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

@@ -10,5 +10,27 @@ 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"=>['unit','brand','category'],"platform"]]);
+    }
+
+        public static function onAfterUpdate(Model $model) : void{
+        if($model->version=='2.0' && $model->is_del==0 && $model->status==4){
+            self::sysncAct($model->actCode,$model->status,$model->version);
+         }
+     }
+
+     public static function sysncAct($actCode,$actStatus,$version){
+        $list=ActGood::where(['version'=>$version,'actCode'=>$actCode,'is_del'=>0,'status'=>6])->select();
+        if(!$list->isEmpty()){
+            ActGood::where(['version'=>$version,'actCode'=>$actCode,'is_del'=>0,'status'=>6])->update(['status'=>3]);
+        }
+
+     }
 }

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

@@ -3,24 +3,49 @@ 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')->where("is_del",0)->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',"unit_name","brand_name","cat_name","cat_search"]);
     }
+
+    public static function onAfterUpdate(Model $model) : void{
+        if($model->version=='2.0' && $model->is_del==0 && $model->status!=3){
+            self::sysncAct($model->actCode,$model->status,$model->version);
+         }
+     }
+
+    // 0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
+    //'待选择商品','待同步创建优惠券码','待同步优惠券码','待确认上传至活动主办方','已确认上传至活动主办方','券码创建失败','券码同步失败'
+    public static function sysncAct($actCode,$goodStatus,$version){
+                $actStatus=['1'=>'1','2'=>'2','4'=>'5','5'=>'6','6'=>'3'];//0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
+                $num = self::where(['version'=>$version,'actCode'=>$actCode,'is_del'=>0])->where('status','<>',$goodStatus)->count();
+               if($num==0){
+                    $act = \app\txx\model\Act::where(['actCode'=>$actCode])->findOrEmpty();
+                    if(!$act->isEmpty()){
+                        $act->status=$actStatus[$goodStatus];
+                        $act->save();
+                    }
+               }
+     }
 }

+ 15 - 0
app/txx/model/PlatformYouzan.php

@@ -3,6 +3,8 @@ declare (strict_types = 1);
 
 namespace app\txx\model;
 
+use app\model\GoodBasic;
+use app\model\Platform;
 use think\model;
 
 /**
@@ -10,5 +12,18 @@ use 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_info_img","good_thumb_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');
+    }
 }

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

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace app\txx\model;
+use think\Model;
+
+class YzActivityPromoCode  extends  Model{
+
+    protected $connection = 'mysql_yz';//切换连接参数
+    protected $name = 'activity_promocode';
+    protected $pk = 'id';
+    protected $autoWriteTimestamp = false;
+    protected $createTime='createTime';
+    protected $updateTime='updateTime';
+
+    public static function GetOrderNumById($id){
+      $coupid= self::where(["act_good_id"=>$id])->value("group_id",0);
+      if ($coupid>0){
+          return self::name("order_promotion")->where(["coupon_id"=>$coupid])->count();
+      }
+      return 0;
+    }
+}

+ 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_',
 		],
 	],