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(); } } } }