123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Service;
- use App\Models\AdqAccountBindPidConf;
- use App\Models\AdqUser;
- class AccountConfService
- {
- public static function bindPid($sysGroupId, $accountId, $pid, $note, $isConfirm) {
- # 检测pid 是否已绑定其他投放账号
- $bindAccountIds = self::getAccountIdByPid($sysGroupId, $pid, null, $accountId);
- \DB::begintransaction();
- if(!empty($bindAccountIds)) {
- if(0 == $isConfirm) {
- return ['已经绑定其他投放账号', 4906];
- } else {
- # 将其他已绑定账号解除绑定
- $updateData = ['enable' => 0, 'update_time' => date('Y-m-d H:i:s')];
- $query = "`enable` = 1 and `sys_group_id` = " . $sysGroupId . " and `pid` = '" . $pid . "' and `account_id` in ('"
- . implode("','", $bindAccountIds) . "')";
- $updateRes = AdqAccountBindPidConf::updateDataByQuery($query, $updateData);
- if(!$updateRes) {
- \DB::rollBack();
- return ['程序异常', 500];
- }
- }
- }
- $res = AdqAccountBindPidConf::saveData($sysGroupId, $accountId, $pid, $note);
- if(!$res) {
- \DB::rollBack();
- return ['程序异常', 500];
- }
- \DB::commit();
- return ['成功', 0];
- }
- public static function bindPidList($sysGroupId, $accountId, $note, $page, $pageSize) {
- $query = AdqAccountBindPidConf::getBinPidListQuery($sysGroupId, $accountId, $note);
- $countQuery = clone $query;
- $count = $countQuery->count();
- $list = $query->orderBy('id', 'desc')->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
- return [$list, $count];
- }
- public static function editStatus($id, $status) {
- $updateData = ['status' => $status, 'update_time' => date('Y-m-d H:i:s')];
- $res = AdqAccountBindPidConf::updateDataById($id, $updateData);
- if(!$res) {
- return ['程序异常', 500];
- }
- return ['成功', 0];
- }
- public static function getAccountIdByPid($sysGroupId, $pid, $status = null, $debarAccountId = null) {
- $params['sys_group_id'] = $sysGroupId;
- $params['pid'] = $pid;
- if(!is_null($status)) $params['status'] = $status;
- if(!empty($debarAccountId)) $params['debar_account_id'] = $debarAccountId;
- $confDataList = AdqAccountBindPidConf::search($params);
- if($confDataList->isEmpty()) {
- return null;
- }
- $confDataList = $confDataList->toArray();
- return array_column($confDataList, 'account_id');
- }
- public static function checkBindType($sysGroupId, $accountId, $type) {
- $data = [];
- if(1 == $type) {
- // 企微投放,检测之前是否有开启状态的推广计划绑定关系
- $params = ['sys_group_id' => $sysGroupId, 'status' => 1, 'account_id' => $accountId];
- $result = AdqAccountBindPidConf::search($params);
- $count = $result->count();
- $bindStatus = $count > 0;
- $data = [
- 'bind_status' => $bindStatus,
- 'msg' => $bindStatus ? '已绑定推广计划,请将已绑定计划的状态全部关闭后再执行本操作' : '',
- ];
- } else if(2 == $type) {
- // 直接投放,检测之前是否有未删除的企微客服绑定关系
- $params = ['account_id' => $accountId];
- $result = AdqUser::search($params);
- $count = $result->count();
- $bindStatus = $count > 0;
- $data = [
- 'bind_status' => $bindStatus,
- 'msg' => $bindStatus ? '已绑定企微客服,请将企微客服绑定关系全部删除后再执行本操作' : '',
- ];
- }
- return $data;
- }
- }
|