123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- declare (strict_types = 1);
- namespace app\txx\model;
- ;use think\Model;
- /**
- * @mixin \think\Model
- */
- class ActGood extends Model
- {
- protected $createTime='addtime';
- protected $updateTime='updatetime'; //
- public static $statusCn=['无状态','待生成券码信息','待同步券码信息','已同步券码信息','券码生成失败','券码同步失败','同步券码信息中'];
- //
- 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();
- }
- }
- }
- }
|