PrizeCommand.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Console\Commands\Welfare;
  3. use App\Services\Welfare\NoticeService;
  4. use Illuminate\Console\Command;
  5. use App\Models\User\UserModel;
  6. use App\Models\Welfare\TicketModel;
  7. use App\Models\Welfare\LotteryModel;
  8. use App\Models\Welfare\JigsawFlowModel;
  9. use App\Models\Welfare\PrizeModel;
  10. class PrizeCommand extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'welfare:prize';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '福利发奖';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $lottery = LotteryModel::whereRaw("from_unixtime(`drawed_at`, '%Y-%m-%d %H:00:00') = ?", [
  41. date('Y-m-d H:00:00')
  42. ])
  43. ->first();
  44. if (!$lottery) {
  45. dd('活动不存在');
  46. }
  47. // 发奖品
  48. $tickets = TicketModel::where('lottery_id', $lottery->id)
  49. ->whereNotIn('uid', [20000001, 20010000])
  50. ->where('lucky', 1)
  51. ->get();
  52. foreach ($tickets as $ticket) {
  53. PrizeModel::create([
  54. 'uid' => $ticket->uid,
  55. 'title' => $lottery->title,
  56. 'cover_url' => $lottery->cover_url,
  57. 'cost' => $lottery->cost,
  58. ]);
  59. }
  60. $n = new NoticeService();
  61. // 发碎片
  62. $users = TicketModel::where('lottery_id', $lottery->id)
  63. ->whereNotIn('uid', [20000001, 20010000])
  64. ->distinct()
  65. ->pluck('uid');
  66. foreach ($users as $uid) {
  67. UserModel::where('uid', $uid)->increment('jigsaw_amount');
  68. JigsawFlowModel::create([
  69. 'uid' => $uid,
  70. 'source' => '参与抽奖获得',
  71. 'amount' => 1,
  72. 'remains_amount' => 1
  73. ]);
  74. // 通知
  75. $n->afterLottery($uid, $lottery->id);
  76. }
  77. }
  78. }