VipAdminBind.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class VipAdminBind extends Model
  5. {
  6. // 表名
  7. protected $table = 'vip_admin_bind';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. ];
  16. /**
  17. * @var AdminExtend AdminExtend模型对象
  18. */
  19. protected $adminExtendModel = null;
  20. public function __construct($data = [])
  21. {
  22. parent::__construct($data);
  23. $this->adminExtendModel = model('AdminExtend');
  24. }
  25. /**
  26. * 获取当前VIP所管辖的渠道商和配号代理商id
  27. * @param $vipId
  28. * @return array
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. * @throws \think\exception\DbException
  32. */
  33. public function getChannelAndAgentId($vipId)
  34. {
  35. $channelIds = $this->getChannelIds($vipId);
  36. $agentIds = $this->getAgentIds($channelIds);
  37. $adminIds = array_merge($channelIds, $agentIds);
  38. return $adminIds;
  39. }
  40. /**
  41. * 通过vipId获取隶属的渠道商id
  42. * @param $vipId
  43. * @param $channelId 渠道商id
  44. * @param $username 渠道商用户名
  45. * @param $nickname 渠道商昵称
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public function getChannelIds($vipId, $channelId = null, $username = null, $nickname = null)
  52. {
  53. #region 获取所有渠道商id
  54. $fetchObj = $this->join(['admin' => 'qds'], 'qds.id = vip_admin_bind.admin_id_slave')
  55. ->join('admin_config', 'qds.id = admin_config.admin_id')
  56. ->join(['auth_group_access' => 'aga_qds'], 'aga_qds.uid = qds.id and aga_qds.group_id=3')
  57. ->where(['vip_admin_bind.admin_id_master' => $vipId])
  58. ->field('vip_admin_bind.admin_id_slave');
  59. if (!empty($channelId)) {
  60. if (is_array($channelId)) {
  61. $fetchObj->whereIn('qds.id', $channelId);
  62. } else {
  63. $fetchObj->where('qds.id', $channelId);
  64. }
  65. }
  66. if (!empty($username)) {
  67. $username = trim($username);
  68. $fetchObj->where(['username' => $username]);
  69. }
  70. if (!empty($nickname)) {
  71. $nickname = trim($nickname);
  72. $fetchObj->where(['nickname' => ['like', "%$nickname%"]]);
  73. }
  74. $channelList = $fetchObj->select();
  75. $channelIds = array_column($channelList, 'admin_id_slave');
  76. #endregion
  77. return $channelIds;
  78. }
  79. /**
  80. * 通过渠道商id获取隶属的配号代理商id
  81. * @param $channelIds
  82. * @return array
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @throws \think\exception\DbException
  86. */
  87. public function getAgentIds($channelIds)
  88. {
  89. #region 获取所有配号代理商id
  90. $agentIds = [];
  91. if (!empty($channelIds)) {
  92. $agentList = $this->adminExtendModel->where(['distribute' => 1, 'create_by' => ['in', $channelIds]])
  93. ->field('admin_id')->select();
  94. $agentIds = array_column($agentList, 'admin_id');
  95. }
  96. #endregion
  97. return $agentIds;
  98. }
  99. /**
  100. * 通过渠道商id获取隶属的所有代理商id
  101. * @param $channelIds
  102. * @return array
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\ModelNotFoundException
  105. * @throws \think\exception\DbException
  106. */
  107. public function getAllAgentIds($channelIds)
  108. {
  109. #region 获取所有代理商id
  110. $agentIds = [];
  111. if (!empty($channelIds)) {
  112. $agentList = $this->adminExtendModel->where(['create_by' => ['in', $channelIds]])
  113. ->field('admin_id')->select();
  114. $agentIds = array_column($agentList, 'admin_id');
  115. }
  116. #endregion
  117. return $agentIds;
  118. }
  119. public function getAdminIdsByVip($vipId){
  120. return model("VipAdminBind")
  121. ->where("admin_id_master",$vipId)
  122. ->where("flag = 1")
  123. ->column("admin_id_slave");
  124. }
  125. /**
  126. * 获取vip账号对应的服务号列表
  127. * @param $iVipId
  128. * @return array
  129. * @throws \think\db\exception\DataNotFoundException
  130. * @throws \think\db\exception\ModelNotFoundException
  131. * @throws \think\exception\DbException
  132. */
  133. public function getSerListByAdminId($iVipId)
  134. {
  135. $admin_list = $this->alias("v")
  136. ->join('admin_config a', 'v.admin_id_slave=a.admin_id', 'RIGHT')
  137. ->where(['v.admin_id_master' => $iVipId])
  138. ->whereNotNull('a.json')
  139. ->field('a.admin_id,a.json $.authorizer_info.nick_name')
  140. ->select();
  141. $res = [];
  142. foreach ($admin_list as $v){
  143. $res[] = ['sub_id' => $v['admin_id'], 'sub_name' => trim($v["json_extract(a.json , '$.authorizer_info.nick_name')"], '"') ?: '-'];
  144. }
  145. return $res;
  146. }
  147. }