date = $date; $this->channelUid = $channelUid; } /** * 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) { $date = Carbon::parse($date)->toDateString(); // 统计全部. $total = $this->getRepo()->countOneDayActive($date, $channelUid); $android = $this->getRepo()->countOneDayActive($date, $channelUid, 'A'); $ios = $this->getRepo()->countOneDayActive($date, $channelUid, 'I'); $h5 = $this->getRepo()->countOneDayActive($date, $channelUid, 'H'); $item = [ 'date' => $date, 'total' => $total, 'android' => $android, 'ios' => $ios, 'h5' => $h5, ]; $sqlChannelUid = ''; $item['mom_app_uid'] = ''; // 预先设置母包UID $item['agent_uid'] = ''; // 预先定义代理UID if (!is_null($channelUid)) { $item['channel_uid'] = $channelUid; $sqlChannelUid = $channelUid; if (!empty($item['channel_uid'])) { $channelObj = ChannelModel::where(['uid' => $item['channel_uid']])->first(); if (!empty($channelObj)) { // 补充母包UID $item['mom_app_uid'] = $channelObj->mom_app_uid; $item['agent_uid'] = $channelObj->agent_uid; } } $info = StatisticsActiveModel::whereDate('date', '=', $date) ->where('channel_uid', '=', $sqlChannelUid) ->first(); } else { $info = StatisticsActiveModel::whereDate('date', '=', $date) ->whereNull('channel_uid') ->where('mom_app_uid', '=', '') ->first(); } if (!empty($info)) { $info->total = $total; $info->android = $android; $info->ios = $ios; $info->h5 = $h5; $result = $info->save(); } else { $result = StatisticsActiveModel::create($item); } // Todo. self::notify(); return boolval($result); } /** * 发送通知, 重新读取数据然后拼接数据,发送邮箱或者tg. */ private function notify() { // Todo 发送通知, 重新读取数据然后拼接数据,发送邮箱或者tg. } /** * 获取仓库. * @return StatisticsActiveRepository */ private function getRepo() { if (!$this->repo instanceof StatisticsActiveRepository) { $this->repo = new StatisticsActiveRepository(); } return $this->repo; } }