Prize.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Configs;
  5. use App\Models\Activitys;
  6. use App\Models\LotteryBoxs;
  7. class Prize extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'command:prize';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '抽奖宝箱信息处理';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $actIds = Activitys::where('status', 1)->where('is_complete_set', 1)->pluck('activity_id')->toArray();
  37. $prizeOpenIds = Configs::where('is_open_prize', 1)->whereIn('activity_id', $actIds)->pluck('activity_id');
  38. $i = 0;
  39. foreach($prizeOpenIds as $k=>$v){
  40. $actConfig = Configs::where('activity_id', $v)->first()->toArray();
  41. $levels = [1,2,3,4];
  42. $querys = [];
  43. foreach($levels as $key=>$val){
  44. $query['activity_id'] = $actConfig['activity_id'];
  45. $query['corp_id'] = $actConfig['corp_id'];
  46. switch($val){
  47. case 1:
  48. $query['lottery_level'] = 1;
  49. $query['lottery_name'] = '铜宝箱';
  50. $query['status'] = 1;
  51. $query['open_rule'] = $actConfig['copper_box_km'];
  52. $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_one.png';
  53. break;
  54. case 2:
  55. $query['lottery_level'] = 2;
  56. $query['lottery_name'] = '银宝箱';
  57. $query['status'] = 1;
  58. $query['open_rule'] = $actConfig['silver_box_km'];
  59. $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_two.png';
  60. break;
  61. case 3:
  62. $query['lottery_level'] = 3;
  63. $query['lottery_name'] = '金宝箱';
  64. $query['status'] = 1;
  65. $query['open_rule'] = $actConfig['gold_box_km'];
  66. $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_three.png';
  67. break;
  68. case 4:
  69. $query['lottery_level'] = 4;
  70. $query['lottery_name'] = '幸运宝箱';
  71. $query['status'] = 0;
  72. $query['open_rule'] = 0;
  73. $query['lottery_icon'] = '//s1-hn.aghcdn.com/brainstorming/prize/prize_four.png';
  74. break;
  75. }
  76. $query['open_mode'] = 'km';
  77. $query['create_time'] = time();
  78. $query['update_time'] = time();
  79. $box = LotteryBoxs::where('activity_id', $actConfig['activity_id'])
  80. ->where('corp_id', $actConfig['corp_id'])
  81. ->where('lottery_level', $query['lottery_level'])
  82. ->first();
  83. if(!$box){
  84. $querys[] = $query;
  85. }
  86. }
  87. $res = LotteryBoxs::insert($querys);
  88. if($res){
  89. echo $v.'=======成功'.PHP_EOL;
  90. } else {
  91. echo $v.'=======失败'.PHP_EOL;
  92. }
  93. $i++;
  94. }
  95. echo $i.'个活动同步成功';
  96. }
  97. }