123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace app\common\model;
- use think\Model;
- class VipAdminBind extends Model
- {
- // 表名
- protected $table = 'vip_admin_bind';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- ];
- /**
- * @var AdminExtend AdminExtend模型对象
- */
- protected $adminExtendModel = null;
- public function __construct($data = [])
- {
- parent::__construct($data);
- $this->adminExtendModel = model('AdminExtend');
- }
- /**
- * 获取当前VIP所管辖的渠道商和配号代理商id
- * @param $vipId
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getChannelAndAgentId($vipId)
- {
- $channelIds = $this->getChannelIds($vipId);
- $agentIds = $this->getAgentIds($channelIds);
- $adminIds = array_merge($channelIds, $agentIds);
- return $adminIds;
- }
- /**
- * 通过vipId获取隶属的渠道商id
- * @param $vipId
- * @param $channelId 渠道商id
- * @param $username 渠道商用户名
- * @param $nickname 渠道商昵称
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getChannelIds($vipId, $channelId = null, $username = null, $nickname = null)
- {
- #region 获取所有渠道商id
- $fetchObj = $this->join(['admin' => 'qds'], 'qds.id = vip_admin_bind.admin_id_slave')
- ->join('admin_config', 'qds.id = admin_config.admin_id')
- ->join(['auth_group_access' => 'aga_qds'], 'aga_qds.uid = qds.id and aga_qds.group_id=3')
- ->where(['vip_admin_bind.admin_id_master' => $vipId])
- ->field('vip_admin_bind.admin_id_slave');
- if (!empty($channelId)) {
- if (is_array($channelId)) {
- $fetchObj->whereIn('qds.id', $channelId);
- } else {
- $fetchObj->where('qds.id', $channelId);
- }
- }
- if (!empty($username)) {
- $username = trim($username);
- $fetchObj->where(['username' => $username]);
- }
- if (!empty($nickname)) {
- $nickname = trim($nickname);
- $fetchObj->where(['nickname' => ['like', "%$nickname%"]]);
- }
- $channelList = $fetchObj->select();
- $channelIds = array_column($channelList, 'admin_id_slave');
- #endregion
- return $channelIds;
- }
- /**
- * 通过渠道商id获取隶属的配号代理商id
- * @param $channelIds
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getAgentIds($channelIds)
- {
- #region 获取所有配号代理商id
- $agentIds = [];
- if (!empty($channelIds)) {
- $agentList = $this->adminExtendModel->where(['distribute' => 1, 'create_by' => ['in', $channelIds]])
- ->field('admin_id')->select();
- $agentIds = array_column($agentList, 'admin_id');
- }
- #endregion
- return $agentIds;
- }
- /**
- * 通过渠道商id获取隶属的所有代理商id
- * @param $channelIds
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getAllAgentIds($channelIds)
- {
- #region 获取所有代理商id
- $agentIds = [];
- if (!empty($channelIds)) {
- $agentList = $this->adminExtendModel->where(['create_by' => ['in', $channelIds]])
- ->field('admin_id')->select();
- $agentIds = array_column($agentList, 'admin_id');
- }
- #endregion
- return $agentIds;
- }
- public function getAdminIdsByVip($vipId){
- return model("VipAdminBind")
- ->where("admin_id_master",$vipId)
- ->where("flag = 1")
- ->column("admin_id_slave");
- }
- /**
- * 获取vip账号对应的服务号列表
- * @param $iVipId
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getSerListByAdminId($iVipId)
- {
- $admin_list = $this->alias("v")
- ->join('admin_config a', 'v.admin_id_slave=a.admin_id', 'RIGHT')
- ->where(['v.admin_id_master' => $iVipId])
- ->whereNotNull('a.json')
- ->field('a.admin_id,a.json $.authorizer_info.nick_name')
- ->select();
- $res = [];
- foreach ($admin_list as $v){
- $res[] = ['sub_id' => $v['admin_id'], 'sub_name' => trim($v["json_extract(a.json , '$.authorizer_info.nick_name')"], '"') ?: '-'];
- }
- return $res;
- }
- }
|