where('platform_id', $params['platform_id']) ->where('enable', 1) ->where('account', $params['account']) ->first(); if(!empty($row)) { return ['账号名称已存在', 5101]; } $res = IntelligentMassSendingAccount::query() ->insertGetId($params); $code = $res>0 ? 0 : 400; return [$res, $code]; } public static function accountIndex($page, $pageSize, $sysGroupId) { $offset = ($page - 1) * $pageSize; $query = IntelligentMassSendingAccount::query() ->where('sys_group_id', $sysGroupId) ->where('enable', 1); $countQuery = clone $query; $count = $countQuery->count(); $list = $query->selectRaw('id as account_id, account, description, status, active_status,' .' service_provider_id, platform_id') ->orderBy('id', 'desc') ->offset($offset) ->limit($pageSize) ->get(); # 提取服务商ID $serviceProviderIdList = $list->pluck('service_provider_id')->toArray(); # 根据服务商ID统一计算关联的剧集数 $playletStat = PlatformPlaylet::query() ->whereIn('partner_id', $serviceProviderIdList) ->where('enable', 1) ->where('state', 1) ->selectRaw('partner_id, count(1) as count') ->groupBy('partner_id') ->get(); $platformArr = array_values(config('platform.platform')); $platformArr = array_column($platformArr, 'platform_name', 'platform_id'); foreach($list as $value) { $playletInfo = $playletStat->where('partner_id', $value->service_provider_id)->first(); $value->playlet_num = $playletInfo->count ?? 0; unset($value->service_provider_id); $value->platform_name = $platformArr[$value->platform_id] ?? null; } return [$list, $count]; } public static function editAccount($accountId, $params) { # 判断账号是否已经使用 $row = IntelligentMassSendingAccount::query() ->where('platform_id', $params['platform_id']) ->where('enable', 1) ->where('account', $params['account']) ->where('id', '!=', $accountId) ->first(); if(!empty($row)) { return ['账号名称已存在', 5101]; } $res = IntelligentMassSendingAccount::query() ->where('id', $accountId) ->update($params); return [$res, 0]; } public static function accountList($platformId, $sysGroupId) { $list = IntelligentMassSendingAccount::query() ->selectRaw('id as account_id, account') ->where('enable', 1) ->where('status', 1) ->where('active_status', 1) ->where('sys_group_id', $sysGroupId) ->where(function($query) use ($platformId){ if(!empty($platformId)) $query->where('platform_id', $platformId); })->get(); return $list; } public static function addSmallApp($params) { # 判断账号是否已经使用 $row = IntelligentMassSendingSmallApp::query() ->where('sys_group_id', $params['sys_group_id']) ->where('enable', 1) ->where('app_id', $params['app_id']) ->first(); if(!empty($row)) { return ['小程序已存在', 5102]; } $res = IntelligentMassSendingSmallApp::query() ->insertGetId($params); $code = $res>0 ? 0 : 400; return [$res, $code]; } public static function editSmallApp($dataId, $params) { # 判断账号是否已经使用 $row = IntelligentMassSendingSmallApp::query() ->where('sys_group_id', $params['sys_group_id']) ->where('enable', 1) ->where('app_id', $params['app_id']) ->where('id', '!=', $dataId) ->first(); if(!empty($row)) { return ['小程序已存在', 5102]; } $res = IntelligentMassSendingSmallApp::query() ->where('id', $dataId) ->update($params); return [$res, 0]; } public static function smallAppIndex($appName, $page, $pageSize, $sysGroupId) { $offset = ($page -1) * $pageSize; $query = IntelligentMassSendingSmallApp::query() ->where('sys_group_id', $sysGroupId) ->where('enable', 1); if($appName) { $query->where('app_name', 'like', '%'.$appName.'%'); } $countQuery = clone $query; $count = $countQuery->count(); $list = $query->selectRaw('id as data_id, platform_id, app_id, app_name, status, create_time') ->orderByDesc('id') ->offset($offset) ->limit($pageSize) ->get(); return [$list, $count]; } public static function appList($corpid) { $list = TencentAdConf::query() ->where('corp_id', $corpid) ->where('enable', 1) ->select(['app_id']) ->get(); $appIdList = $list->isNotEmpty() ? $list->pluck('app_id')->toArray() : []; if(empty($appIdList)) { return []; } else { $list = OfficialAccount::query() ->whereIn('mp_app_id', $appIdList) ->where('enable', 1) ->select(['mp_app_id', 'mp_name']) ->get(); return $list; } } public static function smallAppList($sysGroupId, $platformId) { $list = IntelligentMassSendingSmallApp::query() ->where('enable', 1) ->where('sys_group_id', $sysGroupId) ->where(function($query) use ($platformId){ if(!empty($platformId)) $query->where('platform_id', $platformId); }) ->where('status', 1) ->selectRaw('app_id, app_name, platform_id') ->get(); # 添加平台信息 $platformInfoList = config('platform.platform'); foreach($list as $info) { $platformInfo = $platformInfoList[$info->platform_id] ?? 0; $info->platform_name = $platformInfo['platform_name'] ?? null; } return $list; } }