ActGood.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\command;
  4. use app\txx\model\YzActivityPromoCode;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Argument;
  8. use think\console\input\Option;
  9. use think\console\Output;use think\facade\Cache;
  10. class ActGood extends Command
  11. {
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('actgood')
  16. ->setDescription('the actgood command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. if(Cache::get("createPro1")==1) return;
  21. Cache::set("createPro1",1,60);
  22. try {
  23. $output->writeln('<info>actgood</info>');
  24. $actgood = \app\txx\model\ActGood::with(['act'])->where(['version'=>'2.0','status'=>1,'is_del'=>0,'promocode_id'=>0])->findOrEmpty();
  25. if(!$actgood->isEmpty())$this->createPromocode($actgood);
  26. }catch (\Exception $e){
  27. $output->writeln('<error>'.$e->getMessage().'</error>');
  28. }
  29. Cache::set("createPro1",0);
  30. }
  31. /**id
  32. act_good_id
  33. skuCode
  34. item_id
  35. title
  36. is_at_least
  37. code
  38. is_forbid_preference
  39. specify_item_ids
  40. is_share
  41. start_at
  42. end_at
  43. total
  44. expire_notice
  45. quota
  46. cent_value
  47. code_type
  48. range_type
  49. at_least
  50. status
  51. group_id
  52. is_expired
  53. fetch_url
  54. createTime
  55. updateTime
  56. * @param $actgood
  57. */
  58. //
  59. public function createPromocode($actgood){
  60. $promocode = YzActivityPromoCode::where(["act_good_id"=>$actgood->id,"skuCode"=>$actgood->yz_good_code,'is_del'=>0])->findOrEmpty();
  61. if($promocode->isEmpty()){
  62. $promocode = YzActivityPromoCode::create([
  63. "act_good_id"=>$actgood->id,
  64. "actCode"=>$actgood->actCode,
  65. "skuCode"=>$actgood->yz_good_code,
  66. "item_id"=>0,
  67. "title"=>$actgood->act_name,
  68. "is_at_least"=>0,
  69. "code"=>"",
  70. "is_forbid_preference"=>1,
  71. "specify_item_ids"=>"",
  72. "is_share"=>0,
  73. "start_at"=>startTime($actgood->startTime),
  74. "end_at"=>endTime(date("Y-m-d H:i:s",strtotime($actgood->endTime)+3600*24*7)),
  75. "total"=>$actgood->balance_num,
  76. "expire_notice"=>1,
  77. "quota"=>1,
  78. "cent_value"=>0,
  79. "code_type"=>'GENERAL',
  80. "range_type"=>"PART",
  81. "at_least"=>0,
  82. "status"=>0,
  83. "addtime"=>date("Y-m-d H:i:s"),
  84. "updatetime"=>date("Y-m-d H:i:s")
  85. ]);
  86. if(!$promocode->isEmpty()){
  87. $actgood->promocode_id = $promocode->id;
  88. $actgood->status = 2; //生成券码
  89. $actgood->save();
  90. }else {
  91. $actgood->remark = "优惠券信息创建失败";
  92. $actgood->status = 4;
  93. $actgood->save();
  94. }
  95. }else{
  96. $actgood->remark = "优惠券信息已存在";
  97. $actgood->status = 4;
  98. $actgood->save();
  99. }
  100. }
  101. }