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