企微短剧业务系统

PlatformService.php 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. namespace App\Service;
  3. use App\Error;
  4. use App\Log;
  5. use App\Models\IntelligentMassSending\IntelligentMassSendingAccount;
  6. use App\Models\MassMsgLinkRecord;
  7. use App\Models\PlatformApp;
  8. use App\Models\PlatformEpisode;
  9. use App\Models\PlatformPlaylet;
  10. use App\Models\PlatformPlayletGroup;
  11. use App\Models\PlatformPlayletGroupDetail;
  12. use App\Models\PromoteLink;
  13. use App\Models\Report\PlayletDataTrend;
  14. use App\RedisModel;
  15. use App\Support\EmailQueue;
  16. class PlatformService
  17. {
  18. /*
  19. * 获取短剧列表
  20. * */
  21. public static function playletList($platformId, $sysGroupId, $keyword, $accountId, $page, $pageSize)
  22. {
  23. # 查询对应账号的渠道商id
  24. $accountData = IntelligentMassSendingAccount::getChannelIds($platformId, $sysGroupId, $accountId);
  25. if(empty($accountData)) return [[], 0];
  26. $accountList = $accountData->pluck('service_provider_id');
  27. list($list, $count) = PlatformPlaylet::getPlayletList($platformId, $keyword, $accountList, $page, $pageSize);
  28. # 平台数据获取
  29. $platformList = config('platform.platform');
  30. foreach($list as $item) {
  31. # 平台名称
  32. $item->platform_name = $platformList[$item->platform_id]['platform_name'] ?? '未知';
  33. # 账号名称
  34. $accountInfo = $accountData->where('service_provider_id', $item->partner_id)->first();
  35. $item->account = $accountInfo->account ?? '-';
  36. unset($item->partner_id);
  37. }
  38. return [$list, $count];
  39. }
  40. /*
  41. * 创建推广链接
  42. * */
  43. public static function createLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  44. {
  45. try {
  46. # 检验小程序app_id
  47. if($platformId != 4 && empty($params['mini_app_id'])){
  48. $errno = 4105;
  49. return [];
  50. }
  51. switch($platformId) {
  52. case 4: // 嘉书H5(东方小剧场)
  53. list($pagePath, $pid) = self::createJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId,$errno);
  54. break;
  55. case 3: // 迈步
  56. list($pagePath, $pid) = self::createMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, $errno);
  57. break;
  58. default:
  59. $errno = 4910;
  60. break;
  61. }
  62. } catch (\Exception $e) {
  63. EmailQueue::rPush('生成推广链接过程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com',
  64. 'song.shen@kuxuan-inc.com'], '生成推广链接过程发生异常');
  65. Log::logError('迈步推广链接存储失败', [
  66. 'line' => $e->getLine(),
  67. 'msg' => $e->getMessage(),
  68. 'params' => $params,
  69. 'platformId' => $platformId,
  70. 'accountId' => $accountId,
  71. 'sys_group_id' => $sysGroupId,
  72. 'admin_id' => $adminId
  73. ], 'CreateLink');
  74. $errno = 4914;
  75. }
  76. if($errno || !$pagePath) return [];
  77. # 查询剧封面和标题
  78. $playletInfo = PlatformPlaylet::query()->select('name', 'description', 'cover_url')
  79. ->where('platform_id', $platformId)->where('playlet_id', $params['playlet_id'])
  80. ->where('enable', 1)->where('state', 1)
  81. ->first();
  82. $desc = empty($playletInfo->description) ? (empty($playletInfo->name) ? null : $playletInfo->name) : $playletInfo->description;
  83. $name = $playletInfo->name ?? null;
  84. $coverUrl = $playletInfo->cover_url ?? '';
  85. return ['path' => $pagePath, 'desc' => $desc, 'cover' => $coverUrl, 'pid' => $pid, 'playlet_name' => $name];
  86. }
  87. public static function createJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  88. {
  89. # 查询渠道商id
  90. $channelInfo = IntelligentMassSendingAccount::query()->where('id', $accountId)
  91. ->where('platform_id', $platformId)->where('status', 1)
  92. ->where('active_status', 1)->where('enable', 1)->first();
  93. if(empty($channelInfo)) {
  94. $errno = 4912;
  95. return [null, null];
  96. }
  97. $customerId = $channelInfo->service_provider_id;
  98. $apiKey = $channelInfo->api_key;
  99. # 查询第三方平台app_id
  100. $platformAppId = PlatformApp::getAppExit($platformId, $customerId, $params['app_id']);
  101. if(empty($platformAppId)) {
  102. $errno = 4915;
  103. return [null, null];
  104. }
  105. # 查询剧集
  106. $sectionCount = PlatformPlaylet::query()
  107. ->where('platform_id', $platformId)
  108. ->where('playlet_id', $params['playlet_id'])
  109. ->where('enable', 1)
  110. ->value('section_count');
  111. if(empty($sectionCount) || $params['episode_num'] > $sectionCount) {
  112. $errno = 4911;
  113. return [null, null];
  114. }
  115. # 生成推广链接
  116. $promotionData = JiaShuService::savePromotion(
  117. $apiKey, $customerId, $params['app_id'], $params['playlet_id'], $params['episode_num'], $params['name']
  118. );
  119. $code = $promotionData['code'] ?? 1;
  120. if(1008 == $code) {
  121. $errno = 4916;// 该剧素材库不完整,暂时不能创建
  122. return [null, null];
  123. } else if($code) {
  124. $msg = $promotionData['message'] ?? '未标识的错误';
  125. EmailQueue::rPush('生成嘉书H5推广链接失败', $msg, ['song.shen@kuxuan-inc.com'], '生成推广链接失败');
  126. $errno = 4913;
  127. return [false, null];
  128. }
  129. $pid = $promotionData['data']['article'] ?? null;
  130. $linkInfo = $promotionData['data'] ?? null;
  131. if(empty($pid) || empty($linkInfo)) {
  132. $errno = 4913;
  133. return [null, null];
  134. }
  135. # 检出链接信息
  136. $insertData = [
  137. 'platform_id' => $platformId,
  138. 'account' => $accountId,
  139. 'sys_group_id' => $sysGroupId,
  140. 'app_id' => $params['app_id'],
  141. 'playlet_id' => $params['playlet_id'],
  142. 'episode_id' => $params['episode_num'],
  143. 'admin_id' => $adminId,
  144. 'corpid' => $params['corpid'],
  145. 'mini_app_id' => $params['mini_app_id'] ?? null,
  146. 'name' => $params['name'],
  147. 'force_subscribe' => $params['force_subscribe'],
  148. 'force_subscribe_sectionId' => $params['force_subscribe_sectionId'],
  149. 'type' => $params['type'],
  150. 'h5' => $linkInfo['mini_url'],
  151. 'pid' => $pid
  152. ];
  153. $result = PromoteLink::query()->insert($insertData);
  154. if(!$result) {
  155. Log::logError('嘉书H5推广链接存储失败', ['data' => $insertData], 'CreateLink');
  156. }
  157. $pagePath = $insertData['h5'] ?? null;
  158. return [$pagePath, $pid];
  159. }
  160. public static function createMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  161. {
  162. # 查询渠道商id
  163. $channelId = IntelligentMassSendingAccount::query()->where('id', $accountId)
  164. ->where('platform_id', $platformId)->where('status', 1)
  165. ->where('active_status', 1)->where('enable', 1)
  166. ->value('service_provider_id');
  167. if(empty($channelId)) {
  168. $errno = 4912;
  169. return [null, null];
  170. }
  171. # 查询第三方平台app_id
  172. $platformAppId = PlatformApp::getPlatformAppId($platformId, $channelId, $params['app_id'], $params['mini_app_id']);
  173. if(empty($platformAppId)) {
  174. $errno = 4915;
  175. return [null, null];
  176. }
  177. # 查询剧集id
  178. $episodeId = PlatformEpisode::query()->where('platform_id', $platformId)
  179. ->where('playlet_id', $params['playlet_id'])
  180. ->where('name', '第'.$params['episode_num'].'集')->where('enable', 1)
  181. ->value('episode_id');
  182. if(empty($episodeId)) {
  183. $errno = 4911;
  184. return [null, null];
  185. }
  186. # 生成推广链接
  187. $responseData = MaiBuService::savePromotion(
  188. $channelId, $platformAppId, $params['name'], $params['playlet_id'], $episodeId
  189. );
  190. $code = $responseData['code'] ?? 1;
  191. if($code) {
  192. $msg = $responseData['msg'] ?? '未标识的错误';
  193. EmailQueue::rPush('生成推广链接失败', $msg, ['xiaohua.hou@kuxuan-inc.com'], '生成推广链接失败');
  194. return false;
  195. }
  196. $linkInfo = $responseData['data'] ?? [];
  197. $pid = $linkInfo['id'] ?? null;
  198. if(empty($linkInfo) || !$pid) {
  199. $errno = 4913;
  200. return [null, null];
  201. }
  202. # 检出链接信息
  203. $insertData = [
  204. 'platform_id' => $platformId,
  205. 'account' => $accountId,
  206. 'sys_group_id' => $sysGroupId,
  207. 'app_id' => $params['app_id'],
  208. 'playlet_id' => $params['playlet_id'],
  209. 'episode_id' => $episodeId,
  210. 'admin_id' => $adminId,
  211. 'corpid' => $params['corpid'],
  212. 'mini_app_id' => $params['mini_app_id'],
  213. 'name' => $params['name'],
  214. 'force_subscribe' => $params['force_subscribe'],
  215. 'force_subscribe_sectionId' => $params['force_subscribe_sectionId'],
  216. 'type' => $params['type'],
  217. 'page_path' => $linkInfo['pagePath'],
  218. 'quick_h5' => $linkInfo['quickH5'],
  219. 'h5' => $linkInfo['h5'],
  220. 'hap' => $linkInfo['hap'],
  221. 'https_hap' => $linkInfo['httpsHap'],
  222. 'content_share_image' => $linkInfo['contentShareImage'],
  223. 'media_id' => $linkInfo['mediaId'],
  224. 'wx_share_description' => $linkInfo['wxShareDescription'],
  225. 'pid' => $pid
  226. ];
  227. $result = PromoteLink::query()->insert($insertData);
  228. if(!$result) {
  229. Log::logError('迈步推广链接存储失败', ['data' => $insertData], 'CreateLink');
  230. }
  231. if(0 == $params['link_type']) {
  232. $pagePath = $insertData['page_path'] ?? null;
  233. } else {
  234. $pagePath = $insertData['h5'] ?? null;
  235. }
  236. return [$pagePath, $pid];
  237. }
  238. public static function setPlayletGroup($sysGroupId, $corpid, $adminId, $groupId, $name, $playletList, &$errno)
  239. {
  240. if(empty($playletList)) {
  241. $errno = 4101; // 短剧信息不能为空
  242. return false;
  243. }
  244. if(!is_array($playletList)){
  245. $playletList = json_decode($playletList, 1);
  246. }
  247. try{
  248. \DB::begintransaction();
  249. // 更新短剧组
  250. if($groupId) {
  251. $res1 = PlatformPlayletGroup::query()->where('id', $groupId)->update([
  252. 'name' => $name,
  253. 'corpid' => $corpid,
  254. 'sys_group_id' => $sysGroupId,
  255. 'admin_id' => $adminId,
  256. ]);
  257. // 将现有短剧组enable更新为0
  258. $res2 = PlatformPlayletGroupDetail::query()->where('group_id', $groupId)
  259. ->where('enable', 1)->update(['enable' => 0]);
  260. RedisModel::lPush(MassMsgLinkRecord::WELCOME_MSG_PLAYLET_GROUP_UPDATE_RDS, $groupId);
  261. } else {
  262. $res1 = $groupId = PlatformPlayletGroup::query()->insertGetId([
  263. 'name' => $name,
  264. 'corpid' => $corpid,
  265. 'sys_group_id' => $sysGroupId,
  266. 'admin_id' => $adminId,
  267. ]);
  268. if(!$res1) {
  269. \DB::rollBack();
  270. $errno = 4103;
  271. Log::logError('设置剧集组接口异常状态码',[
  272. 'sys_group_id' => $sysGroupId,
  273. 'corpid' => $corpid,
  274. 'admin_id' => $adminId,
  275. 'group_id' => $groupId,
  276. 'name' => $name,
  277. 'playlet_list' => $playletList,
  278. 'errno' => $errno,
  279. ], 'interface');
  280. return false;
  281. }
  282. }
  283. // 循环处理剧集详情信息
  284. foreach($playletList as $key => &$playletInfo) {
  285. $dataId = $playletInfo['data_id'] ?? 0;
  286. $item['sort_order'] = $key + 1;// 补完排序值
  287. $item['group_id'] = $groupId;// 短剧组ID
  288. $item['enable'] = 1;// 有效性
  289. $item['corpid'] = $corpid;
  290. $item['force_subscribe'] = 0;
  291. $item['force_subscribe_sectionId'] = 0;
  292. $item['type'] = 0;
  293. $item['name'] = $playletInfo['name'];
  294. $item['episode_num'] = $playletInfo['episode_num'];
  295. $item['app_id'] = $playletInfo['app_id'];
  296. $item['mini_app_id'] = $playletInfo['mini_app_id'] ?? null;
  297. $item['account_id'] = $playletInfo['account_id'];
  298. $item['link_type'] = $playletInfo['link_type'];
  299. $item['platform_id'] = $playletInfo['platform_id'];
  300. $item['playlet_id'] = $playletInfo['playlet_id'];
  301. $item['playlet_unique_id'] = $playletInfo['playlet_unique_id'];
  302. // 处理好的短剧信息入库
  303. if(empty($dataId)) {
  304. $detailRes = PlatformPlayletGroupDetail::query()->insert($item);
  305. } else {
  306. $detailRes = PlatformPlayletGroupDetail::query()->where('id', $dataId)->update($item);
  307. }
  308. if(!$detailRes) {
  309. \DB::rollBack();
  310. $errno = 4102;
  311. Log::logError('设置剧集组接口异常状态码',[
  312. 'sys_group_id' => $sysGroupId,
  313. 'corpid' => $corpid,
  314. 'admin_id' => $adminId,
  315. 'group_id' => $groupId,
  316. 'name' => $name,
  317. 'playlet_list' => $playletList,
  318. 'errno' => $errno,
  319. ], 'interface');
  320. return false;
  321. }
  322. }
  323. \DB::commit();
  324. return true;
  325. } catch (\Exception $exception) {
  326. Log::logError('设置剧集组接口异常',[
  327. 'params' => [
  328. 'sys_group_id' => $sysGroupId,
  329. 'corpid' => $corpid,
  330. 'admin_id' => $adminId,
  331. 'group_id' => $groupId,
  332. 'name' => $name,
  333. 'playlet_list' => $playletList,
  334. ],
  335. 'exception' => [
  336. 'file' => $exception->getFile(),
  337. 'line' => $exception->getLine(),
  338. 'message' => $exception->getMessage(),
  339. 'trace' => $exception->getTraceAsString(),
  340. ]
  341. ], 'interface');
  342. $errno = 500;
  343. return false;
  344. }
  345. }
  346. public static function playletGroupList($sysGroupId, $page, $pageSize)
  347. {
  348. $groupQuery = PlatformPlayletGroup::query()->where('sys_group_id', $sysGroupId)
  349. ->where('enable', 1);
  350. $total = $groupQuery->count();
  351. $offset = ($page - 1) * $pageSize;
  352. $list = $groupQuery->selectRaw('id as group_id, name')->offset($offset)->limit($pageSize)
  353. ->get();
  354. // 提取短剧组ID
  355. $groupIdList = array_column($list->toArray(), 'group_id');
  356. // 查询对应的短剧列表
  357. $groupDetailList = PlatformPlayletGroupDetail::query()->whereIn('group_id', $groupIdList)
  358. ->where('enable', 1)->orderBy('sort_order', 'asc')->get();
  359. # 查询剧封面和标题
  360. $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'playlet_id',
  361. 'platform_id')->where('enable', 1)->where('state', 1)
  362. ->get();
  363. foreach($list as &$item) {
  364. $groupDetail = $groupDetailList->where('group_id', $item->group_id)->all();
  365. $playletArr = [];
  366. foreach($groupDetail as $value) {
  367. $playletInfo = $playletInfoList->where('platform_id', $value->platform_id)
  368. ->where('playlet_id', $value->playlet_id)->first();
  369. if(!empty($playletInfo)){
  370. $playletArr[] = $playletInfo;
  371. }
  372. }
  373. $item->playlet_list = $playletArr;
  374. }
  375. return [$list, $total];
  376. }
  377. public static function addPlayletToGroup($params, &$errno)
  378. {
  379. // 判断该剧是否已经加入短剧组
  380. $row = PlatformPlayletGroupDetail::query()->where('platform_id', $params['platform_id'])
  381. ->where('enable', 1)->where('group_id', $params['group_id'])
  382. ->where('playlet_id', $params['playlet_id'])->first();
  383. if($row) {
  384. $res = PlatformPlayletGroupDetail::query()->where('id', $row->id)->update($params);
  385. } else {
  386. $res = PlatformPlayletGroupDetail::query()->insert($params);
  387. }
  388. if(!$res){
  389. $errno = 400;
  390. return false;
  391. }
  392. return true;
  393. }
  394. public static function playletGroupDetail($groupId)
  395. {
  396. $groupInfo = PlatformPlayletGroup::query()->selectRaw('id as group_id, name')
  397. ->where('id', $groupId)->first();
  398. if(empty($groupInfo)){
  399. return [[], 4104];
  400. }
  401. // 查询对应的短剧列表
  402. $groupDetailList = PlatformPlayletGroupDetail::query()->where('group_id', $groupId)
  403. ->where('enable', 1)->selectRaw('id as data_id, corpid, platform_id, '.
  404. 'account_id, app_id, mini_app_id, name, playlet_id, episode_num, link_type, playlet_unique_id')
  405. ->orderBy('sort_order', 'asc')->get();
  406. $groupDetailList = $groupDetailList->isNotEmpty() ? $groupDetailList->toArray() : [];
  407. # 查询剧封面和标题
  408. $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'playlet_id',
  409. 'platform_id')->where('enable', 1)->where('state', 1)
  410. ->get();
  411. foreach($groupDetailList as $key => $value) {
  412. $playletInfo = $playletInfoList->where('platform_id', $value['platform_id'])
  413. ->where('playlet_id', $value['playlet_id'])->first();
  414. if(empty($playletInfo)) {
  415. unset($groupDetailList[$key]);
  416. continue;
  417. }
  418. $groupDetailList[$key]['playlet_name'] = $playletInfo->name ?? '';
  419. $groupDetailList[$key]['playlet_description'] = $playletInfo->description ?? '';
  420. $groupDetailList[$key]['playlet_cover'] = $playletInfo->cover_url;
  421. }
  422. $groupInfo->playlet_list = $groupDetailList;
  423. return [$groupInfo, 0];
  424. }
  425. public static function playletGroupH5Detail($groupId, $sender, $ruleId, $msgType)
  426. {
  427. $list = MassMsgLinkRecord::query()->where('playlet_group_id', $groupId)->where('enable', 1)
  428. ->where('sender', $sender)->where('rule_id', $ruleId)->where('msg_type', $msgType)
  429. ->select(['playlet_id', 'platform_id', 'link_type', 'link', 'desc'])->orderBy('sort', 'asc')
  430. ->get();
  431. $list = $list->isNotEmpty() ? $list->toArray() : [];
  432. # 查询剧封面和标题
  433. $playletInfoList = PlatformPlaylet::query()->select('name', 'description', 'cover_url', 'platform_id',
  434. 'playlet_id')->where('enable', 1)->where('state', 1)
  435. ->get();
  436. foreach($list as $key=>$value){
  437. $playletInfo = $playletInfoList->where('platform_id', $value['platform_id'])
  438. ->where('playlet_id', $value['playlet_id'])->first();
  439. if(empty($playletInfo)) {
  440. unset($list[$key]);
  441. continue;
  442. }
  443. $list[$key]['playlet_name'] = $playletInfo->name ?? '';
  444. $list[$key]['playlet_description'] = $playletInfo->description ?? '';
  445. $list[$key]['playlet_cover'] = $playletInfo->cover_url ?? '';
  446. }
  447. return $list;
  448. }
  449. /*
  450. * 创建推广链接
  451. * */
  452. public static function paramsValidate($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  453. {
  454. try {
  455. # 检验小程序app_id
  456. if($platformId != 4 && empty($params['mini_app_id'])){
  457. $errno = 4105;
  458. return ['小程序app_id必填'];
  459. }
  460. if($platformId == 4 && 0 == $params['link_type']){
  461. $errno = 4106;
  462. return ['嘉书平台只能够创建H5类型的推广链接'];
  463. }
  464. switch($platformId) {
  465. case 4: // 嘉书H5(东方小剧场)
  466. $pagePath = self::validateJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId,$errno);
  467. break;
  468. case 3: // 迈步
  469. $pagePath = self::validateMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, $errno);
  470. break;
  471. default:
  472. $errno = 4910;
  473. break;
  474. }
  475. } catch (\Exception $e) {
  476. EmailQueue::rPush('生成推广链接过程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com',
  477. 'song.shen@kuxuan-inc.com'], '生成推广链接过程发生异常');
  478. Log::logError('迈步推广链接存储失败', [
  479. 'line' => $e->getLine(),
  480. 'msg' => $e->getMessage(),
  481. 'params' => $params,
  482. 'platformId' => $platformId,
  483. 'accountId' => $accountId,
  484. 'sys_group_id' => $sysGroupId,
  485. 'admin_id' => $adminId
  486. ], 'CreateLink');
  487. $errno = 4914;
  488. }
  489. if($errno || !$pagePath) return [];
  490. return [];
  491. }
  492. public static function validateJiaShuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  493. {
  494. # 查询渠道商id
  495. $channelInfo = IntelligentMassSendingAccount::query()->where('id', $accountId)
  496. ->where('platform_id', $platformId)->where('status', 1)
  497. ->where('active_status', 1)->where('enable', 1)->first();
  498. if(empty($channelInfo)) {
  499. $errno = 4912;
  500. return [];
  501. }
  502. $customerId = $channelInfo->service_provider_id;
  503. $apiKey = $channelInfo->api_key;
  504. # 查询第三方平台app_id
  505. $platformAppId = PlatformApp::getAppExit($platformId, $customerId, $params['app_id']);
  506. if(empty($platformAppId)) {
  507. $errno = 4915;
  508. return [];
  509. }
  510. # 查询剧集
  511. $sectionCount = PlatformPlaylet::query()
  512. ->where('platform_id', $platformId)
  513. ->where('playlet_id', $params['playlet_id'])
  514. ->where('enable', 1)
  515. ->value('section_count');
  516. if(empty($sectionCount) || $params['episode_num'] > $sectionCount) {
  517. $errno = 4911;
  518. return [];
  519. }
  520. return true;
  521. }
  522. public static function validateMaibuLink($params, $platformId, $accountId, $sysGroupId, $adminId, &$errno)
  523. {
  524. # 查询渠道商id
  525. $channelId = IntelligentMassSendingAccount::query()->where('id', $accountId)
  526. ->where('platform_id', $platformId)->where('status', 1)
  527. ->where('active_status', 1)->where('enable', 1)
  528. ->value('service_provider_id');
  529. if(empty($channelId)) {
  530. $errno = 4912;
  531. return [];
  532. }
  533. # 查询第三方平台app_id
  534. $platformAppId = PlatformApp::getPlatformAppId($platformId, $channelId, $params['app_id'], $params['mini_app_id']);
  535. if(empty($platformAppId)) {
  536. $errno = 4915;
  537. return [];
  538. }
  539. # 查询剧集id
  540. $episodeId = PlatformEpisode::query()->where('platform_id', $platformId)
  541. ->where('playlet_id', $params['playlet_id'])
  542. ->where('name', '第'.$params['episode_num'].'集')->where('enable', 1)
  543. ->value('episode_id');
  544. if(empty($episodeId)) {
  545. $errno = 4911;
  546. return [];
  547. }
  548. return true;
  549. }
  550. public static function batchCreateLink($sysGroupId, $corpid, $adminId, $playletList)
  551. {
  552. if(empty($playletList)) {
  553. return ['短剧信息不能为空', 4101];
  554. }
  555. if(!is_array($playletList)){
  556. $playletList = json_decode($playletList, 1);
  557. }
  558. if(count($playletList) > 9) {
  559. return ['一次最多只能创建9条推广链接', 4107];
  560. }
  561. $linkData = [];
  562. try {
  563. // 循环处理剧集详情信息
  564. foreach($playletList as $key => $playletInfo) {
  565. # 判断必要参数
  566. if(
  567. !isset($playletInfo['platform_id']) ||
  568. !isset($playletInfo['account_id']) ||
  569. !isset($playletInfo['app_id']) ||
  570. !isset($playletInfo['name']) ||
  571. !isset($playletInfo['playlet_id']) ||
  572. !isset($playletInfo['episode_num']) ||
  573. !isset($playletInfo['link_type'])) {
  574. $errno = 1103;
  575. $linkData[] = [
  576. 'link_data' => $playletInfo,
  577. 'err_no' => $errno,
  578. 'err_msg' => Error::getError($errno)
  579. ];
  580. continue;
  581. }
  582. if($playletInfo['platform_id'] == 4 && 0 == $playletInfo['link_type']){
  583. $errno = 4106;
  584. $linkData[] = [
  585. 'link_data' => $playletInfo,
  586. 'err_no' => $errno,
  587. 'err_msg' => Error::getError($errno)
  588. ];
  589. continue;
  590. }
  591. if(!isset($playletInfo['page']) || empty($playletInfo['page'])) {
  592. $playletInfo['corpid'] = $corpid;
  593. $playletInfo['force_subscribe'] = 0;
  594. $playletInfo['force_subscribe_sectionId'] = 0;
  595. $playletInfo['type'] = 0;
  596. $errno = 0;
  597. $linkInfo = PlatformService::createLink(
  598. $playletInfo, $playletInfo['platform_id'], $playletInfo['account_id'], $sysGroupId,
  599. $adminId, $errno
  600. );
  601. if(empty($linkInfo) || $errno > 0) {
  602. $linkData[] = [
  603. 'link_data' => $playletInfo,
  604. 'err_no' => $errno,
  605. 'err_msg' => Error::getError($errno)
  606. ];
  607. } else {
  608. $linkInfo = array_merge($linkInfo, $playletInfo);
  609. $linkData[] = [
  610. 'link_data' => $linkInfo,
  611. 'err_no' => 0,
  612. 'err_msg' => ''
  613. ];
  614. }
  615. if(in_array($linkInfo, [4])) {// 嘉书平台限制1秒钟请求一次接口
  616. sleep(1);
  617. }
  618. } else {
  619. $linkData[] = [
  620. 'link_data' => $playletInfo,
  621. 'err_no' => 0,
  622. 'err_msg' => ''
  623. ];
  624. }
  625. }
  626. return [$linkData, 0];
  627. } catch (\Exception $e) {
  628. EmailQueue::rPush('批量创建推广链接过程发生异常', $e->getTraceAsString(), [
  629. 'song.shen@kuxuan-inc.com'], '批量创建推广链接过程发生异常');
  630. Log::logError('批量创建推广链接过程发生异常', [
  631. 'line' => $e->getLine(),
  632. 'msg' => $e->getMessage(),
  633. 'playlet_list' => $playletList,
  634. 'corpid' => $corpid,
  635. 'sys_group_id' => $sysGroupId,
  636. 'admin_id' => $adminId
  637. ], 'CreateLink');
  638. $errno = 4914;
  639. return [$linkData, $errno];
  640. }
  641. }
  642. }