postData(); $accessList = ModelApplication_category::getAll(); $applicList = ApplicModel::getListByClientId($data['client_id']); return $this->renderSuccess('', compact('accessList','applicList')); } /** * 绑定应用 */ public function bangApplic() { $data = json_decode($this->postData()['params'], true); //代理商扣款 // 代理商详情 $AgentModel = AgentModel::detail($data['agent_id']); if($AgentModel['balance']<$data['applic_info']['supplier_money']){ return $this->renderError($AgentModel->getError() ?: '代理商余额不足'); } $money=$data['applic_info']['shop']; if($AgentModel['level']==1){ $money=$data['applic_info']['supplier_money']; }else if($AgentModel['level']==2){ $money=$data['applic_info']['admin_money']; } $source=0; $params=array( "balance"=>array( "mode"=> 'dec', "money"=>$money, "remark"=> '绑定应用;应用名称:'.$data['applic_info']['app_name'].';客户名称:'.$data['client_name'], ) ); if ($AgentModel->recharge($AgentModel['agent_name'], $source, $params)) { $model = new ApplicModel; // 新增记录 $i=$model->save([ 'client_id' => $data['client_id'], 'applic_id' => $data['applic_info']['id'], 'agent_id' => $data['agent_id'] ]); // 新增权限 $RoleAccessModel = new RoleAccessModel(); $arr=[]; foreach($data['applic_info']['access'] as $key=>$value){ $Model=$RoleAccessModel; $item=$Model->where('client_id','=',$data['client_id'])->where('access_id','=',$value['access_id'])->find(); if(empty($item)){ $arr[]=[ 'role_id'=>$data['role']['role_id'], 'access_id'=>$value['access_id'], 'app_id'=>$data['app']['app_id'], 'client_id'=>$data['client_id'] ]; } } $RoleAccessModel->saveAll($arr); if($i){ return $this->renderSuccess('操作成功'); } } return $this->renderError($model->getError() ?: '操作失败'); } /** * 获取角色菜单信息 */ public function getRoleList() { $user_info = $this->postData(); if ($user_info['is_super'] == 1) { $model = new AccessModel(); $menus = $model->getList(); } else { $model = new AccessModel(); $menus = $model->getListByUser($user_info['shop_user_id']); foreach ($menus as $key => $val) { if ($val['redirect_name'] != $val['children'][0]['path']) { $menus[$key]['redirect_name'] = $menus[$key]['children'][0]['path']; } } } return $this->renderSuccess('', compact('menus')); } public function getApplicRole($id){ $model =ApplicationModel::detail($id); $select_menu = array_column($model->toArray()['access'], 'access_id'); $AccessModel = new AccessModel(); $menus = $AccessModel->getListByApplic($select_menu); return $this->renderSuccess('', compact('menus')); } /** * 添加到分类 */ public function editApplic() { $data=$this->postData(); $applicList = ApplicModel::getListByClientId($data['client_id']); $n=0; if(!empty($data['applic_arr'])){ $applic_arr=$data['applic_arr']; foreach ($applicList as $item) { if(!in_array($item['applic_id'],$data['applic_arr'])){ $model = ApplicModel::detail($item['id']); $model->setDelete(); $n=$n+1; }else{ } } foreach($applic_arr as $k=>$v) { $detail = ApplicModel::getListByApplicId($data['client_id'],$v); if(count($detail)==0){ $model = new ApplicModel; // 新增记录 $model->save([ 'client_id' => $data['client_id'], 'applic_id' => $v, 'agent_id' => $data['agent_id'] ]); $n=$n+1; } } } return $this->renderSuccess('保存成功'); } /** * 添加商城 */ public function addShop() { $data=$this->postData(); $arr = [ 'app_name' => $data['app_name'], 'client_id' => $data['client_id'], 'no_expire' => true, 'weixin_service' => false ]; $arr['password']=$this->make_coupon_card(); $arr['password_confirm']=$arr['password']; $arr['user_name']=$arr['app_name']; $model = new AppModel; // 新增商城,主管理员记录 if ($model->add($arr,$data['client_id'])) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } //生成8位随机码 : public function make_coupon_card() { $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $rand = $code[rand(0,25)] .strtoupper(dechex(date('m'))) .date('d').substr(time(),-5) .substr(microtime(),2,5) .sprintf('%02d',rand(0,99)); for( $a = md5( $rand, true ), $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV', $d = '', $f = 0; $f < 8; $g = ord( $a[ $f ] ), $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ], $f++ ); return $d; } /** * 客户详情 */ public function getClientDetail($client_id) { $data = ClientModel::detail($client_id); $agentInfo = AgentModel::detail($data['agent_id']); return $this->renderSuccess('', compact('data','agentInfo')); } }