SupervipCommand.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands\User;
  3. use App\Managers\CouponManager;
  4. use App\Models\NoticeModel;
  5. use App\Models\User\UserModel;
  6. use App\Models\User\UserSysTagModel;
  7. use App\Services\Pay\CouponService;
  8. use Illuminate\Console\Command;
  9. class SupervipCommand extends Command
  10. {
  11. protected $signature = "supervip:store";
  12. protected $description = "";
  13. public function handle()
  14. {
  15. $tags = UserSysTagModel::where([
  16. ['supvip_endat', '>', time()],
  17. ['last_be_supvip_at', '<', 1559116560]
  18. ])->get();
  19. foreach ($tags as $tag) {
  20. $user = UserModel::findOrFail($tag->uid);
  21. // 1. 判断要给用户增加超级会员天数
  22. $xuvip = false;
  23. $user->supvip_endat > time() && $xuvip = true;
  24. $addday = 1;
  25. $xuvip ? $user->supvip_endat += $addday * 86400 : $user->supvip_endat = mktime(
  26. 0,
  27. 0,
  28. 0
  29. ) + (1 + $addday) * 86400;
  30. // 2. 记录kdgx_fpdx_user_record增加天数、修改到期时间
  31. if (UserSysTagModel::where('uid', $user->uid)->exists()) {
  32. $update = array('supvip_endat' => $user->supvip_endat, 'last_supvip_expire_notice_at' => 0);
  33. !$xuvip && $update['last_be_supvip_at'] = mktime(0, 0, 0);
  34. UserSysTagModel::where('uid', $user->uid)->increment('supvip_days', $addday, $update);
  35. } else {
  36. UserSysTagModel::create(array(
  37. 'uid' => $user->uid,
  38. 'supvip_days' => $addday,
  39. 'supvip_endat' => $user->supvip_endat,
  40. 'last_be_supvip_at' => mktime(0, 0, 0)
  41. ));
  42. }
  43. $user->save();
  44. // 3. 发放72h入场券
  45. $couponManager = new CouponManager();
  46. $couponManager->generateSuperVip72FreeCoupons($user->uid);
  47. NoticeModel::create([
  48. 'uid' => $user->uid,
  49. 'title' => '收到一张系统赠发的"72小时恋爱"活动入场券',
  50. 'content' => "亲爱的超级会员,近日小象陆续收到反馈,因时间原因部分月份存在5期活动开启报名的情况,为保证超级会员权益,系统特此赠发一张“入场券”,感谢你对小象的支持。",
  51. 'type' => 5,
  52. 'type_id' => 0,
  53. 'create_at' => time(),
  54. 'update_at' => time(),
  55. 'tab_content' => '去查看',
  56. 'tab_url' => '/pages/tickets/tickets',
  57. ]);
  58. }
  59. }
  60. }