123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
-
- namespace App\Console\Commands;
-
- use Illuminate\Console\Command;
- use App\Models\Configs;
- use App\Models\Activitys;
- use App\Models\LotteryBoxs;
-
- class Prize extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'command:prize';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '抽奖宝箱信息处理';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- * @return mixed
- */
- public function handle()
- {
- $actIds = Activitys::where('status', 1)->where('is_complete_set', 1)->pluck('activity_id')->toArray();
- $prizeOpenIds = Configs::where('is_open_prize', 1)->whereIn('activity_id', $actIds)->pluck('activity_id');
- $i = 0;
- foreach($prizeOpenIds as $k=>$v){
- $actConfig = Configs::where('activity_id', $v)->first()->toArray();
- $levels = [1,2,3,4];
- $querys = [];
- foreach($levels as $key=>$val){
- $query['activity_id'] = $actConfig['activity_id'];
- $query['corp_id'] = $actConfig['corp_id'];
- switch($val){
- case 1:
- $query['lottery_level'] = 1;
- $query['lottery_name'] = '铜宝箱';
- $query['status'] = 1;
- $query['open_rule'] = $actConfig['copper_box_km'];
- $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_one.png';
- break;
- case 2:
- $query['lottery_level'] = 2;
- $query['lottery_name'] = '银宝箱';
- $query['status'] = 1;
- $query['open_rule'] = $actConfig['silver_box_km'];
- $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_two.png';
- break;
- case 3:
- $query['lottery_level'] = 3;
- $query['lottery_name'] = '金宝箱';
- $query['status'] = 1;
- $query['open_rule'] = $actConfig['gold_box_km'];
- $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_three.png';
- break;
- case 4:
- $query['lottery_level'] = 4;
- $query['lottery_name'] = '幸运宝箱';
- $query['status'] = 0;
- $query['open_rule'] = 0;
- $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_four.png';
- break;
- }
- $query['open_mode'] = 'km';
- $query['create_time'] = time();
- $query['update_time'] = time();
- $box = LotteryBoxs::where('activity_id', $actConfig['activity_id'])
- ->where('corp_id', $actConfig['corp_id'])
- ->where('lottery_level', $query['lottery_level'])
- ->first();
- if(!$box){
- $querys[] = $query;
- }
- }
-
- $res = LotteryBoxs::insert($querys);
- if($res){
- echo $v.'=======成功'.PHP_EOL;
- } else {
- echo $v.'=======失败'.PHP_EOL;
- }
- $i++;
- }
- echo $i.'个活动同步成功';
- }
- }
|