| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * 今日的累计.
- *
- * @author nj
- * @date 2021-08-02 12:21
- */
- namespace App\Jobs\Statistics;
- use App\Repositories\Statistics\StatisticsAgentAttrsRepository;
- use Carbon\Carbon;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class AgentAttrsTodayJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * 定义仓库.
- * @var null|StatisticsAgentAttrsRepository
- */
- protected $repo = null;
- /**
- * 指定队列.
- * @var string
- */
- // public $queue = 'attrs_today';
- /**
- * 日期.
- * @var string
- */
- protected $date = '';
- protected $channelUid = null;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(string $date, $channelUid = null)
- {
- $this->date = $date;
- $this->channelUid = $channelUid;
- $this->onQueue('attrs_today');
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- $date = Carbon::parse($this->date)->toDateString();
- if (is_null($this->channelUid)) {
- // 统计全部.
- $result = self::runJob($date);
- } else {
- // 统计渠道
- $result = self::runJob($date, $this->channelUid);
- }
- }
- /**
- * 执行统计.
- * @param string $date 日期
- * @param null $channelUid 渠道UID
- * @return bool
- */
- protected function runJob($date, $channelUid = null)
- {
- $this->getRepo()->todayJob($date, $channelUid);
- // Todo.
- self::notify();
- return true;
- }
- /**
- * 发送通知, 重新读取数据然后拼接数据,发送邮箱或者tg.
- */
- private function notify()
- {
- // Todo 发送通知, 重新读取数据然后拼接数据,发送邮箱或者tg.
- }
- /**
- * 获取属性统计仓库.
- * @return StatisticsAgentAttrsRepository
- */
- private function getRepo()
- {
- if (!$this->repo instanceof StatisticsAgentAttrsRepository) {
- $this->repo = new StatisticsAgentAttrsRepository();
- }
- return $this->repo;
- }
- }
|