企微短剧业务系统

PitcherService.php 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\AccountConfigNoUserRelation;
  5. use App\Models\AdqUser;
  6. use App\Models\DjUser;
  7. use App\Models\DramaSeries;
  8. use App\Models\DramaUserRela;
  9. use App\Models\OfficialAccount;
  10. use App\Models\OfficialAccountRelation;
  11. use App\Models\OfficialWebUserActionReportConf;
  12. use App\Models\OfficialWebUserActionSetId;
  13. use App\Models\OperateLog;
  14. use App\Models\ReportRules;
  15. use App\Models\OfficialReportRules;
  16. use App\Models\System\Users;
  17. use App\Models\TencentAdAuth;
  18. use App\Models\TencentAdConf;
  19. use App\Models\AuthorizeCorp;
  20. use App\RedisModel;
  21. use App\Support\EmailQueue;
  22. use Illuminate\Support\Facades\Auth;
  23. class PitcherService
  24. {
  25. public static function wxAccountList($keyword, $isSelect, $page, $pageSize, $sysGroupId, $adminId, $isSystemAdmin)
  26. {
  27. // $mpAppIdList = OfficialAccount::getSysGroupMpAppIdList($sysGroupId, 'PitcherService.wxAccountList');
  28. $mpAppIdList = OfficialAccount::getAccountMpAppIdList($adminId, $sysGroupId, $isSystemAdmin);
  29. return PitcherService::officialAccountsMap($keyword, $isSelect, $page, $pageSize, $mpAppIdList, $sysGroupId, $adminId, $isSystemAdmin);
  30. }
  31. public static function officialAccountsList($keyword, $isSelect, $page, $pageSize, $sysGroupId, $adminId, $isSystemAdmin)
  32. {
  33. $mpAppIdList = OfficialAccountRelation::getSysGroupMpAppIdList($sysGroupId, true, []);
  34. return PitcherService::officialAccountsMap($keyword, $isSelect, $page, $pageSize, $mpAppIdList, $sysGroupId, $adminId, $isSystemAdmin);
  35. }
  36. public static function officialAccountsMap($keyword, $isSelect, $page, $pageSize, $mpAppIdList, $sysGroupId, $adminId, $isSystemAdmin)
  37. {
  38. $wxAccountQuery = TencentAdAuth::query()
  39. ->select(['wechat_account_id', 'account_name', 'created_at', 'is_provisional_stat'])
  40. ->where('enable', 1)
  41. ->whereIn('wechat_account_id', $mpAppIdList);
  42. if (!$isSelect && !empty($keyword)) $wxAccountQuery->where('account_name', 'like', '%'.$keyword.'%');
  43. $total = (clone $wxAccountQuery)->distinct('wechat_account_id')->count();
  44. $wxAccountQuery->groupBy(['wechat_account_id'])->orderByDesc('created_at');
  45. if (!$isSelect) {
  46. if ($total == 0) return [[], 0];
  47. $wxAccountList = $wxAccountQuery
  48. ->offset(($page - 1) * $pageSize)
  49. ->limit($pageSize)
  50. ->get();
  51. $bindInfoList = DramaUserRela::getAccountDramaCount($wxAccountList->pluck('wechat_account_id'), $sysGroupId, 1);
  52. $accountRules = OfficialReportRules::query()
  53. ->whereIn('app_id', $wxAccountList->pluck('wechat_account_id'))
  54. ->select('app_id', 'report_enable', 'report_type', 'purchase_enable', 'miss_enable', 'miss_setvale')
  55. ->get()
  56. ->keyBy('app_id')
  57. ->toArray();
  58. $accountAdConf = TencentAdConf::query()
  59. ->whereIn('app_id', $wxAccountList->pluck('wechat_account_id'))
  60. ->select('app_id', 'user_action_set_id', 'corp_id', 'corp_name', 'channel')
  61. ->get()
  62. ->keyBy('app_id')
  63. ->toArray();
  64. $rules = ReportRules::query()->where('enable', 1)->pluck('name', 'id')->all();
  65. foreach ($wxAccountList as $value) {
  66. $value->drama_count = $bindInfoList->get($value->wechat_account_id) ?? 0;
  67. $value->report_enable = $accountRules[$value->wechat_account_id]['report_enable'] ?? 0;
  68. $value->report_type = $accountRules[$value->wechat_account_id]['report_type'] ?? 0;
  69. $value->purchase_enable = $accountRules[$value->wechat_account_id]['purchase_enable'] ?? 0;
  70. $value->miss_enable = $accountRules[$value->wechat_account_id]['miss_enable'] ?? 0;
  71. $value->miss_setvale = $accountRules[$value->wechat_account_id]['miss_setvale'] ?? 0;
  72. $value->user_action_set_id = $accountAdConf[$value->wechat_account_id]['user_action_set_id'] ?? 0;
  73. $value->corp_id = $accountAdConf[$value->wechat_account_id]['corp_id'] ?? 0;
  74. $value->corp_name = $accountAdConf[$value->wechat_account_id]['corp_name'] ?? 0;
  75. $value->rule_name = $rules[$value->report_type] ?? '';
  76. $value->channel = $accountAdConf[$value->wechat_account_id]['channel'] ?? 0;
  77. }
  78. return [$wxAccountList, $total];
  79. } else {
  80. if ($total == 0) return [];
  81. $wxAccountList = $wxAccountQuery->get();
  82. return $wxAccountList;
  83. }
  84. }
  85. /**
  86. * 获取账号所有投放账号信息
  87. * */
  88. public static function adAccountList($keyword, $sysGroupId, $adminId, $isSystemAdmin)
  89. {
  90. $isAllMp = $isAllAdq = true;
  91. $mpAccountIdList = $adqAccountIdList = [];
  92. if($sysGroupId != $adminId && !$isSystemAdmin) {
  93. # 获取该账号已分配的adq账号
  94. $accountAuthInfo = Users::select('is_all_adq', 'adq_account', 'is_all_mp', 'mp_account')
  95. ->where('enable', 1)->where('id', $adminId)
  96. ->first();
  97. if(empty($accountAuthInfo)) return [];
  98. if(!$accountAuthInfo->is_all_adq) {
  99. $isAllAdq = false;
  100. $adqAccountIdList = $accountAuthInfo->adq_account ? explode(',', $accountAuthInfo->adq_account) : [];
  101. }
  102. if(!$accountAuthInfo->is_all_mp) {
  103. $isAllMp = false;
  104. $mpAccountIdList = $accountAuthInfo->mp_account ? explode(',', $accountAuthInfo->mp_account) : [];
  105. }
  106. }
  107. # 获取企业下的adq账号
  108. $adqAccountList = OfficialWebUserActionSetId::selectRaw('account_id, account_id as account_name')
  109. ->where(function($query) use($keyword) {
  110. if($keyword) $query->where('account_id', 'like', '%'.$keyword.'%');
  111. })
  112. ->where(function($query) use($isAllAdq, $adqAccountIdList) {
  113. if($isAllAdq === false) {
  114. $query->whereIn('account_id', $adqAccountIdList);
  115. }
  116. })
  117. ->where('sys_group_id', $sysGroupId)
  118. ->where('enable', 1)
  119. ->groupBy(['account_id'])
  120. ->get()->toArray();
  121. # 获取企业下的mp账号
  122. $mpAccountIds = OfficialAccountRelation::selectRaw('app_id')->where('enable', 1)
  123. ->where('sys_group_id', $sysGroupId)
  124. ->where(function($query) use($isAllMp, $mpAccountIdList) {
  125. if($isAllMp === false) {
  126. $query->whereIn('app_id', $mpAccountIdList);
  127. }
  128. })
  129. ->distinct()->pluck('app_id');
  130. $mpAccountList = TencentAdAuth::selectRaw('wechat_account_id as account_id, account_name')
  131. ->where(function($query) use($keyword) {
  132. if($keyword) $query->where('account_name', 'like', '%'.$keyword.'%');
  133. })
  134. ->where('enable', 1)
  135. ->whereIn('wechat_account_id', $mpAccountIds)
  136. ->get()->toArray();
  137. return array_merge($adqAccountList, $mpAccountList);
  138. }
  139. /**
  140. * 获取当前登录账号可见的adq账号
  141. * */
  142. public static function adqAccountListForUser($adminId, $sysGroupId, $isSystemAdmin)
  143. {
  144. $isAll = true;
  145. $accountList = [];
  146. if($sysGroupId != $adminId && !$isSystemAdmin) {
  147. # 获取该账号已分配的adq账号
  148. $accountAuthInfo = Users::select('is_all_adq', 'adq_account')->where('enable', 1)->where('id', $adminId)->first();
  149. if(empty($accountAuthInfo)) return [];
  150. if(!$accountAuthInfo->is_all_adq) {
  151. $isAll = false;
  152. $accountList = $accountAuthInfo->adq_account ? explode(',', $accountAuthInfo->adq_account) : [];
  153. }
  154. }
  155. $adqAccountList = OfficialWebUserActionSetId::where('sys_group_id', $sysGroupId)
  156. ->where(function ($query) use($isAll, $accountList) {
  157. if($isAll === false) {
  158. $query->whereIn('account_id', $accountList);
  159. }
  160. })
  161. ->where('enable', 1)->pluck('account_id')->toArray();
  162. return $adqAccountList;
  163. }
  164. public static function dramaList($keyword, $isSelect, $page, $pageSize, $sysGroupId)
  165. {
  166. $dramaQuery = DramaSeries::query()
  167. ->select(['id', 'name', 'created_at', 'enable'])
  168. ->where(function ($query) use ($isSelect, $keyword) {
  169. if (!$isSelect && !empty($keyword)) $query->where('name', 'like', '%'.$keyword.'%');
  170. })
  171. ->where('sys_group_id', $sysGroupId)
  172. ->orderByDesc('created_at');
  173. $total = $dramaQuery->count();
  174. if (!$isSelect) {
  175. if ($total == 0) return [[], 0];
  176. $dramaList = $dramaQuery->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
  177. return [$dramaList, $total];
  178. } else {
  179. if ($total == 0) return [];
  180. $dramaList = $dramaQuery->get();
  181. return $dramaList;
  182. }
  183. }
  184. public static function pitcherList($sysGroupId)
  185. {
  186. $res = Users::query()
  187. ->where('group_admin_id', $sysGroupId)
  188. ->where('is_promoter', 1)
  189. ->where('enable', 1)
  190. ->select("id","name")
  191. ->get();
  192. if($res->isEmpty()) {
  193. return [];
  194. }
  195. Log::logInfo('pitcherList', [
  196. 'sys_group_id' => $sysGroupId,
  197. 'user_list' => $res->toArray()], 'app_auth');
  198. return $res->toArray();
  199. }
  200. public static function bind($appId, $dramaId, $userId, $startDate, $endDate, $sysGroupId)
  201. {
  202. $wxAccountInfo = OfficialAccount::query()
  203. ->where('mp_app_id', $appId)
  204. ->where('enable', 1)
  205. ->first();
  206. if (empty($wxAccountInfo)) return [false, 3101];
  207. $dramaInfo = DramaSeries::getDramaInfoById($dramaId);
  208. if (empty($dramaInfo)) return [false, 3102];
  209. $userInfo = Users::query()
  210. ->where('id', $userId)
  211. ->where('enable', 1)
  212. ->first();
  213. if (empty($userInfo)) return [false, 3103];
  214. // 时间校验
  215. $checkRes = self::dateCheck($appId, $startDate, $endDate);
  216. if (!$checkRes) return [false, 3105];
  217. $result = [
  218. 'app_id' => $appId,
  219. 'drama_id' => $dramaId,
  220. 'user_id' => $userId,
  221. 'start_date' => $startDate,
  222. 'end_date' => $endDate,
  223. 'sys_group_id' => $sysGroupId,
  224. 'order_type' => 1,
  225. ];
  226. DataStatisticsService::mpRelaAdd($appId, $dramaId, $userId, $startDate, $endDate);
  227. try {
  228. DramaUserRela::query()->firstOrCreate($result, $result);
  229. } catch (\Throwable $e) {
  230. Log::logError('数据关系绑定失败', [
  231. 'appId' => $appId,
  232. 'dramaId' => $dramaId,
  233. 'userId' => $userId,
  234. 'startDate' => $startDate,
  235. 'endDate' => $endDate,
  236. 'order_type'=> 1,
  237. ], 'PitcherService');
  238. return [false, 3106];
  239. }
  240. // 日志记录
  241. Log::logInfo('编辑账号绑定短剧投手', [
  242. 'old' => [],
  243. 'new' => [
  244. 'app_id' => $appId,
  245. 'drama_id' => $dramaId,
  246. 'user_id' => $userId,
  247. 'start_date' => $startDate,
  248. 'end_date' => $endDate,
  249. 'sys_group_id' => $sysGroupId,
  250. ],
  251. 'operate' => 'add',
  252. 'order_type' => 1
  253. ], 'pitcher_change');
  254. return [true, 0];
  255. }
  256. public static function index($appId, $page, $pageSize, $sysGroupId)
  257. {
  258. $tDate = date('Y-m-d');
  259. $fieldList = 'id, app_id, drama_id, user_id, start_date, end_date, enable';
  260. $relaList = DramaUserRela::getBindList($appId, $sysGroupId, $page, $pageSize, $fieldList, 1);
  261. if ($relaList->isEmpty()) return [[], 0];
  262. $total = $relaList->count();
  263. $dramaList = DramaSeries::query()->whereIn('id', $relaList->pluck('drama_id'))->pluck('name', 'id');
  264. $userList = Users::query()->whereIn('id', $relaList->pluck('user_id'))->pluck('name', 'id');
  265. foreach ($relaList as $value) {
  266. $value->is_contain = 0;
  267. if (($tDate >= $value->start_date) && ($tDate <= $value->end_date)) {
  268. $value->is_contain = 1;
  269. }
  270. $value->drama_name = $dramaList->get($value->drama_id) ?? null;
  271. $value->user_name = $userList->get($value->user_id) ?? null;
  272. }
  273. return [$relaList, $total];
  274. }
  275. public static function relaEdit($relaId, $dramaId, $userId, $startDate, $endDate, $enable)
  276. {
  277. $relaInfo = DramaUserRela::query()->find($relaId);
  278. if (empty($relaInfo)) return [false, 3104];
  279. $old = $relaInfo->toArray();
  280. // 时间校验
  281. $checkRes = self::dateCheck($relaInfo->app_id, $startDate, $endDate, $relaId);
  282. if (!$checkRes) return [false, 3105];
  283. try {
  284. $relaInfo->update([
  285. 'drama_id' => $dramaId,
  286. 'user_id' => $userId,
  287. 'start_date' => $startDate,
  288. 'end_date' => $endDate,
  289. 'enable' => $enable
  290. ]);
  291. } catch (\Throwable $e) {
  292. Log::logError('绑定数据编辑失败', [
  293. 'relaId' => $relaId,
  294. 'dramaId' => $dramaId,
  295. 'userId' => $userId,
  296. 'startDate' => $startDate,
  297. 'endDate' => $endDate,
  298. 'enable' => $enable
  299. ], 'PitcherService');
  300. return [false, 3106];
  301. }
  302. DataStatisticsService::mpRelaEdit($dramaId, $userId, $startDate, $endDate, $enable, $old);
  303. // 日志记录
  304. Log::logInfo('编辑账号绑定短剧投手', [
  305. 'old' => $old,
  306. 'new' => [
  307. 'drama_id' => $dramaId,
  308. 'user_id' => $userId,
  309. 'start_date' => $startDate,
  310. 'end_date' => $endDate,
  311. 'enable' => $enable
  312. ],
  313. 'operate' => 'edit',
  314. 'order_type' => 1,
  315. ], 'pitcher_change');
  316. return [true, 0];
  317. }
  318. public static function dateCheck($appId, $stDate, $enDate, $relaId = null)
  319. {
  320. $dateList = DramaUserRela::query()
  321. ->select(['start_date', 'end_date'])
  322. ->where('app_id', $appId)
  323. ->where(function ($query) use ($relaId) {
  324. if (!empty($relaId)) $query->where('id', '!=', $relaId);
  325. })
  326. ->where('end_date', '>=', $stDate)
  327. ->where('enable', 1)
  328. ->get();
  329. if ($dateList->isEmpty()) return true;
  330. $dateArr = $dateList->toArray();
  331. $dateArr[] = [
  332. 'start_date' => $stDate,
  333. 'end_date' => $enDate
  334. ];
  335. $stDataList = array_column($dateArr, 'start_date');
  336. array_multisort($stDataList, SORT_ASC, $dateArr);
  337. foreach ($dateArr as $k => $v){
  338. if ($v['start_date'] > $v['end_date'])
  339. return false;
  340. if ($k > 0 && ($dateArr[$k]['start_date'] <= $dateArr[$k-1]['end_date']))
  341. return false;
  342. }
  343. return true;
  344. }
  345. public static function adqDateCheck($accountId, $stDate, $enDate, $sysGroupId, $relaId = null)
  346. {
  347. $dateList = DramaUserRela::query()
  348. ->select(['start_date', 'end_date'])
  349. ->where('account_id', $accountId)
  350. ->where('sys_group_id', $sysGroupId)
  351. ->where(function ($query) use ($relaId) {
  352. if (!empty($relaId)) $query->where('id', '!=', $relaId);
  353. })
  354. ->where('end_date', '>=', $stDate)
  355. ->where('enable', 1)
  356. ->get();
  357. if ($dateList->isEmpty()) return true;
  358. $dateArr = $dateList->toArray();
  359. $dateArr[] = [
  360. 'start_date' => $stDate,
  361. 'end_date' => $enDate
  362. ];
  363. $stDataList = array_column($dateArr, 'start_date');
  364. array_multisort($stDataList, SORT_ASC, $dateArr);
  365. foreach ($dateArr as $k => $v){
  366. if ($v['start_date'] > $v['end_date'])
  367. return false;
  368. if ($k > 0 && ($dateArr[$k]['start_date'] <= $dateArr[$k-1]['end_date']))
  369. return false;
  370. }
  371. return true;
  372. }
  373. public static function dramaAdd($dramaName, $sysGroupId, &$errno)
  374. {
  375. # 校验剧是否已存在
  376. $isExist = DramaSeries::where('sys_group_id', $sysGroupId)->where('name', $dramaName)->exists();
  377. if($isExist) {
  378. $errno = 3108;
  379. return [];
  380. }
  381. $res = DramaSeries::updateOrInsert([
  382. 'name' => $dramaName,
  383. 'sys_group_id' => $sysGroupId
  384. ], [
  385. 'name' => $dramaName,
  386. 'sys_group_id' => $sysGroupId
  387. ]);
  388. $errno = $res ? 0 : 3109;
  389. return [];
  390. }
  391. public static function dramaEdit($dramaId, $dramaName, $enable)
  392. {
  393. $dramaInfo = DramaSeries::query()->find($dramaId);
  394. if (empty($dramaInfo)) return [false, 3102];
  395. try {
  396. $dramaInfo->update([
  397. 'name' => $dramaName,
  398. 'enable' => $enable
  399. ]);
  400. } catch (\Throwable $e) {
  401. Log::logError('剧集编辑失败', [
  402. 'dramaId' => $dramaId,
  403. 'dramaName' => $dramaName,
  404. 'enable' => $enable
  405. ], 'PitcherService');
  406. return [false, 3106];
  407. }
  408. return [true, 0];
  409. }
  410. public static function reportRuleList()
  411. {
  412. $res = ReportRules::select('id', 'name')->where('enable', 1)->orderBy('id')->get();
  413. return $res;
  414. }
  415. public static function setReportRule($app_ids, $report_type, $report_enable, $purchase_enable, $miss_enable, $miss_setvale, $if_all=0)
  416. {
  417. if ($miss_enable == 1 && $miss_setvale == 0) return [false, 4408];
  418. $data = [
  419. 'report_type' => $report_type,
  420. 'report_enable' => $report_enable,
  421. 'purchase_enable' => $purchase_enable,
  422. 'miss_enable' => $miss_enable,
  423. 'miss_setvale' => $miss_setvale,
  424. 'enable' => 1
  425. ];
  426. //配置所有为一种规则
  427. if($if_all == 1){
  428. $app_ids = TencentAdAuth::query()
  429. ->where('enable', 1)
  430. ->select('wechat_account_id')
  431. ->distinct()
  432. ->pluck('wechat_account_id')
  433. ->all();
  434. }
  435. foreach($app_ids as $app_id){
  436. $rulesRes = OfficialReportRules::updateOrCreate(['app_id' => $app_id], $data);
  437. // 写入缓存
  438. RedisModel::hSet(OfficialReportRules::OFFICIAL_REPORT_RULES_CONF, $app_id, json_encode([
  439. 'report_enable' => $rulesRes->report_enable,
  440. 'report_type' => $rulesRes->report_type,
  441. 'purchase_enable' => $rulesRes->purchase_enable,
  442. 'miss_enable' => $rulesRes->miss_enable,
  443. 'miss_setvale' => $rulesRes->miss_setvale,
  444. 'enable' => $rulesRes->enable
  445. ]));
  446. // 判断漏单是否关闭,若关闭,则将漏单计数清零
  447. if(0 == $miss_enable) {
  448. RedisModel::hDel(OfficialReportRules::OFFICIAL_REPORT_MISS_INCR_NUM, $app_id);
  449. }
  450. }
  451. return [true, 0];
  452. }
  453. public static function setAccountReportConf($app_id, $user_action_set_id, $corp_id, $channel, $isProvisionalStat, $sysGroupId)
  454. {
  455. $corp_name = AuthorizeCorp::where('corpid', $corp_id)->value('corp_name');
  456. $conf = TencentAdConf::where('app_id', $app_id)->first();
  457. $account = TencentAdAuth::where('wechat_account_id', $app_id)->select(['account_id', 'is_provisional_stat'])->first();
  458. if($account->is_provisional_stat != $isProvisionalStat) {
  459. $result = TencentAdAuth::where('wechat_account_id', $app_id)->update(['is_provisional_stat' => $isProvisionalStat]);
  460. if($isProvisionalStat == 0) {
  461. AccountConfigNoUserRelation::where('app_id', $app_id)->where('enable', 1)->where('sys_group_id', $sysGroupId)
  462. ->update(['enable' => 0]);
  463. }
  464. }
  465. if( isset($conf->id) ){
  466. $conf->user_action_set_id = $user_action_set_id;
  467. $conf->corp_id = $corp_id;
  468. $conf->corp_name = $corp_name;
  469. $conf->channel = $channel;
  470. } else {
  471. $conf = new TencentAdConf();
  472. $conf->account_id = $account->account_id ?? null;
  473. $conf->app_id = $app_id;
  474. $conf->user_action_set_id = $user_action_set_id;
  475. $conf->corp_id = $corp_id;
  476. $conf->corp_name = $corp_name;
  477. $conf->channel = $channel;
  478. }
  479. return $conf->save();
  480. }
  481. public static function getCorpIdList()
  482. {
  483. $list = AuthorizeCorp::select('corpid', 'corp_name')->where('enable', 1)->where('is_customized_app', 1)->get();
  484. return $list;
  485. }
  486. public static function adqAccountList($keyword, $isSelect, $page, $pageSize, $sysGroupId, $adminId, $isSystemAdmin)
  487. {
  488. $isAll = true;
  489. $accountList = [];
  490. if($sysGroupId != $adminId && !$isSystemAdmin) {
  491. # 获取该账号已分配的adq账号
  492. $accountAuthInfo = Users::query()->select('is_all_adq', 'adq_account')
  493. ->where('enable', 1)->where('id', $adminId)->first();
  494. if(empty($accountAuthInfo)) return [];
  495. if(!$accountAuthInfo->is_all_adq) {
  496. $isAll = false;
  497. $accountList = $accountAuthInfo->adq_account ? explode(',', $accountAuthInfo->adq_account) : [];
  498. }
  499. }
  500. $adqAccountQuery = OfficialWebUserActionSetId::query()->where('sys_group_id', $sysGroupId)
  501. ->where(function ($query) use($isAll, $accountList) {
  502. if($isAll === false) {
  503. $query->whereIn('account_id', $accountList);
  504. }
  505. })
  506. ->where('enable', 1);
  507. if (!$isSelect && !empty($keyword)) $adqAccountQuery->where('account_id', 'like', '%'.$keyword.'%');
  508. $total = (clone $adqAccountQuery)->distinct('account_id')->count();
  509. $adqAccountQuery->orderByDesc('create_time');
  510. if (!$isSelect) {
  511. if ($total == 0) return [[], 0];
  512. $adqAccountList = $adqAccountQuery
  513. ->offset(($page - 1) * $pageSize)
  514. ->limit($pageSize)
  515. ->get();
  516. $bindInfoList = DramaUserRela::getAccountDramaCount($adqAccountList->pluck('account_id'), $sysGroupId, 2);
  517. $rules = ReportRules::query()->where('enable', 1)->pluck('name', 'id')->all();
  518. foreach ($adqAccountList as $value) {
  519. $value->drama_count = $bindInfoList->get($value->account_id) ?? 0;
  520. $value->rule_name = $rules[$value->report_type] ?? '';
  521. $value->user_action_set_id = $value->web_user_action_set_id;
  522. $value->amount_setvale = !empty($value->amount_setvale) ? json_decode($value->amount_setvale, 1) : [];
  523. unset($value->web_user_action_set_id);
  524. }
  525. return [$adqAccountList, $total];
  526. } else {
  527. if ($total == 0) return [];
  528. $adqAccountList = $adqAccountQuery->select('account_id')->get();
  529. return $adqAccountList;
  530. }
  531. }
  532. public static function adqPitcherIndex($accountId, $page, $pageSize, $sysGroupId)
  533. {
  534. $tDate = date('Y-m-d');
  535. $fieldList = 'id as rela_id, account_id, drama_id, user_id, start_date, end_date, enable';
  536. $relaList = DramaUserRela::getBindList($accountId, $sysGroupId, $page, $pageSize, $fieldList, 2);
  537. $total = $relaList->count();
  538. if ($relaList->isEmpty()) return [[], 0];
  539. $dramaList = DramaSeries::query()->whereIn('id', $relaList->pluck('drama_id'))->pluck('name', 'id');
  540. $userList = Users::query()->whereIn('id', $relaList->pluck('user_id'))->pluck('name', 'id');
  541. foreach ($relaList as $value) {
  542. $value->is_contain = 0;
  543. if (($tDate >= $value->start_date) && ($tDate <= $value->end_date)) {
  544. $value->is_contain = 1;
  545. }
  546. $value->drama_name = $dramaList->get($value->drama_id) ?? null;
  547. $value->user_name = $userList->get($value->user_id) ?? null;
  548. }
  549. return [$relaList, $total];
  550. }
  551. public static function adqBindPitcher($accountId, $dramaId, $userId, $startDate, $endDate, $sysGroupId)
  552. {
  553. $adqAccountInfo = OfficialWebUserActionSetId::query()
  554. ->where('account_id', $accountId)
  555. ->where('enable', 1)
  556. ->where('sys_group_id', $sysGroupId)
  557. ->first();
  558. if (empty($adqAccountInfo)) return [false, 3107];
  559. $dramaInfo = DramaSeries::query()
  560. ->where('id', $dramaId)
  561. ->where('enable', 1)
  562. ->first();
  563. if (empty($dramaInfo)) return [false, 3102];
  564. $userInfo = Users::query()
  565. ->where('id', $userId)
  566. ->where('enable', 1)
  567. ->first();
  568. if (empty($userInfo)) return [false, 3103];
  569. // 时间校验
  570. $checkRes = self::adqDateCheck($accountId, $startDate, $endDate, $sysGroupId);
  571. if (!$checkRes) return [false, 3105];
  572. $result = [
  573. 'account_id' => $accountId,
  574. 'drama_id' => $dramaId,
  575. 'user_id' => $userId,
  576. 'start_date' => $startDate,
  577. 'end_date' => $endDate,
  578. 'sys_group_id' => $sysGroupId,
  579. 'order_type' => 2,
  580. ];
  581. DataStatisticsService::adqRelaAdd($accountId, $dramaId, $userId, $startDate, $endDate);
  582. try {
  583. DramaUserRela::query()->firstOrCreate($result, $result);
  584. } catch (\Throwable $e) {
  585. Log::logError('数据关系绑定失败', [
  586. 'accountId' => $accountId,
  587. 'dramaId' => $dramaId,
  588. 'userId' => $userId,
  589. 'startDate' => $startDate,
  590. 'endDate' => $endDate
  591. ], 'PitcherService');
  592. return [false, 3106];
  593. }
  594. // 日志记录
  595. Log::logInfo('编辑账号绑定短剧投手', [
  596. 'old' => [],
  597. 'new' => [
  598. 'account_id' => $accountId,
  599. 'drama_id' => $dramaId,
  600. 'user_id' => $userId,
  601. 'start_date' => $startDate,
  602. 'end_date' => $endDate,
  603. 'sys_group_id' => $sysGroupId,
  604. 'order_type' => 2,
  605. ],
  606. 'operate' => 'add',
  607. 'order_type' => 2,
  608. ], 'pitcher_change');
  609. return [true, 0];
  610. }
  611. public static function adqEditPitcher($relaId, $dramaId, $userId, $startDate, $endDate, $enable, $sysGroupId)
  612. {
  613. $relaInfo = DramaUserRela::query()->find($relaId);
  614. if (empty($relaInfo)) return [false, 3104];
  615. $old = $relaInfo->toArray();
  616. // 时间校验
  617. $checkRes = self::adqDateCheck($relaInfo->account_id, $startDate, $endDate, $sysGroupId, $relaId);
  618. if (!$checkRes) return [false, 3105];
  619. try {
  620. $relaInfo->update([
  621. 'drama_id' => $dramaId,
  622. 'user_id' => $userId,
  623. 'start_date' => $startDate,
  624. 'end_date' => $endDate,
  625. 'enable' => $enable
  626. ]);
  627. } catch (\Throwable $e) {
  628. Log::logError('绑定数据编辑失败', [
  629. 'relaId' => $relaId,
  630. 'dramaId' => $dramaId,
  631. 'userId' => $userId,
  632. 'startDate' => $startDate,
  633. 'endDate' => $endDate,
  634. 'enable' => $enable
  635. ], 'PitcherService');
  636. return [false, 3106];
  637. }
  638. // 日志记录
  639. Log::logInfo('编辑账号绑定短剧投手', [
  640. 'old' => $old,
  641. 'new' => [
  642. 'drama_id' => $dramaId,
  643. 'user_id' => $userId,
  644. 'start_date' => $startDate,
  645. 'end_date' => $endDate,
  646. 'enable' => $enable
  647. ],
  648. 'operate' => 'edit',
  649. 'order_type' => 2,
  650. ], 'pitcher_change');
  651. DataStatisticsService::adqRelaEdit($dramaId, $userId, $startDate, $endDate, $enable, $old);
  652. return [true, 0];
  653. }
  654. public static function adqBindUserActionSetId($accountId, $userActionSetId, $corpId, $sysGroupId, $isProvisionalStat)
  655. {
  656. $corpName = null;
  657. if(!empty($corpId)) {
  658. $corpName = AuthorizeCorp::query()
  659. ->where('corpid', $corpId)
  660. ->value('corp_name');
  661. }
  662. $conf = OfficialWebUserActionSetId::query()
  663. ->where('account_id', $accountId)
  664. ->where('sys_group_id', $sysGroupId)
  665. ->first();
  666. \DB::beginTransaction();//开启事务
  667. if( isset($conf->id) ){
  668. $originalWebUserActionSetId = $conf->web_user_action_set_id;
  669. $conf->web_user_action_set_id = $userActionSetId;
  670. $conf->corp_id = $corpId;
  671. $conf->corp_name = $corpName;
  672. $conf->is_provisional_stat = $isProvisionalStat;
  673. if($isProvisionalStat == 0 && $conf->is_provisional_stat != $isProvisionalStat) {
  674. AccountConfigNoUserRelation::where('sys_group_id', $sysGroupId)->where('account_id', $accountId)
  675. ->where('enable', 1)->update(['enable' => 0]);
  676. }
  677. } else {
  678. $originalWebUserActionSetId = null;
  679. $conf = new OfficialWebUserActionSetId();
  680. $conf->account_id = $accountId;
  681. $conf->web_user_action_set_id = $userActionSetId;
  682. $conf->corp_id = $corpId;
  683. $conf->corp_name = $corpName;
  684. $conf->sys_group_id = $sysGroupId;
  685. $conf->is_provisional_stat = $isProvisionalStat;
  686. }
  687. $res1 = $conf->save();
  688. $count = 0;
  689. if(!empty($corpId)) {
  690. $count = AdqUser::query()
  691. ->where('corpid', $corpId)
  692. ->where('account_id', $accountId)
  693. ->count();
  694. }
  695. if($count > 0){
  696. $res2 = AdqUser::query()
  697. ->where('corpid', $corpId)
  698. ->where('account_id', $accountId)
  699. ->update([
  700. 'user_action_set_id' => $userActionSetId,
  701. 'update_time' => date('Y-m-d H:i:s')
  702. ]);
  703. } else {
  704. $res2 = true;
  705. }
  706. if($res1 && $res2) {
  707. \DB::commit();
  708. return true;
  709. } else {
  710. \DB::rollback();//数据库回滚
  711. return false;
  712. }
  713. }
  714. public static function setAdqAccountReportRule($accountIds, $reportType, $reportEnable, $purchaseEnable, $missEnable
  715. , $missSetvale, $sysGroupId, $missValue, $ifAll, $amountEnable, $amountSetvale, $resetEnable, $resetSetvale, $adminId)
  716. {
  717. if ($missEnable == 1 && $missSetvale == 0) return [false, 4408];
  718. // 参数验证
  719. $errcode = 0;
  720. PitcherService::decideAmount($amountEnable, $amountSetvale, $errcode);
  721. if($errcode) return [false, $errcode];
  722. $newConfList = [];
  723. // 按照金额排序
  724. if(1 == $amountEnable){
  725. $stAmountDataList = array_column($amountSetvale, 'start_amount');
  726. array_multisort($stAmountDataList, SORT_ASC, $amountSetvale);
  727. foreach($amountSetvale as $val) {
  728. if(3 == $val['type']) {
  729. $hourSetVale = $val['hour_setvale'];
  730. $stTimeDataList = array_column($hourSetVale, 'start_time');
  731. array_multisort($stTimeDataList, SORT_ASC, $hourSetVale);
  732. foreach($hourSetVale as $v) {
  733. $newConfList[] = $val['start_amount'].'-'.$val['end_amount'].'-'.$v['start_time'].'-'.$v['end_time'];
  734. }
  735. } else {
  736. $newConfList[] = $val['start_amount'].'-'.$val['end_amount'];
  737. }
  738. }
  739. }
  740. $data = [
  741. 'report_type' => $reportType,
  742. 'report_enable' => $reportEnable,
  743. 'purchase_enable' => $purchaseEnable,
  744. 'miss_enable' => $missEnable,
  745. 'miss_setvale' => $missSetvale,
  746. 'miss_value' => $missValue,
  747. 'enable' => 1,
  748. 'amount_enable' => $amountEnable,
  749. 'amount_setvale' => json_encode($amountSetvale, 256),
  750. 'reset_enable' => $resetEnable,
  751. 'reset_setvale' => $resetSetvale
  752. ];
  753. //配置所有为一种规则
  754. if($ifAll == 1){
  755. $accountIds = OfficialWebUserActionSetId::query()
  756. ->select('account_id')
  757. ->where('sys_group_id', $sysGroupId)
  758. ->distinct()
  759. ->pluck('account_id')
  760. ->all();
  761. }
  762. foreach($accountIds as $accountId){
  763. $rulesRes = OfficialWebUserActionSetId::query()
  764. ->updateOrCreate([
  765. 'account_id' => $accountId
  766. ], $data);
  767. // 写入缓存
  768. RedisModel::hSet(OfficialWebUserActionSetId::OFFICIAL_ADQ_ACCOUNT_REPORT_RULES_CONF,
  769. $accountId.'-'.$sysGroupId, json_encode([
  770. 'report_enable' => $rulesRes->report_enable,
  771. 'report_type' => $rulesRes->report_type,
  772. 'purchase_enable' => $rulesRes->purchase_enable,
  773. 'miss_enable' => $rulesRes->miss_enable,
  774. 'miss_setvale' => $rulesRes->miss_setvale,
  775. 'enable' => $rulesRes->enable,
  776. 'account_id' => $accountId,
  777. 'miss_value' => $missValue,
  778. 'amount_enable' => $amountEnable,
  779. 'amount_setvale' => json_encode($amountSetvale, 256)
  780. ]));
  781. // 操作记录
  782. OperateLog::saveData(3, json_encode(array_merge($data, ['account_id' => $accountId]), 256), $adminId);
  783. // 判断漏单是否关闭,若关闭,则将漏单计数清零
  784. if(0 == $missEnable) {
  785. RedisModel::hDel(OfficialWebUserActionSetId::OFFICIAL_ADQ_ACCOUNT_REPORT_MISS_INCR_NUM,
  786. $accountId.'-'.$sysGroupId);
  787. }
  788. // 获取账号下所有键
  789. $configList = RedisModel::hGetAll(OfficialWebUserActionSetId::ADQ_ACCOUNT_REPORT_MISS_INCR_NUM.'-'.$accountId
  790. .'-'.$sysGroupId);
  791. if(!empty($configList)) {
  792. // 将本次修改后失效的配置删除
  793. foreach($configList as $key=>$val) {
  794. if(!in_array($key, $newConfList)){
  795. RedisModel::hDel(OfficialWebUserActionSetId::ADQ_ACCOUNT_REPORT_MISS_INCR_NUM.'-'.$accountId
  796. .'-'.$sysGroupId, $key);
  797. }
  798. }
  799. }
  800. }
  801. return [true, 0];
  802. }
  803. public static function decideAmount($amountEnable, $amountSetvale, &$errcode)
  804. {
  805. # 已经开启回传金额设置,但是实际设置内容为空
  806. if(1 == $amountEnable && empty($amountSetvale)) {
  807. $errcode = 4409;
  808. return ;
  809. }
  810. # 验证字段是否缺失以及金额范围存在交叉部分
  811. $stAmountDataList = array_column($amountSetvale, 'start_amount');
  812. array_multisort($stAmountDataList, SORT_ASC, $amountSetvale);
  813. foreach ($amountSetvale as $k => $v){
  814. if(!isset($v['start_amount']) || !isset($v['end_amount']) || !isset($v['type']) || !isset($v['hour_setvale'])
  815. || $v['start_amount'] < 0 || $v['end_amount'] <= 0 || !in_array($v['type'], [1, 2,3]) || (3 == $v['type'] && empty($v['hour_setvale']))){
  816. $errcode = 4410; // 填写参数有误
  817. return ;
  818. }
  819. if ($v['start_amount'] >= $v['end_amount']) {
  820. $errcode = 4411; // 最小金额要需小于最高金额
  821. return ;
  822. }
  823. if ($k > 0 && ($amountSetvale[$k]['start_amount'] < $amountSetvale[$k-1]['end_amount'])) {
  824. $errcode = 4412; // 多项配置之间金额范围存在交叉
  825. return ;
  826. }
  827. if(3 == $v['type']) {
  828. foreach($v['hour_setvale'] as $kk => $vv) {
  829. if(!isset($vv['start_time']) || !isset($vv['end_time']) || !isset($vv['miss_setvale']) || !isset($vv['miss_value'])
  830. || !isset($vv['return_type']) ||
  831. ($vv['return_type'] == 3 && ($vv['miss_setvale'] <= 0 || $vv['miss_value'] <= 0))) {
  832. $errcode = 4410;// 填写参数有误
  833. return ;
  834. }
  835. if($vv['start_time'] >= $vv['end_time']) {
  836. $errcode = 4413; // 起始时间需小于截止时间
  837. }
  838. if ($kk > 0 && ($v['hour_setvale'][$kk]['start_time'] < $v['hour_setvale'][$kk - 1]['end_time'])) {
  839. $errcode = 4414;// 多项配置之间时间范围存在交叉
  840. return ;
  841. }
  842. if ($kk > 0 && (date('H:i', strtotime($v['hour_setvale'][$kk]['start_time'] . ' -1 minutes'))
  843. != $v['hour_setvale'][$kk - 1]['end_time']) ) {
  844. $errcode = 4415;
  845. return ;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. # adq账号绑定客服
  852. public static function adqAccountBindUserAction($accountId, $userList, $confirm, $sysGroupId) {
  853. try {
  854. Log::logInfo('投放账号绑定客服配置记录',[
  855. 'account_id' => $accountId, 'user_list' => $userList, 'confirm' => $confirm, 'sys_group_id' => $sysGroupId
  856. ], 'adqAccountBindUserConfig');
  857. # 直接清空所有绑定关系
  858. if(empty($userList)) {
  859. AdqUser::query()->where('account_id', $accountId)->update(['account_id' => null, 'user_action_set_id' => null]);
  860. return ['', 0];
  861. }
  862. # 查询所选择客服是否已经绑定过其他投放账号
  863. $userSqlArr = [];
  864. foreach ($userList as $userInfo) {
  865. $corpid = $userInfo['corpid'];
  866. $users = $userInfo['user_list'];
  867. foreach ($users as $userId) {
  868. $userSqlArr[] = '("' . $corpid . '","' . $userId . '")';
  869. }
  870. }
  871. if (0 == $confirm) {
  872. $adqUserConf = AdqUser::search([
  873. 'user_sql' => $userSqlArr,
  874. 'not_exist_account_list' => [$accountId],
  875. 'account_exist' => 1
  876. ]);
  877. if ($adqUserConf->isNotEmpty()) {
  878. # 查询已经绑定过其他投放账号的企微以及客服信息
  879. $corpidList = array_column($userList, 'corpid');
  880. $corpDataList = AuthorizeCorp::getAllCorpList($corpidList);
  881. $userList = DjUser::getUserBySearch([
  882. 'user_sql' => $userSqlArr
  883. ]);
  884. $existUser = [];
  885. foreach ($adqUserConf as $conf) {
  886. $corpData = $corpDataList->where('corpid', $conf->corpid)->first();
  887. $corpName = $corpData->corp_name ?? '';
  888. $userData = $userList->where('corpid', $conf->corpid)->where('user_id', $conf->user_id)->first();
  889. $userName = $userData->name ?? '';
  890. $existUser[] = [
  891. 'corp_id' => $conf->corpid,
  892. 'corp_name' => $corpName,
  893. 'user_id' => $conf->user_id,
  894. 'user_name' => $userName
  895. ];
  896. }
  897. return [$existUser, 4905];
  898. }
  899. }
  900. # 写入数据
  901. $alreadyExistAdqUserConf = AdqUser::search([
  902. 'user_sql' => $userSqlArr,
  903. ]);
  904. $existIdList = array_column($alreadyExistAdqUserConf->toArray(), 'id');
  905. # 查询投放账号对应的数据源ID
  906. $userActionSetId = OfficialWebUserActionSetId::getAccountBindUserActionSetId($sysGroupId, $accountId);
  907. $insertData = [];
  908. foreach ($userList as $userInfo) {
  909. $corpid = $userInfo['corpid'];
  910. $users = $userInfo['user_list'];
  911. foreach ($users as $userId) {
  912. $existRow = $alreadyExistAdqUserConf->where('corpid', $corpid)->where('user_id', $userId)->first();
  913. if (empty($existRow)) {
  914. $insertData[] = [
  915. 'corpid' => $corpid,
  916. 'user_id' => $userId,
  917. 'account_id' => $accountId,
  918. 'user_action_set_id' => $userActionSetId
  919. ];
  920. }
  921. }
  922. }
  923. \DB::begintransaction();
  924. AdqUser::query()->where('account_id', $accountId)->update(['account_id' => null, 'user_action_set_id' => null]);
  925. if (!empty($existIdList)) {
  926. # 全部都需要新增
  927. AdqUser::query()->whereIn('id', $existIdList)->update(['account_id' => $accountId, 'user_action_set_id' => $userActionSetId]);
  928. }
  929. if (!empty($insertData)) {
  930. AdqUser::query()->insert($insertData);
  931. }
  932. \DB::commit();
  933. return ['', 0];
  934. } catch (\Exception $e) {
  935. Log::logError('投放账号绑定客服异常', [
  936. 'file' => $e->getFile(),
  937. 'line' => $e->getLine(),
  938. 'message'=> $e->getMessage(),
  939. 'trace' => $e->getTraceAsString()
  940. ], 'adqAccountBindUserError');
  941. EmailQueue::rPush('投放账号绑定客服异常', 'file:' . $e->getFile() . '; line:' . $e->getLine()
  942. . '; message:' . $e->getMessage(), ['song.shen@kuxuan-inc.com'], '猎羽');
  943. \DB::rollBack();
  944. return ['系统异常', 500];
  945. }
  946. }
  947. public static function adqAccountBindUserList($accountId) {
  948. $adqUserConf = AdqUser::search([
  949. 'account_id' => $accountId
  950. ]);
  951. if($adqUserConf->isNotEmpty()) {
  952. $userSqlArr = [];
  953. $corpidArr = [];
  954. $appIdArr = [];
  955. foreach($adqUserConf as $conf) {
  956. $corpid = $conf->corpid;
  957. $userId = $conf->user_id;
  958. $userSqlArr[] = '("' . $corpid . '","' . $userId . '")';
  959. $corpidArr[] = $corpid;
  960. $appIdArr[] = $conf->app_id;
  961. }
  962. $corpDataList = AuthorizeCorp::getAllCorpList($corpidArr);
  963. $userList = DjUser::getUserBySearch([
  964. 'user_sql' => $userSqlArr
  965. ]);
  966. $appIdArr = array_unique(array_filter($appIdArr));
  967. if(!empty($appIdArr)) {
  968. $appData = OfficialAccount::getAppInfoList($appIdArr);
  969. } else {
  970. $appData = [];
  971. }
  972. $existUser = [];
  973. foreach($adqUserConf as $conf) {
  974. $corpData = $corpDataList->where('corpid', $conf->corpid)->first();
  975. $corpName = $corpData->corp_name ?? '';
  976. $userData = $userList->where('corpid', $conf->corpid)->where('user_id', $conf->user_id)->first();
  977. $userName = $userData->name ?? '';
  978. if(empty($conf->app_id)) {
  979. $appName = null;
  980. } else {
  981. $appName = $appData[$conf->app_id] ?? null;
  982. }
  983. $existUser[] = [
  984. 'data_id' => $conf->id,
  985. 'corp_id' => $conf->corpid,
  986. 'corp_name' => $corpName,
  987. 'user_id' => $conf->user_id,
  988. 'user_name' => $userName,
  989. 'app_id' => $conf->app_id,
  990. 'app_name' => $appName,
  991. ];
  992. }
  993. return $existUser;
  994. } else {
  995. return [];
  996. }
  997. }
  998. public static function adqAccountBindUserDelete($dataId) {
  999. return AdqUser::query()->where('id', $dataId)->update(['account_id' => null, 'user_action_set_id' => null]);
  1000. }
  1001. public static function adqAccountBindAppId($dataIdList, $appId, &$errcode)
  1002. {
  1003. if(empty($appId)) {
  1004. $appId = null;
  1005. }
  1006. # 验证APP_id
  1007. if ( !empty($appId) ) {
  1008. $exist = OfficialAccount::query()->where('mp_app_id', $appId)->where('enable', 1)->first();
  1009. if(empty($exist)) {
  1010. $errcode = 3101;
  1011. return ;
  1012. }
  1013. }
  1014. $res = AdqUser::query()->whereIn('id', $dataIdList)->update([
  1015. 'app_id' => $appId,
  1016. 'update_time' => date('Y-m-d H:i:s')
  1017. ]);
  1018. if(!$res) {
  1019. $errcode = 500;
  1020. }
  1021. return ;
  1022. }
  1023. }