123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- <?php
- namespace App\Service;
- use App\Error;
- use App\Log;
- use App\Models\IntelligentMassSending\IntelligentMassSendingAccount;
- use App\Models\MassMsgLinkRecord;
- use App\Models\PlatformApp;
- use App\Models\PlatformEpisode;
- use App\Models\PlatformPlaylet;
- use App\Models\PlatformPlayletGroup;
- use App\Models\PlatformPlayletGroupDetail;
- use App\Models\PromoteLink;
- use App\Models\Report\PlayletDataTrend;
- use App\RedisModel;
- use App\Support\EmailQueue;
- class PlatformService
- {
- /*
- * 获取短剧列表
- * */
- public static function playletList($platformId, $sysGroupId, $keyword, $accountId, $page, $pageSize)
- {
- # 查询对应账号的渠道商id
- $accountData = IntelligentMassSendingAccount::getChannelIds($platformId, $sysGroupId, $accountId);
- if(empty($accountData)) return [[], 0];
- $accountList = $accountData->pluck('service_provider_id');
- list($list, $count) = PlatformPlaylet::getPlayletList($platformId, $keyword, $accountList, $page, $pageSize);
- # 平台数据获取
- $platformList = config('platform.platform');
- foreach($list as $item) {
- # 平台名称
- $item->platform_name = $platformList[$item->platform_id]['platform_name'] ?? '未知';
- # 账号名称
- $accountInfo = $accountData->where('service_provider_id', $item->partner_id)->first();
- $item->account = $accountInfo->account ?? '-';
- unset($item->partner_id);
- }
-
- return [$list, $count];
- }
- /*
- * 创建推广链接
- * */
- public static function createLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- try {
- # 检验小程序app_id
- if($platformId != 4 && empty($params['mini_app_id'])){
- $errno = 4105;
- return [];
- }
- switch($platformId) {
- case 4: // 嘉书H5(东方小剧场)
- list($pagePath, $pid) = self::createJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId,$errno);
- break;
- case 3: // 迈步
- list($pagePath, $pid) = self::createMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, $errno);
- break;
- default:
- $errno = 4910;
- break;
- }
- } catch (\Exception $e) {
- EmailQueue::rPush('生成推广链接过程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com',
- 'song.shen@kuxuan-inc.com'], '生成推广链接过程发生异常');
- Log::logError('迈步推广链接存储失败', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'params' => $params,
- 'platformId' => $platformId,
- 'accountId' => $accountId,
- 'sys_group_id' => $sysGroupId,
- 'admin_id' => $adminId
- ], 'CreateLink');
- $errno = 4914;
- }
- if($errno || !$pagePath) return [];
- # 查询剧封面和标题
- $playletInfo = PlatformPlaylet::query()->select('name', 'description', 'cover_url')
- ->where('platform_id', $platformId)->where('playlet_id', $params['playlet_id'])
- ->where('enable', 1)->where('state', 1)
- ->first();
- $desc = empty($playletInfo->description) ? (empty($playletInfo->name) ? null : $playletInfo->name) : $playletInfo->description;
- $name = $playletInfo->name ?? null;
- $coverUrl = $playletInfo->cover_url ?? '';
- return ['path' => $pagePath, 'desc' => $desc, 'cover' => $coverUrl, 'pid' => $pid, 'playlet_name' => $name];
- }
- public static function createJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- # 查询渠道商id
- $channelInfo = IntelligentMassSendingAccount::query()->where('id', $accountId)
- ->where('platform_id', $platformId)->where('status', 1)
- ->where('active_status', 1)->where('enable', 1)->first();
- if(empty($channelInfo)) {
- $errno = 4912;
- return [null, null];
- }
- $customerId = $channelInfo->service_provider_id;
- $apiKey = $channelInfo->api_key;
- # 查询第三方平台app_id
- $platformAppId = PlatformApp::getAppExit($platformId, $customerId, $params['app_id']);
- if(empty($platformAppId)) {
- $errno = 4915;
- return [null, null];
- }
- # 查询剧集
- $sectionCount = PlatformPlaylet::query()
- ->where('platform_id', $platformId)
- ->where('playlet_id', $params['playlet_id'])
- ->where('enable', 1)
- ->value('section_count');
- if(empty($sectionCount) || $params['episode_num'] > $sectionCount) {
- $errno = 4911;
- return [null, null];
- }
- # 生成推广链接
- $promotionData = JiaShuService::savePromotion(
- $apiKey, $customerId, $params['app_id'], $params['playlet_id'], $params['episode_num'], $params['name']
- );
- $code = $promotionData['code'] ?? 1;
- if(1008 == $code) {
- $errno = 4916;// 该剧素材库不完整,暂时不能创建
- return [null, null];
- } else if($code) {
- $msg = $promotionData['message'] ?? '未标识的错误';
- EmailQueue::rPush('生成嘉书H5推广链接失败', $msg, ['song.shen@kuxuan-inc.com'], '生成推广链接失败');
- $errno = 4913;
- return [false, null];
- }
- $pid = $promotionData['data']['article'] ?? null;
- $linkInfo = $promotionData['data'] ?? null;
- if(empty($pid) || empty($linkInfo)) {
- $errno = 4913;
- return [null, null];
- }
- # 检出链接信息
- $insertData = [
- 'platform_id' => $platformId,
- 'account' => $accountId,
- 'sys_group_id' => $sysGroupId,
- 'app_id' => $params['app_id'],
- 'playlet_id' => $params['playlet_id'],
- 'episode_id' => $params['episode_num'],
- 'admin_id' => $adminId,
- 'corpid' => $params['corpid'],
- 'mini_app_id' => $params['mini_app_id'] ?? null,
- 'name' => $params['name'],
- 'force_subscribe' => $params['force_subscribe'],
- 'force_subscribe_sectionId' => $params['force_subscribe_sectionId'],
- 'type' => $params['type'],
- 'h5' => $linkInfo['mini_url'],
- 'pid' => $pid
- ];
- $result = PromoteLink::query()->insert($insertData);
- if(!$result) {
- Log::logError('嘉书H5推广链接存储失败', ['data' => $insertData], 'CreateLink');
- }
- $pagePath = $insertData['h5'] ?? null;
- return [$pagePath, $pid];
- }
- public static function createMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- # 查询渠道商id
- $channelId = IntelligentMassSendingAccount::query()->where('id', $accountId)
- ->where('platform_id', $platformId)->where('status', 1)
- ->where('active_status', 1)->where('enable', 1)
- ->value('service_provider_id');
- if(empty($channelId)) {
- $errno = 4912;
- return [null, null];
- }
- # 查询第三方平台app_id
- $platformAppId = PlatformApp::getPlatformAppId($platformId, $channelId, $params['app_id'], $params['mini_app_id']);
- if(empty($platformAppId)) {
- $errno = 4915;
- return [null, null];
- }
- # 查询剧集id
- $episodeId = PlatformEpisode::query()->where('platform_id', $platformId)
- ->where('playlet_id', $params['playlet_id'])
- ->where('name', '第'.$params['episode_num'].'集')->where('enable', 1)
- ->value('episode_id');
- if(empty($episodeId)) {
- $errno = 4911;
- return [null, null];
- }
- # 生成推广链接
- $responseData = MaiBuService::savePromotion(
- $channelId, $platformAppId, $params['name'], $params['playlet_id'], $episodeId
- );
- $code = $responseData['code'] ?? 1;
- if($code) {
- $msg = $responseData['msg'] ?? '未标识的错误';
- EmailQueue::rPush('生成推广链接失败', $msg, ['xiaohua.hou@kuxuan-inc.com'], '生成推广链接失败');
- return false;
- }
- $linkInfo = $responseData['data'] ?? [];
- $pid = $linkInfo['id'] ?? null;
- if(empty($linkInfo) || !$pid) {
- $errno = 4913;
- return [null, null];
- }
- # 检出链接信息
- $insertData = [
- 'platform_id' => $platformId,
- 'account' => $accountId,
- 'sys_group_id' => $sysGroupId,
- 'app_id' => $params['app_id'],
- 'playlet_id' => $params['playlet_id'],
- 'episode_id' => $episodeId,
- 'admin_id' => $adminId,
- 'corpid' => $params['corpid'],
- 'mini_app_id' => $params['mini_app_id'],
- 'name' => $params['name'],
- 'force_subscribe' => $params['force_subscribe'],
- 'force_subscribe_sectionId' => $params['force_subscribe_sectionId'],
- 'type' => $params['type'],
- 'page_path' => $linkInfo['pagePath'],
- 'quick_h5' => $linkInfo['quickH5'],
- 'h5' => $linkInfo['h5'],
- 'hap' => $linkInfo['hap'],
- 'https_hap' => $linkInfo['httpsHap'],
- 'content_share_image' => $linkInfo['contentShareImage'],
- 'media_id' => $linkInfo['mediaId'],
- 'wx_share_description' => $linkInfo['wxShareDescription'],
- 'pid' => $pid
- ];
- $result = PromoteLink::query()->insert($insertData);
- if(!$result) {
- Log::logError('迈步推广链接存储失败', ['data' => $insertData], 'CreateLink');
- }
- if(0 == $params['link_type']) {
- $pagePath = $insertData['page_path'] ?? null;
- } else {
- $pagePath = $insertData['h5'] ?? null;
- }
- return [$pagePath, $pid];
- }
- public static function setPlayletGroup($sysGroupId, $corpid, $adminId, $groupId, $name, $playletList, &$errno)
- {
- if(empty($playletList)) {
- $errno = 4101; // 短剧信息不能为空
- return false;
- }
- if(!is_array($playletList)){
- $playletList = json_decode($playletList, 1);
- }
- try{
- \DB::begintransaction();
- // 更新短剧组
- if($groupId) {
- $res1 = PlatformPlayletGroup::query()->where('id', $groupId)->update([
- 'name' => $name,
- 'corpid' => $corpid,
- 'sys_group_id' => $sysGroupId,
- 'admin_id' => $adminId,
- ]);
- // 将现有短剧组enable更新为0
- $res2 = PlatformPlayletGroupDetail::query()->where('group_id', $groupId)
- ->where('enable', 1)->update(['enable' => 0]);
- RedisModel::lPush(MassMsgLinkRecord::WELCOME_MSG_PLAYLET_GROUP_UPDATE_RDS, $groupId);
- } else {
- $res1 = $groupId = PlatformPlayletGroup::query()->insertGetId([
- 'name' => $name,
- 'corpid' => $corpid,
- 'sys_group_id' => $sysGroupId,
- 'admin_id' => $adminId,
- ]);
- if(!$res1) {
- \DB::rollBack();
- $errno = 4103;
- Log::logError('设置剧集组接口异常状态码',[
- 'sys_group_id' => $sysGroupId,
- 'corpid' => $corpid,
- 'admin_id' => $adminId,
- 'group_id' => $groupId,
- 'name' => $name,
- 'playlet_list' => $playletList,
- 'errno' => $errno,
- ], 'interface');
- return false;
- }
- }
- // 循环处理剧集详情信息
- foreach($playletList as $key => &$playletInfo) {
- $dataId = $playletInfo['data_id'] ?? 0;
- $item['sort_order'] = $key + 1;// 补完排序值
- $item['group_id'] = $groupId;// 短剧组ID
- $item['enable'] = 1;// 有效性
- $item['corpid'] = $corpid;
- $item['force_subscribe'] = 0;
- $item['force_subscribe_sectionId'] = 0;
- $item['type'] = 0;
- $item['name'] = $playletInfo['name'];
- $item['episode_num'] = $playletInfo['episode_num'];
- $item['app_id'] = $playletInfo['app_id'];
- $item['mini_app_id'] = $playletInfo['mini_app_id'] ?? null;
- $item['account_id'] = $playletInfo['account_id'];
- $item['link_type'] = $playletInfo['link_type'];
- $item['platform_id'] = $playletInfo['platform_id'];
- $item['playlet_id'] = $playletInfo['playlet_id'];
- $item['playlet_unique_id'] = $playletInfo['playlet_unique_id'];
- // 处理好的短剧信息入库
- if(empty($dataId)) {
- $detailRes = PlatformPlayletGroupDetail::query()->insert($item);
- } else {
- $detailRes = PlatformPlayletGroupDetail::query()->where('id', $dataId)->update($item);
- }
- if(!$detailRes) {
- \DB::rollBack();
- $errno = 4102;
- Log::logError('设置剧集组接口异常状态码',[
- 'sys_group_id' => $sysGroupId,
- 'corpid' => $corpid,
- 'admin_id' => $adminId,
- 'group_id' => $groupId,
- 'name' => $name,
- 'playlet_list' => $playletList,
- 'errno' => $errno,
- ], 'interface');
- return false;
- }
- }
- \DB::commit();
- return true;
- } catch (\Exception $exception) {
- Log::logError('设置剧集组接口异常',[
- 'params' => [
- 'sys_group_id' => $sysGroupId,
- 'corpid' => $corpid,
- 'admin_id' => $adminId,
- 'group_id' => $groupId,
- 'name' => $name,
- 'playlet_list' => $playletList,
- ],
- 'exception' => [
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]
- ], 'interface');
- $errno = 500;
- return false;
- }
- }
- public static function playletGroupList($sysGroupId, $page, $pageSize)
- {
- $groupQuery = PlatformPlayletGroup::query()->where('sys_group_id', $sysGroupId)
- ->where('enable', 1);
- $total = $groupQuery->count();
- $offset = ($page - 1) * $pageSize;
- $list = $groupQuery->selectRaw('id as group_id, name')->offset($offset)->limit($pageSize)
- ->get();
- // 提取短剧组ID
- $groupIdList = array_column($list->toArray(), 'group_id');
- // 查询对应的短剧列表
- $groupDetailList = PlatformPlayletGroupDetail::query()->whereIn('group_id', $groupIdList)
- ->where('enable', 1)->orderBy('sort_order', 'asc')->get();
- # 查询剧封面和标题
- $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'playlet_id',
- 'platform_id')->where('enable', 1)->where('state', 1)
- ->get();
- foreach($list as &$item) {
- $groupDetail = $groupDetailList->where('group_id', $item->group_id)->all();
- $playletArr = [];
- foreach($groupDetail as $value) {
- $playletInfo = $playletInfoList->where('platform_id', $value->platform_id)
- ->where('playlet_id', $value->playlet_id)->first();
- if(!empty($playletInfo)){
- $playletArr[] = $playletInfo;
- }
- }
- $item->playlet_list = $playletArr;
- }
- return [$list, $total];
- }
- public static function addPlayletToGroup($params, &$errno)
- {
- // 判断该剧是否已经加入短剧组
- $row = PlatformPlayletGroupDetail::query()->where('platform_id', $params['platform_id'])
- ->where('enable', 1)->where('group_id', $params['group_id'])
- ->where('playlet_id', $params['playlet_id'])->first();
- if($row) {
- $res = PlatformPlayletGroupDetail::query()->where('id', $row->id)->update($params);
- } else {
- $res = PlatformPlayletGroupDetail::query()->insert($params);
- }
- if(!$res){
- $errno = 400;
- return false;
- }
- return true;
- }
- public static function playletGroupDetail($groupId)
- {
- $groupInfo = PlatformPlayletGroup::query()->selectRaw('id as group_id, name')
- ->where('id', $groupId)->first();
- if(empty($groupInfo)){
- return [[], 4104];
- }
- // 查询对应的短剧列表
- $groupDetailList = PlatformPlayletGroupDetail::query()->where('group_id', $groupId)
- ->where('enable', 1)->selectRaw('id as data_id, corpid, platform_id, '.
- 'account_id, app_id, mini_app_id, name, playlet_id, episode_num, link_type, playlet_unique_id')
- ->orderBy('sort_order', 'asc')->get();
- $groupDetailList = $groupDetailList->isNotEmpty() ? $groupDetailList->toArray() : [];
- # 查询剧封面和标题
- $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'playlet_id',
- 'platform_id')->where('enable', 1)->where('state', 1)
- ->get();
- foreach($groupDetailList as $key => $value) {
- $playletInfo = $playletInfoList->where('platform_id', $value['platform_id'])
- ->where('playlet_id', $value['playlet_id'])->first();
- if(empty($playletInfo)) {
- unset($groupDetailList[$key]);
- continue;
- }
- $groupDetailList[$key]['playlet_name'] = $playletInfo->name ?? '';
- $groupDetailList[$key]['playlet_description'] = $playletInfo->description ?? '';
- $groupDetailList[$key]['playlet_cover'] = $playletInfo->cover_url;
- }
- $groupInfo->playlet_list = $groupDetailList;
- return [$groupInfo, 0];
- }
- public static function playletGroupH5Detail($groupId, $sender, $ruleId, $msgType)
- {
- $list = MassMsgLinkRecord::query()->where('playlet_group_id', $groupId)->where('enable', 1)
- ->where('sender', $sender)->where('rule_id', $ruleId)->where('msg_type', $msgType)
- ->select(['playlet_id', 'platform_id', 'link_type', 'link', 'desc'])->orderBy('sort', 'asc')
- ->get();
- $list = $list->isNotEmpty() ? $list->toArray() : [];
- # 查询剧封面和标题
- $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'platform_id',
- 'playlet_id')->where('enable', 1)->where('state', 1)
- ->get();
- foreach($list as $key=>$value){
- $playletInfo = $playletInfoList->where('platform_id', $value['platform_id'])
- ->where('playlet_id', $value['playlet_id'])->first();
- if(empty($playletInfo)) {
- unset($list[$key]);
- continue;
- }
- $list[$key]['playlet_name'] = $playletInfo->name ?? '';
- $list[$key]['playlet_description'] = $playletInfo->description ?? '';
- $list[$key]['playlet_cover'] = $playletInfo->cover_url ?? '';
- }
- return $list;
- }
- /*
- * 创建推广链接
- * */
- public static function paramsValidate($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- try {
- # 检验小程序app_id
- if($platformId != 4 && empty($params['mini_app_id'])){
- $errno = 4105;
- return ['小程序app_id必填'];
- }
- if($platformId == 4 && 0 == $params['link_type']){
- $errno = 4106;
- return ['嘉书平台只能够创建H5类型的推广链接'];
- }
- switch($platformId) {
- case 4: // 嘉书H5(东方小剧场)
- $pagePath = self::validateJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId,$errno);
- break;
- case 3: // 迈步
- $pagePath = self::validateMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, $errno);
- break;
- default:
- $errno = 4910;
- break;
- }
- } catch (\Exception $e) {
- EmailQueue::rPush('生成推广链接过程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com',
- 'song.shen@kuxuan-inc.com'], '生成推广链接过程发生异常');
- Log::logError('迈步推广链接存储失败', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'params' => $params,
- 'platformId' => $platformId,
- 'accountId' => $accountId,
- 'sys_group_id' => $sysGroupId,
- 'admin_id' => $adminId
- ], 'CreateLink');
- $errno = 4914;
- }
- if($errno || !$pagePath) return [];
- return [];
- }
- public static function validateJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- # 查询渠道商id
- $channelInfo = IntelligentMassSendingAccount::query()->where('id', $accountId)
- ->where('platform_id', $platformId)->where('status', 1)
- ->where('active_status', 1)->where('enable', 1)->first();
- if(empty($channelInfo)) {
- $errno = 4912;
- return [];
- }
- $customerId = $channelInfo->service_provider_id;
- $apiKey = $channelInfo->api_key;
- # 查询第三方平台app_id
- $platformAppId = PlatformApp::getAppExit($platformId, $customerId, $params['app_id']);
- if(empty($platformAppId)) {
- $errno = 4915;
- return [];
- }
- # 查询剧集
- $sectionCount = PlatformPlaylet::query()
- ->where('platform_id', $platformId)
- ->where('playlet_id', $params['playlet_id'])
- ->where('enable', 1)
- ->value('section_count');
- if(empty($sectionCount) || $params['episode_num'] > $sectionCount) {
- $errno = 4911;
- return [];
- }
- return true;
- }
- public static function validateMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
- {
- # 查询渠道商id
- $channelId = IntelligentMassSendingAccount::query()->where('id', $accountId)
- ->where('platform_id', $platformId)->where('status', 1)
- ->where('active_status', 1)->where('enable', 1)
- ->value('service_provider_id');
- if(empty($channelId)) {
- $errno = 4912;
- return [];
- }
- # 查询第三方平台app_id
- $platformAppId = PlatformApp::getPlatformAppId($platformId, $channelId, $params['app_id'], $params['mini_app_id']);
- if(empty($platformAppId)) {
- $errno = 4915;
- return [];
- }
- # 查询剧集id
- $episodeId = PlatformEpisode::query()->where('platform_id', $platformId)
- ->where('playlet_id', $params['playlet_id'])
- ->where('name', '第'.$params['episode_num'].'集')->where('enable', 1)
- ->value('episode_id');
- if(empty($episodeId)) {
- $errno = 4911;
- return [];
- }
- return true;
- }
- public static function batchCreateLink($sysGroupId, $corpid, $adminId, $playletList)
- {
- if(empty($playletList)) {
- return ['短剧信息不能为空', 4101];
- }
- if(!is_array($playletList)){
- $playletList = json_decode($playletList, 1);
- }
- if(count($playletList) > 9) {
- return ['一次最多只能创建9条推广链接', 4107];
- }
- $linkData = [];
- try {
- // 循环处理剧集详情信息
- foreach($playletList as $key => $playletInfo) {
- # 判断必要参数
- if(
- !isset($playletInfo['platform_id']) ||
- !isset($playletInfo['account_id']) ||
- !isset($playletInfo['app_id']) ||
- !isset($playletInfo['name']) ||
- !isset($playletInfo['playlet_id']) ||
- !isset($playletInfo['episode_num']) ||
- !isset($playletInfo['link_type'])) {
- $errno = 1103;
- $linkData[] = [
- 'link_data' => $playletInfo,
- 'err_no' => $errno,
- 'err_msg' => Error::getError($errno)
- ];
- continue;
- }
- if($playletInfo['platform_id'] == 4 && 0 == $playletInfo['link_type']){
- $errno = 4106;
- $linkData[] = [
- 'link_data' => $playletInfo,
- 'err_no' => $errno,
- 'err_msg' => Error::getError($errno)
- ];
- continue;
- }
- if(!isset($playletInfo['page']) || empty($playletInfo['page'])) {
- $playletInfo['corpid'] = $corpid;
- $playletInfo['force_subscribe'] = 0;
- $playletInfo['force_subscribe_sectionId'] = 0;
- $playletInfo['type'] = 0;
- $errno = 0;
- $linkInfo = PlatformService::createLink(
- $playletInfo, $playletInfo['platform_id'], $playletInfo['account_id'], $sysGroupId,
- $adminId, $errno
- );
- if(empty($linkInfo) || $errno > 0) {
- $linkData[] = [
- 'link_data' => $playletInfo,
- 'err_no' => $errno,
- 'err_msg' => Error::getError($errno)
- ];
- } else {
- $linkInfo = array_merge($linkInfo, $playletInfo);
- $linkData[] = [
- 'link_data' => $linkInfo,
- 'err_no' => 0,
- 'err_msg' => ''
- ];
- }
- if(in_array($linkInfo, [4])) {// 嘉书平台限制1秒钟请求一次接口
- sleep(1);
- }
- } else {
- $linkData[] = [
- 'link_data' => $playletInfo,
- 'err_no' => 0,
- 'err_msg' => ''
- ];
- }
- }
- return [$linkData, 0];
- } catch (\Exception $e) {
- EmailQueue::rPush('批量创建推广链接过程发生异常', $e->getTraceAsString(), [
- 'song.shen@kuxuan-inc.com'], '批量创建推广链接过程发生异常');
- Log::logError('批量创建推广链接过程发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'playlet_list' => $playletList,
- 'corpid' => $corpid,
- 'sys_group_id' => $sysGroupId,
- 'admin_id' => $adminId
- ], 'CreateLink');
- $errno = 4914;
- return [$linkData, $errno];
- }
- }
- }
|