企微短剧业务系统

AccountConfService.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Service;
  3. use App\Models\AdqAccountBindPidConf;
  4. use App\Models\AdqUser;
  5. class AccountConfService
  6. {
  7. public static function bindPid($sysGroupId, $accountId, $pid, $note, $isConfirm) {
  8. # 检测pid 是否已绑定其他投放账号
  9. $bindAccountIds = self::getAccountIdByPid($sysGroupId, $pid, null, $accountId);
  10. \DB::begintransaction();
  11. if(!empty($bindAccountIds)) {
  12. if(0 == $isConfirm) {
  13. return ['已经绑定其他投放账号', 4906];
  14. } else {
  15. # 将其他已绑定账号解除绑定
  16. $updateData = ['enable' => 0, 'update_time' => date('Y-m-d H:i:s')];
  17. $query = "`enable` = 1 and `sys_group_id` = " . $sysGroupId . " and `pid` = '" . $pid . "' and `account_id` in ('"
  18. . implode("','", $bindAccountIds) . "')";
  19. $updateRes = AdqAccountBindPidConf::updateDataByQuery($query, $updateData);
  20. if(!$updateRes) {
  21. \DB::rollBack();
  22. return ['程序异常', 500];
  23. }
  24. }
  25. }
  26. $res = AdqAccountBindPidConf::saveData($sysGroupId, $accountId, $pid, $note);
  27. if(!$res) {
  28. \DB::rollBack();
  29. return ['程序异常', 500];
  30. }
  31. \DB::commit();
  32. return ['成功', 0];
  33. }
  34. public static function bindPidList($sysGroupId, $accountId, $note, $page, $pageSize) {
  35. $query = AdqAccountBindPidConf::getBinPidListQuery($sysGroupId, $accountId, $note);
  36. $countQuery = clone $query;
  37. $count = $countQuery->count();
  38. $list = $query->orderBy('id', 'desc')->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
  39. return [$list, $count];
  40. }
  41. public static function editStatus($id, $status) {
  42. $updateData = ['status' => $status, 'update_time' => date('Y-m-d H:i:s')];
  43. $res = AdqAccountBindPidConf::updateDataById($id, $updateData);
  44. if(!$res) {
  45. return ['程序异常', 500];
  46. }
  47. return ['成功', 0];
  48. }
  49. public static function getAccountIdByPid($sysGroupId, $pid, $status = null, $debarAccountId = null) {
  50. $params['sys_group_id'] = $sysGroupId;
  51. $params['pid'] = $pid;
  52. if(!is_null($status)) $params['status'] = $status;
  53. if(!empty($debarAccountId)) $params['debar_account_id'] = $debarAccountId;
  54. $confDataList = AdqAccountBindPidConf::search($params);
  55. if($confDataList->isEmpty()) {
  56. return null;
  57. }
  58. $confDataList = $confDataList->toArray();
  59. return array_column($confDataList, 'account_id');
  60. }
  61. public static function checkBindType($sysGroupId, $accountId, $type) {
  62. $data = [];
  63. if(1 == $type) {
  64. // 企微投放,检测之前是否有开启状态的推广计划绑定关系
  65. $params = ['sys_group_id' => $sysGroupId, 'status' => 1, 'account_id' => $accountId];
  66. $result = AdqAccountBindPidConf::search($params);
  67. $count = $result->count();
  68. $bindStatus = $count > 0;
  69. $data = [
  70. 'bind_status' => $bindStatus,
  71. 'msg' => $bindStatus ? '已绑定推广计划,请将已绑定计划的状态全部关闭后再执行本操作' : '',
  72. ];
  73. } else if(2 == $type) {
  74. // 直接投放,检测之前是否有未删除的企微客服绑定关系
  75. $params = ['account_id' => $accountId];
  76. $result = AdqUser::search($params);
  77. $count = $result->count();
  78. $bindStatus = $count > 0;
  79. $data = [
  80. 'bind_status' => $bindStatus,
  81. 'msg' => $bindStatus ? '已绑定企微客服,请将企微客服绑定关系全部删除后再执行本操作' : '',
  82. ];
  83. }
  84. return $data;
  85. }
  86. }