modelAdmin = model('Admin'); $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin() ? true : false); $payList = model('AdminExtend')->getPayMethodList(); unset($payList[3]); unset($payList[4]); $this->view->assign("payMethodList", $payList); $this->assignconfig("admin", ['id' => $this->auth->id]); $this->assign("group", $this->group); $payerList = model('Payer')->getPayerList(); $this->assign("payerList", $payerList); } /** * 查看 */ public function index() { // $isassociated: 1=> 正常 2=> 关联 3=> 删除 $kl_id = $this->request->param('kl_id') ?? 0; // KL规则是否关联渠道 if ($kl_id && $this->request->param('isassociated')) { $isassociated = $this->request->param('isassociated'); } else { $isassociated = 1; } $kl_id = $this->request->param('kl_id') ?? 0; if ($kl_id && $this->request->param('isassociated')) { $isassociated = $this->request->param('isassociated'); } else { $isassociated = 1; } $admin_where_in = []; $admin_where_not_in = []; if ($isassociated == 3) { // 查询已关联的渠道商,即将做删除操作 $except_rule_obj = model('KlRuleManage')->get(['id' => $kl_id]); $except_rule_ids = $except_rule_obj->channel_ids; if (empty($except_rule_ids)) { $admin_where_in['admin.id'] = ['IN', '-1']; } if (!empty($except_rule_ids) && $except_rule_ids != '*') { $admin_where_in['admin.id'] = ['IN', $except_rule_ids]; } } elseif ($isassociated == 2) { // 查询未关联的渠道商,即将做关联操作 $except_rule_obj = model('KlRuleManage')->get(['id' => $kl_id]); $except_rule_ids = $except_rule_obj->channel_ids; if (!empty($except_rule_ids) && $except_rule_ids != '*') { $admin_where_not_in['admin.id'] = ['NOT IN', $except_rule_ids]; } } $isIndex = 0; //筛选渠道 $operate = $this->request->param('operate') ?? ''; $channel_ids = $this->request->param('channel_ids') ?? ''; if ($operate) { if ($operate == 'add') { //添加 $isIndex = 1; } elseif ($operate == 'remove') { //移除 $isIndex = 2; } } $this->assignconfig('channel_ids', $channel_ids); $this->assignconfig('operate', $operate); $this->assign('is_index', $isIndex); $this->assignconfig('is_index', $isIndex); $platformlist = model("platform")->getPlatformList(); $ophosts = OfficialAccountsService::instance()->getOphostModel() ->where('status', 1) ->column('id, concat(id," | ",host," \| ",p_desc)'); $wxpays = OfficialAccountsService::instance()->getWxpayModel() ->where('status', 1) ->column('id, concat(id," | ",pay_host," \| ",name,if(is_closure=\'1\',"(被封)",""))'); $this->assignconfig('platforms', $platformlist); $this->assignconfig('ophosts', $ophosts); $this->assignconfig('wxpays', $wxpays); $this->assignconfig('isassociated', $isassociated); $this->assignconfig('kl_id', $kl_id); $this->assign('isassociated', $isassociated); $this->assign('kl_id', $kl_id); if ($this->request->isAjax()) { //选择渠道列表 if ($operate) { if ($channel_ids && !is_null($channel_ids)) { $channelsRow = model("ChannelMenuList")->where('id', 'eq', $channel_ids)->find(); if ($channelsRow) { $channel_ids = $channelsRow['channel_id']; } } if ($operate == 'add') { //添加 $channel_ids = explode(',', $channel_ids); if (!empty($channel_ids) && $channel_ids[0] != '*') { $admin_where_not_in['admin.id'] = ['NOT IN', $channel_ids]; } } elseif ($operate == 'remove') { //移除 if (empty($channel_ids)) { $admin_where_in['admin.id'] = ['IN', '-1']; } if (!empty($channel_ids) && $channel_ids[0] != '*') { $admin_where_in['admin.id'] = ['IN', $channel_ids]; } } } //今天 $today = date('Ymd', time()); //昨天 $yesterday = date('Ymd', strtotime('-1 days')); $channels = $this->modelAdmin->join('auth_group_access a', 'a.uid= admin.id')->where('a.group_id', 'lt', 3) ->select(); $cNames = []; foreach ($channels as $channel) { $cNames[$channel->id] = $channel->nickname; } // list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $filter = $this->request->get("filter", ''); $sort = $this->request->get("sort", "id"); $order = $this->request->get("order", "DESC"); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); $filter = json_decode($filter, true); $where = []; $idMap = [ 'ophost' => 'ophost_id', 'wxpay' => 'wxpay_id', 'menuophost' => 'menuophost_id', 'menuwxpay_host' => 'menuwxpay_id', ]; if ($filter) { foreach ($filter as $k => $v) { if (array_key_exists($k, $idMap)) { $where["ac.{$idMap[$k]}"] = $v; } elseif ($k == "admin.id" || $k == "admin_extend.reward_state" || $k == "status" || $k == "ac.platform_id") { $where[$k] = ['=', $v]; } else { $where[$k] = ['like', "%{$v}%"]; } } } $fileChannel = []; $authAccess = model('AuthGroupAccess')->where('uid', $this->auth->id)->find(); if ($authAccess->group_id == 2) { $fileChannel['adminExtend.create_by'] = $this->auth->id; } if ($isassociated != 1 || $isIndex != 0) { $total = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') ->where($where) ->where($fileChannel) ->where('a.group_id', 3) ->where($admin_where_in) ->where($admin_where_not_in) ->count(); $list = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') //->join('orders_collect o','o.admin_id = admin.id and o.type=3 and o.flag =3 and business_line="0"','left') //->join('admin_money m','m.admin_id = admin.id','left') ->where($where) ->where($fileChannel) ->where('a.group_id', 3) ->where($admin_where_in) ->where($admin_where_not_in) //->field('admin.id as id,o.id as oid,o.recharge_money as recharge_money,m.benefit_money as benefit_money,m.no_cash_money as no_cash_money,ac.guide_domain,ac.is_fouce,ac.entryhost_id,ac.platform_list,ac.appid,ac.qrcode_image') ->field('admin.id as id,ac.guide_domain,ac.is_fouce,ac.entryhost_id,ac.platform_list,ac.appid,ac.qrcode_image') ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as $k => &$v) { $v['admin_extend']['create_by'] = isset($cNames[$v['admin_extend']['create_by']]) ? $cNames[$v['admin_extend']['create_by']] : ''; } //渠道商开户人列表 $create_list = $offset <= 0 ? model('Admin')->getListByGroup(2, [], 'admin.id,admin.username,admin.nickname') : []; $result = array("total" => $total, "rows" => $list, "create_list" => $create_list); return json($result); } # 结束 $total = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') ->where($where) ->where($fileChannel) ->where('a.group_id', 3) ->count(); $list = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') ->join('orders_collect o', 'o.admin_id = admin.id and o.type=3 and o.flag =3 and business_line="0"', 'left') ->join('admin_money m', 'm.admin_id = admin.id', 'left') ->where($where) ->where($fileChannel) ->where('a.group_id',3) ->field('admin.id as id,o.id as oid,o.recharge_money as recharge_money,m.cash_money,m.count_cash_money,m.split_money,ac.guide_domain,ac.is_fouce,ac.entryhost_id,ac.platform_list,ac.appid,ac.qrcode_image') ->order($sort, $order) ->limit($offset, $limit) ->select(); $todayRes = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') ->join('orders_collect o', 'o.admin_id = admin.id and o.type=1 and o.flag =3 and business_line="0" and o.createdate=' . $today, 'left') ->where($where) ->where($fileChannel) ->where('a.group_id', 3) ->field('admin.id as id,o.id as oid,o.recharge_money as recharge_money') ->order($sort, $order) ->limit($offset, $limit) ->select(); $yesterdayRes = $this->modelAdmin ->with("adminExtend") ->join("admin_config ac", "admin.id = ac.admin_id", "left") ->join('auth_group_access a', 'a.uid= admin.id') ->join('orders_collect o', 'o.admin_id = admin.id and o.type=1 and o.flag =3 and business_line="0" and o.createdate=' . $yesterday, 'left') ->where($where) ->where($fileChannel) ->where('a.group_id', 3) ->field('admin.id as id,o.id as oid,o.recharge_money as recharge_money') ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as $k => &$v) { $v['no_cash_money'] = $v['benefit_money'] = 0; //未提现金额,结算单金额 $money_collect = model('orders_collect')->sumCollect($v['id'],1,3, '20180101', date("Ymd")); if ($money_collect) { $v['benefit_money'] = $money_collect['recharge_money_benefit']; $v['no_cash_money'] = StringHelper::moneyFormat(($money_collect['recharge_money_benefit']*100-$v['cash_money']*100-$v['count_cash_money']*100 - $v['split_money']*100)/100); } $v['entryhost'] = ""; $entryinfo = model("entryhost")->getinfo($v['entryhost_id']); if ($entryinfo) { $v['entryhost'] = $entryinfo['host']; } $adminconfiginfo = model("AdminConfig")->getAdminInfoAll($v['id']); $v['ophost'] = ""; $v['wxpay'] = ""; $v['menuophost'] = ""; $v['menuwxpay_host'] = ""; if ($adminconfiginfo) { $v['ophost'] = $adminconfiginfo['ophost_host']; $v['wxpay'] = $adminconfiginfo['wxpay_name'] . "-{$adminconfiginfo['wxpay_pay_host']}"; if (isset($adminconfiginfo['menuophost'])) { $v['menuophost'] = $adminconfiginfo['menuophost']; } if (isset($adminconfiginfo['menuwxpay_host'])) { $v['menuwxpay_host'] = $adminconfiginfo['menuwxpay_host']; } } $v['platforms'] = ""; if (!empty($v['platform_list'])) { $platarr = explode(",", trim($v['platform_list'], ",")); foreach ($platformlist as $pk => $pv) { if (in_array($pv['id'], $platarr)) { $token = model("ptoken")->getToken($pv['id'], $v['id']); if ($token) { $v['platforms'] .= $pv['name'] . "-已授权
"; } else { $v['platforms'] .= $pv['name'] . "-未授权
"; } } } } if (empty($v['platforms'])) { $v['platforms'] = "无"; } $v['admin_extend']['create_by'] = isset($cNames[$v['admin_extend']['create_by']]) ? $cNames[$v['admin_extend']['create_by']] : ''; $v['today_recharge_money'] = $todayRes[$k]['recharge_money']; $v['yesterday_recharge_money'] = $yesterdayRes[$k]['recharge_money']; //关联短链域名数量 $v['short_relation_count'] = model('ShortRelation')->getRelationCount($v['id']); //关联导粉域名数量 $v['guide_relation_count'] = model('GuideRelation')->getRelationCount($v['id']); } unset($v); //渠道商开户人列表 $create_list = $offset <= 0 ? model('Admin')->getListByGroup(2, [], 'admin.id,admin.username,admin.nickname') : []; $result = array("total" => $total, "rows" => $list, "create_list" => $create_list); return json($result); } return $this->view->fetch(); } /** * 渠道商订单明细 */ /*public function orders($ids) { $ids = intval($ids); $userInfo = model('Admin')->get($ids); $list = model('Orders')->join('User u', 'u.id=orders.user_id')->join('Book b', 'orders.book_id=b.id', 'LEFT') ->where('u.channel_id', $ids) ->field('u.id,orders.user_id,u.avatar,u.nickname,orders.payid,orders.money,orders.state,orders.kandian,orders.free_kandian,b.name,b.author,orders.createtime') ->order('orders.createtime', 'desc') ->paginate(10); if ($list) { foreach ($list as $key => $val) { $list[$key]['createtime'] = date('Y-m-d H:i:s', $val['createtime']); } } $this->assign('list', $list); $this->assign('userInfo', $userInfo); //dump($list); return $this->view->fetch(); }*/ /** * 读者管理 * @param $ids */ public function users($ids) { header('location:/admin/auth/user/index?channel=' . $ids); } /** * 更多 */ public function more($ids) { $this->assign('ids', $ids); $this->assign('user', '/admin/auth/channel/users/ids/' . $ids); $this->assign('order', '/admin/auth/channel/orders/ids/' . $ids); return $this->view->fetch(); } /** * 渠道商数据统计 */ public function collect($ids) { $ids = intval($ids); $userInfo = model('Admin')->get($ids); $users = model('UserCollect')->where(['admin_id' => $ids, 'type' => 3])->find(); //用户统计 $collect = model('OrdersCollect')->where(['admin_id' => $ids, 'type' => 3])->find(); //订单统计 $this->assign('userInfo', $userInfo); $this->assign('users', $users); $this->assign('collect', $collect); return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); $extends = $this->request->post("extend/a"); $config = $this->request->post("config/a"); $adminConfig = $this->request->post("admin_config/a"); if ($params) { if (empty($config)) { $this->error('平台相关信息不能为空'); } //设置AdminConfig参数 $adminData = []; $adminData['unpay_tip'] = '1'; $adminData['read_tip'] = '1'; $adminData['book_guide_chapter_idx'] = config('site.book_guide_chapter_idx'); $adminData['createtime'] = time(); $adminData['updatetime'] = time(); if ($config) { //推送开关 add at 2018-08-31 19:46:08 $adminData['subscribe_tip'] = $config['subscribe_tip'] ?? '0'; $adminData['sign_tip'] = $config['sign_tip'] ?? '0'; $adminData['continueread_tip'] = $config['continueread_tip'] ?? '0'; $adminData['unpay_tip'] = $config['unpay_tip'] ?? '0'; $adminData['read_tip'] = $config['read_tip'] ?? '0'; $adminData['update_tip'] = $config['update_tip'] ?? '0'; $adminData['timing_tip'] = $config['timing_tip'] ?? '0'; $adminData['ref_out_push'] = $config['ref_out_push'] ?? '0'; $adminData['wx_ad_state'] = $config['wx_ad_state']; $adminData['is_account_self'] = $config['is_account_self']; $adminData['custom_goods'] = $config['custom_goods']; $adminData['first_recharge_imgtext_post'] = $config['first_recharge_imgtext_post'] ?? '0'; $adminData['order_unrecharge_post_time'] = (int)$config['order_unrecharge_post_time'] ?? 0; //检查平台信息 $this->checkedPlatform($config, $adminData); } //创建Admin if(! AdminService::instance()->checkPassword($params['password'])){ $this->error(AdminService::instance()->getPasswordRule()); } $params['salt'] = Random::alnum(); $params['password'] = md5(md5($params['password']) . $params['salt']); $params['avatar'] = asset('/img/avatar.png'); //设置新管理员默认头像。 $result = $this->modelAdmin->validate('Admin.add')->save($params); if ($result === false) { $this->error($this->modelAdmin->getError()); } //添加关联权限组 model('AuthGroupAccess')->insert(['uid' => $this->modelAdmin->id, 'group_id' => 3]); //创建AdminExtend if ($extends) { $extends['admin_id'] = $this->modelAdmin->id; $extends['create_by'] = Session::get('admin')['id']; //过滤一下收款方式的空格 $extends['card_holder'] = rm_space($extends['card_holder']); $extends['card_num'] = rm_space($extends['card_num']); $extends['card_bank'] = rm_space($extends['card_bank']); $res = model('Admin_extend')->save($extends); $redis = Redis::instance(); $key = 'AE:' . $this->modelAdmin->id; $redis->del($key); if ($res === false) { $this->error(model('Admin_extend')->getError()); } } //创建AdminConfig $adminData['admin_id'] = $this->modelAdmin->id; if ($adminConfig['palmpay_sub_account_ids']) { $palmpay_sub_account_arr = explode(',', $adminConfig['palmpay_sub_account_ids']); if (!empty($palmpay_sub_account_arr)) { foreach ($palmpay_sub_account_arr as $val) { list($company_id, $palmpay_sub_account_id) = explode('|', $val); $palmpay_sub_account_id_arr[] = array( 'company_id' => $company_id, 'palmpay_sub_account_id' => $palmpay_sub_account_id ); } } } $adminData['palmpay_sub_account_ids'] = empty($palmpay_sub_account_id_arr) ? '[]' : json_encode($palmpay_sub_account_id_arr); $resultSql = model('AdminConfig')->insert($adminData); if ($resultSql === false) { $this->error(model('AdminConfig')->getError()); } $this->success(); } $this->error(); } //虚假域名 $fake_ophost_list = $fake_menuophost_list = model("VirtualDomain")->getFakeophostList(); $this->assign('wxpay_list', model("wxpay")->getListFormatByPlatformId()); $this->assign('platforms', model('Platform')->getPlatformList()); $this->assign('fake_menuophost_list', $fake_menuophost_list); $this->assign('fake_ophost_list', $fake_ophost_list); return $this->view->fetch(); } /** * 检查平台信息 * @param $config * @param $admin_data */ private function checkedPlatform(&$config, &$admin_data) { $admin_data = array_merge($config, $admin_data); if (!$ophost_id = $config['ophost_id'] ?? null) { $this->error('业务域名不能为空'); } if (!$wxpay_id = $config['wxpay_id'] ?? null) { $this->error('支付域名不能为空'); } $ophost = model('Ophost')->where('id', $ophost_id)->column('platform_id,host'); if (!$menuophost_id = $config['menuophost_id'] ?? null) { $this->error('菜单域名不能为空'); } if (!$menuwxpay_id = $config['menuwxpay_id'] ?? null) { $this->error('菜单支付域名不能为空'); } $menu_ophost = model('Ophost')->where('id', $menuophost_id)->column('platform_id,host'); //添加参数 $admin_data['platform_id'] = key($ophost); $admin_data['menu_platform_id'] = key($menu_ophost); $admin_data['ophost_id'] = $ophost_id; $admin_data['wxpay_id'] = $wxpay_id; $admin_data['menuophost_id'] = $menuophost_id; $admin_data['menuwxpay_id'] = $menuwxpay_id; if ($config['platform_list']) { if (!in_array($admin_data['platform_id'], $config['platform_list'])) { array_push($config['platform_list'], $admin_data['platform_id']); } } else { array_push($config['platform_list'], $admin_data['platform_id']); } $admin_data['platform_list'] = trim(implode(',', $config['platform_list']), ','); //下单未充值时间间隔验证 if(isset($admin_data['order_unrecharge_post_time'])){ if($admin_data['order_unrecharge_post_time']<=0){ $admin_data['order_unrecharge_post_time'] = 1; } if($admin_data['order_unrecharge_post_time']>31){ $admin_data['order_unrecharge_post_time'] = 30; } } } /** * 编辑 */ public function edit($ids = null) { $row = $this->modelAdmin->get(['id' => $ids]); if (!$row) { $this->error(__('No Results were found')); } if ($this->request->isPost()) { //编辑处理 $message = null; $params = $this->request->post("row/a"); $extends = $this->request->post("extend/a"); $config = $this->request->post("config/a"); $adminConfig = $this->request->post("admin_config/a"); //修改Admin if ($params) { if ($params['password']) { if(! AdminService::instance()->checkPassword($params['password'])){ $this->error(AdminService::instance()->getPasswordRule()); } $params['salt'] = Random::alnum(); $params['password'] = md5(md5($params['password']) . $params['salt']); $params['token'] = Random::uuid(); AdminService::instance()->updateAdminSessionStatus($ids); } else { unset($params['password'], $params['salt']); } //自定义商品是否开启为否,则删除渠道商自定义商品信息,数据库+redis if ($adminConfig['custom_goods'] == 0) { GoodsService::instance()->delChannelGoodsList($row->id); } //这里需要针对username和email做唯一验证 $adminValidate = \think\Loader::validate('Admin'); $adminValidate->rule([ 'username' => 'require|max:50|unique:admin,username,' . $row->id, 'email' => 'email|unique:admin,email,' . $row->id ]); $result = $row->validate('Admin.edit')->save($params); if ($result === false) { $this->error($row->getError()); } } if ($adminConfig['palmpay_sub_account_ids']) { $palmpay_sub_account_arr = explode(',', $adminConfig['palmpay_sub_account_ids']); if (!empty($palmpay_sub_account_arr)) { foreach ($palmpay_sub_account_arr as $val) { list($company_id, $palmpay_sub_account_id) = explode('|', $val); $palmpay_sub_account_id_arr[] = array( 'company_id' => $company_id, 'palmpay_sub_account_id' => $palmpay_sub_account_id ); } } } $adminConfig['palmpay_sub_account_ids'] = empty($palmpay_sub_account_id_arr) ? '[]' : json_encode($palmpay_sub_account_id_arr); //修改AdminExtend if ($extends) { //仅超管可以编辑开户人 add at 2018-08-31 15:34:09 if (isset($extends['create_by']) && in_array($this->group, [1]) && $extends['create_by'] != $extends['create_by_old']) { //检查开户人状态 $admin = model('Admin')->getById($extends['create_by']); if (!$admin || $admin['status'] != 'normal') { $this->error(__('当前开户人不存在,请重新修改开户人')); } } //过滤一下收款方式的空格 $extends['card_holder'] = rm_space($extends['card_holder']); $extends['card_num'] = rm_space($extends['card_num']); $extends['card_bank'] = rm_space($extends['card_bank']); $res = model('Admin_extend')->allowField(true)->save($extends, ['admin_id' => $row->id]); $redis = Redis::instance(); $key = 'AE:' . $row->id; $redis->del($key); if ($res === false) { $this->error(model('Admin_extend')->getError()); } } //推送开关检查 && AdminConfig修改 $adminConfig['subscribe_tip'] = $adminConfig['subscribe_tip'] ?? '0'; $adminConfig['sign_tip'] = $adminConfig['sign_tip'] ?? '0'; $adminConfig['continueread_tip'] = $adminConfig['continueread_tip'] ?? '0'; $adminConfig['unpay_tip'] = $adminConfig['unpay_tip'] ?? '0'; $adminConfig['read_tip'] = $adminConfig['read_tip'] ?? '0'; $adminConfig['update_tip'] = $adminConfig['update_tip'] ?? '0'; $adminConfig['search_tip'] = $adminConfig['search_tip'] ?? '0'; $adminConfig['timing_tip'] = $adminConfig['timing_tip'] ?? '0'; $adminConfig['first_recharge_imgtext_post'] = $adminConfig['first_recharge_imgtext_post'] ?? '0'; $adminConfig['order_unrecharge_post_time'] = (int)$adminConfig['order_unrecharge_post_time'] ?? 0; //检查平台相关信息 if ($config) { //倒粉域名&短链域名 开关 -- 检测是否有关联的倒粉域名或者短链域名 if (isset($config['guide_domain']) && $config['guide_domain']) { if (!model('ShortRelation')->checkChannelRelation($row['id']) || !model('GuideRelation')->checkChannelRelation($row['id'])) { $this->error('请先为渠道指派导粉域名和短链域名'); } } //检查平台信息&设置要更新的参数 $configCache = model('AdminConfig')->getAdminInfoAll($row['id']); $this->checkedPlatform($config, $adminConfig); //检查是否要刷新菜单 if ($adminConfig['platform_id'] != $configCache['platform_id'] || //平台不一致 $adminConfig['ophost_id'] != $configCache['ophost_id'] || //业务域名不一致 $adminConfig['menuophost_id'] != $configCache['menuophost_id'] //菜单域名不一致 ) { //推送微信菜单 list($status, $message) = WeChatMenu::replaceChannelMenuById($row['id'], $adminConfig['menuophost_id'], $configCache['is_qrcode_menu']); if ($status) { $adminConfig['wx_menu'] = $message; $message = null; } } } $res = model('AdminConfig')->save($adminConfig, ['admin_id' => $row->id]); if ($res === false) { $this->error(model('AdminConfig')->getError()); } //清除redis缓存 model('AdminConfig')->delAdminInfoAllCache($row['id']); if ($message) { $this->success($message); } $this->success(); } //展示处理 $adminConfig = model('AdminConfig')->where('admin_id', $row['id'])->find(); //检查渠道平台列表 if (!$adminConfig['platform_list']) { $this->error('没有平台信息'); } //AdminExtend $extends = model('Admin_extend')->where('admin_id', $row['id'])->find(); //获取全部平台列表 $platform_lists = model('Platform')->getPlatformList(); //检查渠道是否授权全部平台 $channel_is_auth = model('Ptoken')->checkChannelIsAuth($adminConfig['platform_list'], $row['id']); //获取业务域名列表与支付域名列表 if ($channel_is_auth) { $channelAuthPlatformId = model('Platform')->getChannelHaveAuthorizedPlatformId($adminConfig['admin_id'], $adminConfig['platform_list']); } else { $channelAuthPlatformId = $adminConfig['platform_list']; } $ophost_list = model("ophost")->getListFormatByPlatformId($channelAuthPlatformId); $wxpay_list = model("wxpay")->getListFormatByPlatformId(); $menu_wxpay_list = model("wxpay")->getListFormatByPlatformId(); //虚假域名 $fake_ophost_list = $fake_menuophost_list = model("VirtualDomain")->getFakeophostList(); //授权信息-重置 if (in_array($this->group, [ AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN, AdminConstants::ADMIN_CONFIG_SUBSCRIBE_METHOD_GUID, AdminConstants::ADMIN_GROUP_ID_TECHNICAL_SUPPORT, AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER ])) { $auth_platform_list = model("platform")->whereIn('id', $adminConfig['platform_list'])->select(); foreach ($auth_platform_list as $key => $val) { $auth_platform_list[$key]['is_auth'] = false; if (model('Ptoken')->getToken($val['id'], $row['id'])) { $auth_platform_list[$key]['is_auth'] = true; } } $sync = model('SyncUser')->where(['admin_id' => $row['id'], 'appid' => $adminConfig['appid']])->find(); $this->assign('sync', $sync); $this->assign('auth_json', $adminConfig['json']); $this->assign('auth_platform_list', $auth_platform_list); } $canEditDomain = in_array($this->group, [ AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN, AdminConstants::ADMIN_GROUP_ID_TECHNICAL_SUPPORT, AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER ]); $this->assign('can_edit_domain', $canEditDomain); //渠道商开户人列表 $create_list = []; if (in_array($this->group, [ AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN, AdminConstants::ADMIN_GROUP_ID_TECHNICAL_SUPPORT, AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER ])) { $create_list = model('AuthGroupAccess') ->alias('ga') ->field('a.*') ->join('admin a', 'a.id=ga.uid', 'LEFT') ->where(['ga.group_id' => '2']) ->select(); } //关联短链域名数量 $row['short_relation_count'] = model('ShortRelation')->getRelationCount($row['id']); //关联导粉域名数量 $row['guide_relation_count'] = model('GuideRelation')->getRelationCount($row['id']); if ($adminConfig['palmpay_sub_account_ids']) { $json = json_decode($adminConfig['palmpay_sub_account_ids'], true); $adminConfig['palmpay_sub_account_ids'] = implode(',', array_column($json, 'palmpay_sub_account_id')); } $this->assign("row", $row); $this->assign('platforms', $platform_lists); $this->assign('plist', explode(',', $adminConfig['platform_list'])); $this->assign('adminConfigs', $adminConfig); $this->assign('platform_id', $adminConfig['platform_id']); $this->assign('ophost_list', $ophost_list); $this->assign('wxpay_list', $wxpay_list); $this->assign('menu_wxpay_list', $menu_wxpay_list); $this->assign('fake_menuophost_list', $fake_menuophost_list); $this->assign('fake_ophost_list', $fake_ophost_list); $this->assign('extends', $extends); $this->assign('create_list', $create_list); $this->assignconfig('admin_id', $adminConfig['admin_id']); $this->assignconfig('channel_is_auth', $channel_is_auth); return $this->view->fetch(); } /** * 重置服务号 */ public function re() { $admin_id = $this->request->param('admin_id'); /** * 清除旧配置 */ if (!$adminConfig = model('AdminConfig')->get(['admin_id' => $admin_id])) { $this->error('获取信息失败'); } $adminInfo = collection($adminConfig)->toArray(); $token = collection(model('Ptoken')->where(['admin_id' => $admin_id])->select())->toArray(); Log::info('Reset WeChat Config Data:' . var_export(['admin_config' => $adminInfo, 'ptoken' => $token], true)); $data = [ 'secret' => null, 'appid' => null, 'json' => null, 'txt' => null, 'refresh_token' => null, 'wx_menu' => null, 'is_auth' => 0, 'wx_ad_source_id' => 0, 'wx_ad_state' => 0, 'is_account_self' => '0', 'custom_goods' => '0', 'qrcode_image' => null ]; if (false === model('Ptoken')->where(['admin_id' => $admin_id])->delete()) { $this->error('删除Token数据失败'); } if (false === $adminConfig->save($data)) { $this->error('清除授权配置信息失败'); } $redis = Redis::instance(); model('AdminConfig')->delAdminInfoAllCache($admin_id); $redis->del('AA:' . $adminConfig['appid']); //删除渠道商自定义商品信息,数据库+redis GoodsService::instance()->delChannelGoodsList($admin_id); $this->success('重置成功'); } /** * 同步微信用户 */ public function sync() { $admin_id = $this->request->param('admin_id'); if (!$admin_id) { $this->error('获取用户ID错误'); } if (!$adminConfig = model('AdminConfig')->getAdminInfoAll($admin_id)) { $this->error('获取渠道信息错误'); } $mq = new Rabbitmq(); $mq->send(['channel_id' => $admin_id, 'appid' => $adminConfig['appid']], self::SYNC_MQ_QUEUE_NAME, self::SYNC_MQ_EXCHANGE_NAME); Log::info('syncUser->Queue: Channel_id:' . $admin_id . ' AppID:' . $adminConfig['appid'] . ' 添加微信用户同步任务'); $this->success('微信用户同步任务添加成功'); } /** * 删除 */ public function del($ids = "") { if ($ids) { // 避免越权删除管理员 $childrenGroupIds = $this->childrenGroupIds; $adminList = $this->modelAdmin->where('id', 'in', $ids)->where('id', 'in', function ($query) use ($childrenGroupIds) { $query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid'); })->select(); if ($adminList) { $deleteIds = []; foreach ($adminList as $k => $v) { $deleteIds[] = $v->id; } $deleteIds = array_diff($deleteIds, [$this->auth->id]); if ($deleteIds) { $this->modelAdmin->where('id', 'in', $deleteIds)->update(['status' => 'hidden']); //model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete(); $this->success(); } } } $this->error(); } /** * 批量更新 * @internal */ public function multi($ids = "") { // 管理员禁止批量操作 $this->error(); } /** * 检查平台是否授权 */ public function checkplatformauth() { $platform_id = $this->request->get("platform_id"); $channel_id = $this->request->get("channel_id"); if (!is_numeric($platform_id) || !is_numeric($channel_id)) { $this->error('没有平台ID OR 渠道ID'); } if ($sourcePtoken = model('Ptoken')->whereIn('platform_id', $platform_id)->where('admin_id', $channel_id)->select()) { $this->success(); } else { $this->error('没有授权'); } } /** * 获取业务域名 * @return \think\response\Json */ public function ajaxgetophostlistbyplatformid() { $platform_id = $this->request->get("platform_id"); if (!is_numeric($platform_id)) { $res['code'] = 0; $res['msg'] = "参数错误"; return json($res); } $res['code'] = 1; $res['data'] = model("ophost")->getListFormatByPlatformId($platform_id); return json($res); } /** * 获取支付域名 * @return \think\response\Json */ public function ajaxgetwxpaylistbyplatformid() { $platform_id = $this->request->get("platform_id"); $ophost_id = $this->request->get("ophost_id"); if (!is_numeric($platform_id) || !is_numeric($ophost_id)) { $res['code'] = 0; $res['msg'] = "参数错误"; return json($res); } $res['code'] = 1; $res['data'] = model("wxpay")->getListFormatByPlatformId(); return json($res); } public function select() { $isIndex = 0; $operate = $this->request->param('operate') ?? 'add'; //不用的位置调用,选择不用的type $type = $this->request->param('type',1); //需要过滤渠道 的资源id, $sourceId = $this->request->param('source_id',0); if ($operate) { if ($operate == 'add') { //添加 $isIndex = 1; } elseif ($operate == 'remove') { //移除 $isIndex = 2; } } $this->assignconfig('source_id',$sourceId); $this->assignconfig('operate', $operate); $this->assign('is_index', $isIndex); $this->assignconfig('is_index', $isIndex); $this->assignconfig('type', $type); $this->assignconfig('group_ids', $this->request->param('group_ids')); if ($this->request->isAjax()) { $groupIds = [3,7]; if ($this->request->param('group_ids') > 0) { $groupIds = explode(',', $this->request->param('group_ids')); } $authGroupList = model('AuthGroupAccess')->where('group_id', 'in',$groupIds) ->field('uid,group_id') ->select(); $groupName = AuthGroup::where('id', 'in', $groupIds) ->column('id,name'); $adminGroupName = []; $allIds = []; foreach ($authGroupList as $k => $v) { $allIds[] = $v['uid']; if (isset($groupName[$v['group_id']])) $adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']]; } //获取添加的channelIds $oldIds = []; switch ($type){ case 1: $oldChannels = GoodsChannelsService::instance()->getChannelsByGoods($sourceId); $oldIds = $oldChannels != false ? array_column($oldChannels,'channel_id') : []; break; case 2: $oldChannels =PayGuideService::instance()->getChannelByGuide($sourceId); $oldIds = $oldChannels != false ? array_column($oldChannels,'channel_id') : []; break; case 3: $oldChannels = model('admin/ConfigLightRule')->where('id', $sourceId)->column('channel_ids'); $oldIds = $oldChannels != false ? explode(',', $oldChannels[0]) : []; break; default: break; } $admin_where_not_in = $admin_where_in = []; //如果是 add 取差集,如果是 remove 显示老用户 // $allIds = $operate == 'add' ? array_diff($allIds,$oldIds) : $oldIds; if($operate == 'add'){ $admin_where_not_in['admin.id'] = ['NOT IN', $oldIds]; }else{ $admin_where_in['admin.id'] = ['IN', $oldIds]; } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->modelAdmin ->join("auth_group_access", "admin.id = auth_group_access.uid", "inner") ->where($where) ->where($admin_where_not_in) ->where($admin_where_in) ->where('auth_group_access.group_id', 'in',$groupIds) ->order($sort, $order) ->count(); $list = $this->modelAdmin ->join("auth_group_access", "admin.id = auth_group_access.uid", "inner") ->where($where) ->where($admin_where_not_in) ->where($admin_where_in) ->where('auth_group_access.group_id', 'in',$groupIds) ->field(['password', 'salt', 'token'], true) ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as $k => &$v) { $groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : []; $v['groups'] = implode(',', array_keys($groups)); $v['groups_text'] = implode(',', array_values($groups)); } unset($v); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } }