$data['id']], $data); } else { return LandingPageLink::create($data); } } public function deleteLink(int $id) { LandingPageLink::where('id', $id)->delete(); } public function updateLinkStatus(int $id, int $status, string $remark) { if ($status) { $this->saveLink(['id' => $id, 'status' => $status, 'remark' => $remark]); LandingPageLinkLog::create(['link_id' => $id, 'status' => $status, 'remark' => $remark]); } } public function findLinks(array $query_params = [], bool $is_page = false) { $sql = LandingPageLink::orderBy('id', 'desc'); if (isset($query_params['name']) && $query_params['name']) { $sql->where('name', 'like', $query_params['name'] . '%'); } if (isset($query_params['gzh_name']) && $query_params['gzh_name']) { $sql->where('gzh_name', 'like', $query_params['gzh_name'] . '%'); } if (isset($query_params['gzh_code']) && $query_params['gzh_code']) { $sql->where('gzh_code', $query_params['gzh_code']); } if (isset($query_params['status']) && $query_params['status']) { $sql->where('status', $query_params['status']); } if (isset($query_params['channel_id']) && $query_params['channel_id']) { $sql->where('channel_id', $query_params['channel_id']); } if ($is_page) { return $sql->paginate(20); } else { return $sql->get(); } } public function findDomains() { return LandingPageDomain::where('is_enabled', 1)->get(); } public function findOfficialAccounts(int $distribution_channel_id) { return OfficialAccount::select('nickname', 'appid', 'alias', 'head_img') ->where('distribution_channel_id', $distribution_channel_id) ->where('is_auth', 1) ->where('is_enabled', 1) ->get(); } /** * 获取付费回传配置信息 */ public function getChargeFeedBackConfig(int $channel_id, int $channel_user_id) { $switch_status = (new NormalChargeFeedBack)->getSwitchStatus($channel_id); $orange_switch_status = (new OrangeChargeFeedBack)->getSwitchStatus($channel_id); $type = Redis::hGet('channel:setting:' . $channel_id, 'tiktok_report_type') ?? self::CURRENT_DAY_REGISTER; $service = new ConfigService; $source = BaseConst::Platform; $result = [ 'orange_switch_status' => $orange_switch_status, 'switch_status' => $switch_status, 'type' => $type, 'weibo_monitor_link' => "https://newtrack.zhuishuyun.com/?dycallback=3&channel_id={$channel_id}&source={$source}&ip={ip}&ua={ua}&clicktime={clicktime}&IMP={IMP}&ad_id={ad_id}&creative_id={creative_id}", 'kuaishou_monitor_link' => "https://newtrack.zhuishuyun.com/?dycallback=6&channel_id={$channel_id}&source={$source}&aid=__AID__&dname=__DNAME__&cid=__CID__&imei=__IMEI__&androidid=__ANDROIDID2__&oaid=__OAID__&mac=__MAC__&ip=__IP__&ua=__UA__&ts=__TS__&callback=__CALLBACK__&imei=__IMEI2__&os=__OS__&did=__DID__&accountid=__ACCOUNTID__&csite=__CSITE__" ]; $is_open = $service->hasAuth($channel_user_id, 'platform_charge_percent_report'); if ($is_open) { $percent = Redis::hGet('channel:setting:' . $channel_id, 'tiktok_report_percent'); if ($percent) { $percent = json_decode($percent, true); $molecule = round($percent['molecule'] / $percent['denominator'] * 100); } else { $molecule = (int) Redis::hGet('channel:setting:' . $channel_id, 'new_tiktok_report_percent'); } $eligible_count = Redis::hGet('channel:setting:' . $channel_id, 'tiktok_report_eligible_count'); return array_merge([ 'molecule' => $molecule, 'eligible_count' => $eligible_count, ], $result); } return $result; } private function getService(bool $is_orange) { return $is_orange ? new OrangeChargeFeedBack : new NormalChargeFeedBack; } public function setSwitchStatus(int $channel_id, int $status, bool $is_orange = false) { $this->getService($is_orange)->setSwitchStatus($channel_id, $status); } public function syncSwitchStatus(array $channel_ids, int $status, bool $is_orange = false) { $this->getService($is_orange)->syncSwitchStatus($channel_ids, $status); } public function findUserReportInfos(int $channel_id, array $params, bool $is_page = true) { $sql = Order::where('orders.distribution_channel_id', $channel_id) ->where('orders.status', 'PAID') ->select('orders.*') ->orderBy('orders.id', 'desc'); //限制用户的创建时间 if (isset($params['user_begin_time']) || isset($params['user_end_time'])) { $sql->join('users','users.id','orders.uid'); if (isset($params['user_begin_time']) && $params['user_begin_time']) { $date = substr($params['user_begin_time'],0,10); $sql->where('users.created_at', '>=', $date. ' 00:00:00'); } if (isset($params['user_end_time']) && $params['user_end_time']) { $date = substr($params['user_end_time'],0,10); $sql->where('users.created_at', '<=', $date. ' 23:59:59'); } } if (isset($params['begin_time']) && $params['begin_time']) { $date = substr($params['begin_time'],0,10); $sql->where('orders.created_at', '>=', $date. ' 00:00:00'); } if (isset($params['end_time']) && $params['begin_time']) { $date = substr($params['end_time'],0,10); $sql->where('orders.created_at', '<=', $date. ' 23:59:59'); } if (isset($params['uid']) && $params['uid']) { $sql->where('orders.uid', $params['uid']); } //限制派单ID if (isset($params['send_order_id']) && $params['send_order_id']) { $sql->where('orders.send_order_id', $params['send_order_id']); } if (isset($params['adid']) && $params['adid']) { $sql->whereExists(function ($query) use ($params) { $query->select(DB::raw(1)) ->from('report_user_bind_records') ->whereRaw('report_user_bind_records.uid = orders.uid') ->where('report_user_bind_records.adid', $params['adid']); }); } if (isset($params['link_source']) && $params['link_source']) { $sql->whereExists(function ($query) use ($params) { $query->select(DB::raw(1)) ->from('report_user_charge_records') ->whereRaw('report_user_charge_records.order_no = orders.trade_no') ->where('report_user_charge_records.link_source', $params['link_source']); }); } $qapp_account = isset($params['qapp_account']) && !empty($params['qapp_account']) ? $params['qapp_account']:''; \Log::info('findUserReportInfos:channel_id:'.$channel_id.' qapp_account:'.$qapp_account.' params:'.json_encode($params)); // 注意:快应用的子账号必须要限制下权限 if (!empty($qapp_account)) { $user = DB::table('qapp_channel_accounts')->where('account',$params['qapp_account'])->select(['is_owner_role','company_id','distribution_channel_id'])->first(); $is_owner_role = $user->is_owner_role; if (!empty($params['nickname']) && $is_owner_role ) { //根据名称搜索 $sql->join('qapp_send_orders', 'orders.send_order_id', 'qapp_send_orders.send_order_id') ->where('qapp_send_orders.account', $params['nickname']); }else{ // 主账号 if ($is_owner_role) { $qapp_account_arr = DB::table('qapp_channel_accounts')->where('company_id',$user->company_id) ->where('distribution_channel_id',$user->distribution_channel_id) ->pluck('account')->all(); }else{ $qapp_account_arr = [$params['qapp_account']]; } $sql->join('qapp_send_orders', 'orders.send_order_id', 'qapp_send_orders.send_order_id') ->whereIn('qapp_send_orders.account', $qapp_account_arr); } // 限制 回传方式--》 根据回传方式找派单 if(isset($params['report_type']) && $params['report_type']){ $sql->where('report_type',$params['report_type']); } } if ($is_page) { return $sql->paginate(); } else { return $sql->get(); } } public function setReportType(int $channel_id, string $type, int $molecule, int $eligible_count) { if (in_array($type, LandingPageLinkService::REPORT_TYPE)) { $molecule = $molecule == 0 ? 100 : $molecule; Redis::hset('channel:setting:' . $channel_id, 'tiktok_report_type', $type); Redis::hDel('channel:setting:' . $channel_id, 'tiktok_report_percent'); Redis::hset('channel:setting:' . $channel_id, 'new_tiktok_report_percent', $molecule); Redis::hset('channel:setting:' . $channel_id, 'tiktok_report_eligible_count', $eligible_count); $service = new Report; $service->report('api/report/config', [ 'source' => BaseConst::Platform, 'channel_id' => $channel_id, 'type' => $type, 'molecule' => $molecule, 'denominator' => 100, 'eligible_count' => $eligible_count, ]); } } public function addBaiduAdAccount(array $data, int $channel_user_id) { $model = BaiDuAdAccount::create( [ 'account_name' => $data['account_name'], 'token' => $data['token'], 'channel_user_id' => $channel_user_id, 'is_enabled' => 1, ] ); $this->baiDuAdAccountReport($model); } public function delBaiduAdAccount(int $id, int $channel_user_id) { $model = BaiDuAdAccount::where('id', $id)->where('channel_user_id', $channel_user_id)->first(); if ($model) { $model->is_enabled = 0; $model->save(); $this->baiDuAdAccountReport($model); } } private function baiDuAdAccountReport(BaiDuAdAccount $model) { $service = new Report; $service->report('api/report/baidu/token', [ 'source' => BaseConst::Platform, 'adid' => $model->id, 'token' => $model->token, 'is_enabled' => $model->is_enabled, ]); } public function findBaiduAdAccounts(int $channel_user_id): Collection { return BaiDuAdAccount::where('is_enabled', 1)->where('channel_user_id', $channel_user_id)->get(); } public function reReport(int $bind_id, float $amount, string $order_no, bool $is_qapp = false) { $service = $is_qapp ? new QappRereport : new Rereport; $service->reReport($bind_id, $amount, $order_no); } }