NationalDay.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Modules\Activity\Services;
  3. use App\Modules\Product\Models\Product;
  4. /**
  5. * 个人微信号——国庆活动
  6. *
  7. * @property int $start_time 活动开始时间
  8. * @property int $end_time 活动结束时间
  9. * @property string $title 活动名称
  10. * @property int $product_id 活动充值选项id
  11. * @property array $sign_config 活动签到配置
  12. * @property \App\Modules\Product\Models\Product $product 活动充值选项
  13. * @property bool $is_begin 活动是否开始
  14. * @property bool $is_end 活动是否结束
  15. * @property string $redis_key redis键值
  16. */
  17. trait NationalDay
  18. {
  19. public $start_time;
  20. public $end_time;
  21. public $title;
  22. public $product_id;
  23. public $product;
  24. public $sign_config;
  25. public $is_begin;
  26. public $is_end;
  27. private $redis_key;
  28. public function __construct()
  29. {
  30. $this->start_time = strtotime('2019-10-01');
  31. $this->end_time = strtotime('2019-10-08');
  32. $this->title = "十月金秋&国庆666书币福利";
  33. $this->product_id = 7498;
  34. $this->product = $this->getProduct();
  35. $this->sign_config = [
  36. ['day' => 1, 'bonus' => 50, 'is_strong' => false],
  37. ['day' => 2, 'bonus' => 50, 'is_strong' => false],
  38. ['day' => 3, 'bonus' => 100, 'is_strong' => true],
  39. ['day' => 4, 'bonus' => 50, 'is_strong' => false],
  40. ['day' => 5, 'bonus' => 50, 'is_strong' => false],
  41. ['day' => 6, 'bonus' => 50, 'is_strong' => false],
  42. ['day' => 7, 'bonus' => 266, 'is_strong' => true],
  43. ];
  44. $this->redis_key = 'activity_national_day:' . date('Ymd');
  45. $this->is_begin = time() >= $this->start_time;
  46. $this->is_end = time() >= $this->end_time;
  47. }
  48. /**
  49. * 获取签到奖励
  50. * @param int $days 累计签到天数
  51. * @return int
  52. */
  53. protected function getSignBonusMoney(int $days)
  54. {
  55. $config = collect($this->sign_config)->where('day', $days)->first();
  56. return $config ? $config['bonus'] : 0;
  57. }
  58. private function getProduct()
  59. {
  60. return Product::find($this->product_id);
  61. }
  62. }