企微短剧业务系统

PitcherService.php 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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 = AuthorizeCorp::query()
  657. ->where('corpid', $corpId)
  658. ->value('corp_name');
  659. $conf = OfficialWebUserActionSetId::query()
  660. ->where('account_id', $accountId)
  661. ->where('sys_group_id', $sysGroupId)
  662. ->first();
  663. \DB::beginTransaction();//开启事务
  664. if( isset($conf->id) ){
  665. $originalWebUserActionSetId = $conf->web_user_action_set_id;
  666. $conf->web_user_action_set_id = $userActionSetId;
  667. $conf->corp_id = $corpId;
  668. $conf->corp_name = $corpName;
  669. $conf->is_provisional_stat = $isProvisionalStat;
  670. if($isProvisionalStat == 0 && $conf->is_provisional_stat != $isProvisionalStat) {
  671. AccountConfigNoUserRelation::where('sys_group_id', $sysGroupId)->where('account_id', $accountId)
  672. ->where('enable', 1)->update(['enable' => 0]);
  673. }
  674. } else {
  675. $originalWebUserActionSetId = null;
  676. $conf = new OfficialWebUserActionSetId();
  677. $conf->account_id = $accountId;
  678. $conf->web_user_action_set_id = $userActionSetId;
  679. $conf->corp_id = $corpId;
  680. $conf->corp_name = $corpName;
  681. $conf->sys_group_id = $sysGroupId;
  682. $conf->is_provisional_stat = $isProvisionalStat;
  683. }
  684. $res1 = $conf->save();
  685. $count = AdqUser::query()
  686. ->where('corpid', $corpId)
  687. ->where('account_id', $accountId)
  688. ->count();
  689. if($count > 0){
  690. $res2 = AdqUser::query()
  691. ->where('corpid', $corpId)
  692. ->where('account_id', $accountId)
  693. ->update([
  694. 'user_action_set_id' => $userActionSetId,
  695. 'update_time' => date('Y-m-d H:i:s')
  696. ]);
  697. } else {
  698. $res2 = true;
  699. }
  700. if($res1 && $res2) {
  701. \DB::commit();
  702. return true;
  703. } else {
  704. \DB::rollback();//数据库回滚
  705. return false;
  706. }
  707. }
  708. public static function setAdqAccountReportRule($accountIds, $reportType, $reportEnable, $purchaseEnable, $missEnable
  709. , $missSetvale, $sysGroupId, $missValue, $ifAll, $amountEnable, $amountSetvale, $resetEnable, $resetSetvale, $adminId)
  710. {
  711. if ($missEnable == 1 && $missSetvale == 0) return [false, 4408];
  712. // 参数验证
  713. $errcode = 0;
  714. PitcherService::decideAmount($amountEnable, $amountSetvale, $errcode);
  715. if($errcode) return [false, $errcode];
  716. $newConfList = [];
  717. // 按照金额排序
  718. if(1 == $amountEnable){
  719. $stAmountDataList = array_column($amountSetvale, 'start_amount');
  720. array_multisort($stAmountDataList, SORT_ASC, $amountSetvale);
  721. foreach($amountSetvale as $val) {
  722. if(3 == $val['type']) {
  723. $hourSetVale = $val['hour_setvale'];
  724. $stTimeDataList = array_column($hourSetVale, 'start_time');
  725. array_multisort($stTimeDataList, SORT_ASC, $hourSetVale);
  726. foreach($hourSetVale as $v) {
  727. $newConfList[] = $val['start_amount'].'-'.$val['end_amount'].'-'.$v['start_time'].'-'.$v['end_time'];
  728. }
  729. } else {
  730. $newConfList[] = $val['start_amount'].'-'.$val['end_amount'];
  731. }
  732. }
  733. }
  734. $data = [
  735. 'report_type' => $reportType,
  736. 'report_enable' => $reportEnable,
  737. 'purchase_enable' => $purchaseEnable,
  738. 'miss_enable' => $missEnable,
  739. 'miss_setvale' => $missSetvale,
  740. 'miss_value' => $missValue,
  741. 'enable' => 1,
  742. 'amount_enable' => $amountEnable,
  743. 'amount_setvale' => json_encode($amountSetvale, 256),
  744. 'reset_enable' => $resetEnable,
  745. 'reset_setvale' => $resetSetvale
  746. ];
  747. //配置所有为一种规则
  748. if($ifAll == 1){
  749. $accountIds = OfficialWebUserActionSetId::query()
  750. ->select('account_id')
  751. ->where('sys_group_id', $sysGroupId)
  752. ->distinct()
  753. ->pluck('account_id')
  754. ->all();
  755. }
  756. foreach($accountIds as $accountId){
  757. $rulesRes = OfficialWebUserActionSetId::query()
  758. ->updateOrCreate([
  759. 'account_id' => $accountId
  760. ], $data);
  761. // 写入缓存
  762. RedisModel::hSet(OfficialWebUserActionSetId::OFFICIAL_ADQ_ACCOUNT_REPORT_RULES_CONF,
  763. $accountId.'-'.$sysGroupId, json_encode([
  764. 'report_enable' => $rulesRes->report_enable,
  765. 'report_type' => $rulesRes->report_type,
  766. 'purchase_enable' => $rulesRes->purchase_enable,
  767. 'miss_enable' => $rulesRes->miss_enable,
  768. 'miss_setvale' => $rulesRes->miss_setvale,
  769. 'enable' => $rulesRes->enable,
  770. 'account_id' => $accountId,
  771. 'miss_value' => $missValue,
  772. 'amount_enable' => $amountEnable,
  773. 'amount_setvale' => json_encode($amountSetvale, 256)
  774. ]));
  775. // 操作记录
  776. OperateLog::saveData(3, json_encode(array_merge($data, ['account_id' => $accountId]), 256), $adminId);
  777. // 判断漏单是否关闭,若关闭,则将漏单计数清零
  778. if(0 == $missEnable) {
  779. RedisModel::hDel(OfficialWebUserActionSetId::OFFICIAL_ADQ_ACCOUNT_REPORT_MISS_INCR_NUM,
  780. $accountId.'-'.$sysGroupId);
  781. }
  782. // 获取账号下所有键
  783. $configList = RedisModel::hGetAll(OfficialWebUserActionSetId::ADQ_ACCOUNT_REPORT_MISS_INCR_NUM.'-'.$accountId
  784. .'-'.$sysGroupId);
  785. if(!empty($configList)) {
  786. // 将本次修改后失效的配置删除
  787. foreach($configList as $key=>$val) {
  788. if(!in_array($key, $newConfList)){
  789. RedisModel::hDel(OfficialWebUserActionSetId::ADQ_ACCOUNT_REPORT_MISS_INCR_NUM.'-'.$accountId
  790. .'-'.$sysGroupId, $key);
  791. }
  792. }
  793. }
  794. }
  795. return [true, 0];
  796. }
  797. public static function decideAmount($amountEnable, $amountSetvale, &$errcode)
  798. {
  799. # 已经开启回传金额设置,但是实际设置内容为空
  800. if(1 == $amountEnable && empty($amountSetvale)) {
  801. $errcode = 4409;
  802. return ;
  803. }
  804. # 验证字段是否缺失以及金额范围存在交叉部分
  805. $stAmountDataList = array_column($amountSetvale, 'start_amount');
  806. array_multisort($stAmountDataList, SORT_ASC, $amountSetvale);
  807. foreach ($amountSetvale as $k => $v){
  808. if(!isset($v['start_amount']) || !isset($v['end_amount']) || !isset($v['type']) || !isset($v['hour_setvale'])
  809. || $v['start_amount'] < 0 || $v['end_amount'] <= 0 || !in_array($v['type'], [1, 2,3]) || (3 == $v['type'] && empty($v['hour_setvale']))){
  810. $errcode = 4410; // 填写参数有误
  811. return ;
  812. }
  813. if ($v['start_amount'] >= $v['end_amount']) {
  814. $errcode = 4411; // 最小金额要需小于最高金额
  815. return ;
  816. }
  817. if ($k > 0 && ($amountSetvale[$k]['start_amount'] < $amountSetvale[$k-1]['end_amount'])) {
  818. $errcode = 4412; // 多项配置之间金额范围存在交叉
  819. return ;
  820. }
  821. if(3 == $v['type']) {
  822. foreach($v['hour_setvale'] as $kk => $vv) {
  823. if(!isset($vv['start_time']) || !isset($vv['end_time']) || !isset($vv['miss_setvale']) || !isset($vv['miss_value'])
  824. || !isset($vv['return_type']) ||
  825. ($vv['return_type'] == 3 && ($vv['miss_setvale'] <= 0 || $vv['miss_value'] <= 0))) {
  826. $errcode = 4410;// 填写参数有误
  827. return ;
  828. }
  829. if($vv['start_time'] >= $vv['end_time']) {
  830. $errcode = 4413; // 起始时间需小于截止时间
  831. }
  832. if ($kk > 0 && ($v['hour_setvale'][$kk]['start_time'] < $v['hour_setvale'][$kk - 1]['end_time'])) {
  833. $errcode = 4414;// 多项配置之间时间范围存在交叉
  834. return ;
  835. }
  836. if ($kk > 0 && (date('H:i', strtotime($v['hour_setvale'][$kk]['start_time'] . ' -1 minutes'))
  837. != $v['hour_setvale'][$kk - 1]['end_time']) ) {
  838. $errcode = 4415;
  839. return ;
  840. }
  841. }
  842. }
  843. }
  844. }
  845. # adq账号绑定客服
  846. public static function adqAccountBindUserAction($accountId, $userList, $confirm, $sysGroupId) {
  847. try {
  848. Log::logInfo('投放账号绑定客服配置记录',[
  849. 'account_id' => $accountId, 'user_list' => $userList, 'confirm' => $confirm, 'sys_group_id' => $sysGroupId
  850. ], 'adqAccountBindUserConfig');
  851. # 直接清空所有绑定关系
  852. if(empty($userList)) {
  853. AdqUser::query()->where('account_id', $accountId)->update(['account_id' => null, 'user_action_set_id' => null]);
  854. return ['', 0];
  855. }
  856. # 查询所选择客服是否已经绑定过其他投放账号
  857. $userSqlArr = [];
  858. foreach ($userList as $userInfo) {
  859. $corpid = $userInfo['corpid'];
  860. $users = $userInfo['user_list'];
  861. foreach ($users as $userId) {
  862. $userSqlArr[] = '("' . $corpid . '","' . $userId . '")';
  863. }
  864. }
  865. if (0 == $confirm) {
  866. $adqUserConf = AdqUser::search([
  867. 'user_sql' => $userSqlArr,
  868. 'not_exist_account_list' => [$accountId],
  869. 'account_exist' => 1
  870. ]);
  871. if ($adqUserConf->isNotEmpty()) {
  872. # 查询已经绑定过其他投放账号的企微以及客服信息
  873. $corpidList = array_column($userList, 'corpid');
  874. $corpDataList = AuthorizeCorp::getAllCorpList($corpidList);
  875. $userList = DjUser::getUserBySearch([
  876. 'user_sql' => $userSqlArr
  877. ]);
  878. $existUser = [];
  879. foreach ($adqUserConf as $conf) {
  880. $corpData = $corpDataList->where('corpid', $conf->corpid)->first();
  881. $corpName = $corpData->corp_name ?? '';
  882. $userData = $userList->where('corpid', $conf->corpid)->where('user_id', $conf->user_id)->first();
  883. $userName = $userData->name ?? '';
  884. $existUser[] = [
  885. 'corp_id' => $conf->corpid,
  886. 'corp_name' => $corpName,
  887. 'user_id' => $conf->user_id,
  888. 'user_name' => $userName
  889. ];
  890. }
  891. return [$existUser, 4905];
  892. }
  893. }
  894. # 写入数据
  895. $alreadyExistAdqUserConf = AdqUser::search([
  896. 'user_sql' => $userSqlArr,
  897. ]);
  898. $existIdList = array_column($alreadyExistAdqUserConf->toArray(), 'id');
  899. # 查询投放账号对应的数据源ID
  900. $userActionSetId = OfficialWebUserActionSetId::getAccountBindUserActionSetId($sysGroupId, $accountId);
  901. $insertData = [];
  902. foreach ($userList as $userInfo) {
  903. $corpid = $userInfo['corpid'];
  904. $users = $userInfo['user_list'];
  905. foreach ($users as $userId) {
  906. $existRow = $alreadyExistAdqUserConf->where('corpid', $corpid)->where('user_id', $userId)->first();
  907. if (empty($existRow)) {
  908. $insertData[] = [
  909. 'corpid' => $corpid,
  910. 'user_id' => $userId,
  911. 'account_id' => $accountId,
  912. 'user_action_set_id' => $userActionSetId
  913. ];
  914. }
  915. }
  916. }
  917. \DB::begintransaction();
  918. AdqUser::query()->where('account_id', $accountId)->update(['account_id' => null, 'user_action_set_id' => null]);
  919. if (!empty($existIdList)) {
  920. # 全部都需要新增
  921. AdqUser::query()->whereIn('id', $existIdList)->update(['account_id' => $accountId, 'user_action_set_id' => $userActionSetId]);
  922. }
  923. if (!empty($insertData)) {
  924. AdqUser::query()->insert($insertData);
  925. }
  926. \DB::commit();
  927. return ['', 0];
  928. } catch (\Exception $e) {
  929. Log::logError('投放账号绑定客服异常', [
  930. 'file' => $e->getFile(),
  931. 'line' => $e->getLine(),
  932. 'message'=> $e->getMessage(),
  933. 'trace' => $e->getTraceAsString()
  934. ], 'adqAccountBindUserError');
  935. EmailQueue::rPush('投放账号绑定客服异常', 'file:' . $e->getFile() . '; line:' . $e->getLine()
  936. . '; message:' . $e->getMessage(), ['song.shen@kuxuan-inc.com'], '猎羽');
  937. \DB::rollBack();
  938. return ['系统异常', 500];
  939. }
  940. }
  941. public static function adqAccountBindUserList($accountId) {
  942. $adqUserConf = AdqUser::search([
  943. 'account_id' => $accountId
  944. ]);
  945. if($adqUserConf->isNotEmpty()) {
  946. $userSqlArr = [];
  947. $corpidArr = [];
  948. $appIdArr = [];
  949. foreach($adqUserConf as $conf) {
  950. $corpid = $conf->corpid;
  951. $userId = $conf->user_id;
  952. $userSqlArr[] = '("' . $corpid . '","' . $userId . '")';
  953. $corpidArr[] = $corpid;
  954. $appIdArr[] = $conf->app_id;
  955. }
  956. $corpDataList = AuthorizeCorp::getAllCorpList($corpidArr);
  957. $userList = DjUser::getUserBySearch([
  958. 'user_sql' => $userSqlArr
  959. ]);
  960. $appIdArr = array_unique(array_filter($appIdArr));
  961. if(!empty($appIdArr)) {
  962. $appData = OfficialAccount::getAppInfoList($appIdArr);
  963. } else {
  964. $appData = [];
  965. }
  966. $existUser = [];
  967. foreach($adqUserConf as $conf) {
  968. $corpData = $corpDataList->where('corpid', $conf->corpid)->first();
  969. $corpName = $corpData->corp_name ?? '';
  970. $userData = $userList->where('corpid', $conf->corpid)->where('user_id', $conf->user_id)->first();
  971. $userName = $userData->name ?? '';
  972. if(empty($conf->app_id)) {
  973. $appName = null;
  974. } else {
  975. $appName = $appData[$conf->app_id] ?? null;
  976. }
  977. $existUser[] = [
  978. 'data_id' => $conf->id,
  979. 'corp_id' => $conf->corpid,
  980. 'corp_name' => $corpName,
  981. 'user_id' => $conf->user_id,
  982. 'user_name' => $userName,
  983. 'app_id' => $conf->app_id,
  984. 'app_name' => $appName,
  985. ];
  986. }
  987. return $existUser;
  988. } else {
  989. return [];
  990. }
  991. }
  992. public static function adqAccountBindUserDelete($dataId) {
  993. return AdqUser::query()->where('id', $dataId)->update(['account_id' => null, 'user_action_set_id' => null]);
  994. }
  995. public static function adqAccountBindAppId($dataIdList, $appId, &$errcode)
  996. {
  997. if(empty($appId)) {
  998. $appId = null;
  999. }
  1000. # 验证APP_id
  1001. if ( !empty($appId) ) {
  1002. $exist = OfficialAccount::query()->where('mp_app_id', $appId)->where('enable', 1)->first();
  1003. if(empty($exist)) {
  1004. $errcode = 3101;
  1005. return ;
  1006. }
  1007. }
  1008. $res = AdqUser::query()->whereIn('id', $dataIdList)->update([
  1009. 'app_id' => $appId,
  1010. 'update_time' => date('Y-m-d H:i:s')
  1011. ]);
  1012. if(!$res) {
  1013. $errcode = 500;
  1014. }
  1015. return ;
  1016. }
  1017. }