where('enable', 1)->where('is_provisional_stat', 1) ->whereIn('wechat_account_id', $mpAppIdList); if (!$isSelect && !empty($keyword)) $wxAccountQuery->where('account_name', 'like', '%'.$keyword.'%'); $total = (clone $wxAccountQuery)->distinct('wechat_account_id')->count(); $wxAccountQuery->groupBy(['wechat_account_id'])->orderByDesc('created_at'); if (!$isSelect) { if ($total == 0) return [[], 0]; $wxAccountList = $wxAccountQuery ->offset(($page - 1) * $pageSize) ->limit($pageSize) ->get(); $appIds = $wxAccountList->pluck('wechat_account_id'); # 获取绑定的adq账号 $adqAccountIds = AccountConfigNoUserRelation::whereIn('app_id', $appIds)->where('sys_group_id', $sysGroupId) ->where('enable', 1)->get(); foreach ($wxAccountList as $value) { $accountIdInfo = $adqAccountIds->where('app_id', $value->wechat_account_id)->pluck('account_id')->toArray(); $value->account_id = $accountIdInfo ? implode(',', $accountIdInfo): ''; } return [$wxAccountList, $total]; } else { if ($total == 0) return []; $wxAccountList = $wxAccountQuery->get(); return $wxAccountList; } } public static function adqAccountList($keyword, $isSelect, $page, $pageSize, $sysGroupId) { $adqAccountQuery = OfficialWebUserActionSetId::where('sys_group_id', $sysGroupId) ->where('enable', 1)->where('is_provisional_stat', 1); if (!$isSelect && !empty($keyword)) $adqAccountQuery->where('account_id', 'like', '%'.$keyword.'%'); $total = (clone $adqAccountQuery)->distinct('account_id')->count(); $adqAccountQuery->orderByDesc('create_time'); if (!$isSelect) { if ($total == 0) return [[], 0]; $adqAccountList = $adqAccountQuery ->offset(($page - 1) * $pageSize) ->limit($pageSize) ->get(); # 获取绑定的公众账号信息 $adqAccountIds = $adqAccountList->pluck('account_id')->unique(); $bindAccountList = AccountConfigNoUserRelation::where('sys_group_id', $sysGroupId)->where('enable', 1) ->whereIn('account_id', $adqAccountIds) ->get(); $mpAccountIds = $bindAccountList->pluck('app_id')->unique(); $mpAccountData = TencentAdAuth::select(['wechat_account_id', 'account_name'])->where('enable', 1) ->whereIn('wechat_account_id', $mpAccountIds)->get(); foreach ($adqAccountList as $value) { # 关联账号名称 $mpAccountIdList = $bindAccountList->where('account_id', $value->account_id)->pluck('app_id'); $mpAccountName = $mpAccountData->whereIn('wechat_account_id', $mpAccountIdList)->pluck('account_name')->toArray(); $value->bind_account_list = empty($mpAccountName) ? '' : implode(',', $mpAccountName); $value->user_action_set_id = $value->web_user_action_set_id; unset($value->web_user_action_set_id); } return [$adqAccountList, $total]; } else { if ($total == 0) return []; $adqAccountList = $adqAccountQuery->select('account_id')->get(); return $adqAccountList; } } /** * 公众号账号绑定adq * */ public static function bindAccount($sysGroupId, $appId, $accountIds, $adType) { try { $accountIds = explode(',', $accountIds); DB::beginTransaction(); AccountConfigNoUserRelation::where('app_id', $appId)->where('sys_group_id', $sysGroupId)->update(['enable'=> 0]); if(empty($accountIds)) { DB::commit(); return 0; } foreach ($accountIds as $accountId) { AccountConfigNoUserRelation::updateOrCreate(['app_id' => $appId, 'sys_group_id' => $sysGroupId, 'account_id' => $accountId], [ 'enable' => 1, 'ad_type' => $adType ]); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); Log::logError('账号绑定过程发生异常', [ 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'sys_group_id' => $sysGroupId, 'appid' => $appId, 'account_id' => $accountIds ], 'ProvisionalBindAccount-Exception'); return 5104; } return 0; } }