123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- declare (strict_types = 1);
- namespace app\txx\command;
- use app\txx\model\YzActivityPromoCode;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;use think\facade\Cache;
- class ActGood extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('actgood')
- ->setDescription('the actgood command');
- }
- protected function execute(Input $input, Output $output)
- {
- if(Cache::get("createPro1")==1) return;
- Cache::set("createPro1",1,60);
- try {
- $output->writeln('<info>actgood</info>');
- $actgood = \app\txx\model\ActGood::with(['act'])->where(['version'=>'2.0','status'=>1,'is_del'=>0,'promocode_id'=>0])->findOrEmpty();
- if(!$actgood->isEmpty())$this->createPromocode($actgood);
- }catch (\Exception $e){
- $output->writeln('<error>'.$e->getMessage().'</error>');
- }
- Cache::set("createPro1",0);
- }
- /**id
- act_good_id
- skuCode
- item_id
- title
- is_at_least
- code
- is_forbid_preference
- specify_item_ids
- is_share
- start_at
- end_at
- total
- expire_notice
- quota
- cent_value
- code_type
- range_type
- at_least
- status
- group_id
- is_expired
- fetch_url
- createTime
- updateTime
- * @param $actgood
- */
- //
- public function createPromocode($actgood){
- $promocode = YzActivityPromoCode::where(["act_good_id"=>$actgood->id,"skuCode"=>$actgood->yz_good_code,'is_del'=>0])->findOrEmpty();
- if($promocode->isEmpty()){
- $promocode = YzActivityPromoCode::create([
- "act_good_id"=>$actgood->id,
- "actCode"=>$actgood->actCode,
- "skuCode"=>$actgood->yz_good_code,
- "item_id"=>0,
- "title"=>$actgood->act_name,
- "is_at_least"=>0,
- "code"=>"",
- "is_forbid_preference"=>1,
- "specify_item_ids"=>"",
- "is_share"=>0,
- "start_at"=>startTime($actgood->startTime),
- "end_at"=>endTime(date("Y-m-d H:i:s",strtotime($actgood->endTime)+3600*24*7)),
- "total"=>$actgood->balance_num,
- "expire_notice"=>1,
- "quota"=>1,
- "cent_value"=>0,
- "code_type"=>'GENERAL',
- "range_type"=>"PART",
- "at_least"=>0,
- "status"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ]);
- if(!$promocode->isEmpty()){
- $actgood->promocode_id = $promocode->id;
- $actgood->status = 2; //生成券码
- $actgood->save();
- }else {
- $actgood->remark = "优惠券信息创建失败";
- $actgood->status = 4;
- $actgood->save();
- }
- }else{
- $actgood->remark = "优惠券信息已存在";
- $actgood->status = 4;
- $actgood->save();
- }
- }
- }
|