ActGood.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\model;
  4. ;use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class ActGood extends Model
  9. {
  10. protected $createTime='addtime';
  11. protected $updateTime='updatetime'; //
  12. public static $statusCn=['无状态','待生成券码信息','待同步券码信息','已同步券码信息','券码生成失败','券码同步失败','同步券码信息中'];
  13. //
  14. public function act(){
  15. return $this->belongsTo(Act::class,'actCode','actCode')->bind(['act_anme','startTime','endTime','company_name','contactor','mobile','act_status'=>'status']);
  16. }
  17. public function Promocode(){
  18. return $this->belongsTo(YzActivityPromoCode::class,'id','act_good_id')->where("is_del",0)->bind(['title','code','fetch_url','promocode_status'=>'status','promocode_remark'=>'remark']);
  19. }
  20. public function yzGood(){
  21. return $this->belongsTo(YzGood::class,'yz_good_code','item_no')->bind(['good_name'=>'title','detail_url']);
  22. }
  23. public function platformYz(){
  24. 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"]);
  25. }
  26. public static function onAfterUpdate(Model $model) : void{
  27. if($model->version=='2.0' && $model->is_del==0 && $model->status!=3){
  28. self::sysncAct($model->actCode,$model->status,$model->version);
  29. }
  30. }
  31. // 0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
  32. //'待选择商品','待同步创建优惠券码','待同步优惠券码','待确认上传至活动主办方','已确认上传至活动主办方','券码创建失败','券码同步失败'
  33. public static function sysncAct($actCode,$goodStatus,$version){
  34. $actStatus=['1'=>'1','2'=>'2','4'=>'5','5'=>'6','6'=>'3'];//0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
  35. $num = self::where(['version'=>$version,'actCode'=>$actCode,'is_del'=>0])->where('status','<>',$goodStatus)->count();
  36. if($num==0){
  37. $act = \app\txx\model\Act::where(['actCode'=>$actCode])->findOrEmpty();
  38. if(!$act->isEmpty()){
  39. $act->status=$actStatus[$goodStatus];
  40. $act->save();
  41. }
  42. }
  43. }
  44. }