"error", "msg"=>"日期格式不正确"], 256); } }else{ $sDate = date('Y-m-d'); $eDate = date('Y-m-d'); } // 重跑用,传数组 if(!empty($params['advertiser_ids'])){ $this->advertiserIds = $params['advertiser_ids']; } // 重跑用,传int if(!empty($params['api_id'])){ $this->apiId = $params['api_id']; } $this->siteMap = (new AgentSiteLogic())->getSiteAuth(); $this->adminUserMap = (new SystemUser())->where("nickname","<>", "")->column("nickname", "id"); for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 day'))){ $this->date = $date; try { $this->initStart(); }catch (\Exception $e){ return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256); } } $this->reRun(); return json_encode(["status"=>"success", "msg"=>""], 256); } // 重跑 protected function reRun(): void { if (date('H') == 8 && date('i') < 20) { $this->date = date('Y-m-d', strtotime("-1 days")); $this->initStart(); } } abstract protected function initStart(); // Todo 从广告名称中拆分归因数据 protected function getSiteInfo($adName): array { $match = []; preg_match("/([\d]*)_([\d]*)_([\d]*)/", $adName, $match); $siteInfo = [ "game_id" => $match[1] ?? 0, "agent_id" => $match[2] ?? 0, "site_id" => $match[3] ?? 0, ]; unset($match); return $siteInfo; } // Todo 从素材名称中获取归属人 protected function getAuthorId($materialName): int|string { $auth_id = 0; foreach ($this->adminUserMap as $id => $name) { $name = mb_substr($name, -2); // 用姓名后两个字匹配,因为有的人素材填写喜欢不带姓 if ($name && strstr($materialName, $name)) { $auth_id = $id; break; } } return $auth_id; } // 获取需要拉取消耗的媒体账户 protected function getTtAccountList(): array { $table = "ad_jrtt_account_list"; $where = [ "status" => 1 ]; if($this->advertiserIds){ $where['advertiser_id'] = $this->advertiserIds; } return Db::connect('db_advert') ->table($table) ->where($where) ->column("pmid, advertiser_id, advertiser_name, son_fandian"); } protected function getTtTokenMap(): array { $table = "ad_jrtt_account"; $where = [ "status" => 1 ]; if($this->apiId){ $where['id'] = $this->apiId; } return Db::connect('db_advert')->table($table)->where($where)->column("access_token", "id"); } // 获取需要拉取消耗的媒体账户 protected function getGdtAccountList(): array { $table = "ad_gdt_account_list"; $where = [ "status" => 1 ]; if($this->advertiserIds){ $where['advertiser_id'] = $this->advertiserIds; } return Db::connect('db_advert') ->table($table) ->where($where) ->column("pmid, advertiser_id, advertiser_name, son_fandian"); } protected function getGdtTokenMap(): array { $table = "ad_gdt_account"; $where = [ "status" => 1 ]; if($this->apiId){ $where['id'] = $this->apiId; } return Db::connect('db_advert')->table($table)->where($where)->column("access_token", "id"); } }