auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)){ $is_distributor = AdminService::instance()->checkAdminIsDistributor($this->auth->id); // 如果登录用户仅仅是代理商,不是配号代理商 if (!$is_distributor) { $this->error('您没有访问权限'); } } $this->model = model('SendMessageMaterialLibrary'); $this->view->assign("messageTypeList", $this->model->getMessageTypeList()); $this->view->assign("userGroupIds", $this->auth->getGroupIds()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法 * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } //用户组 // $whereauth = []; // if( // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT) || // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) || // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) || // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_OPERATOR) // ){ // $whereauth['admin_id'] = ['eq',$this->auth->id]; // }elseif( // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP) || // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR) // ){ // $wheretmp['flag'] = ['eq',1]; // $wheretmp['admin_id_master'] = ['eq',$this->auth->id]; // $vab_ids = model('vip_admin_bind')->where($wheretmp)->column('admin_id_slave'); // if(count($vab_ids) == 1){ // $whereauth['admin_id'] = ['eq',$vab_ids[0]]; // }else{ // $whereauth['admin_id'] = ['in',implode(',',$vab_ids)]; // } // } $whereauth['admin_id'] = ['eq',$this->auth->id]; list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $total = $this->model ->where($where) ->where($whereauth) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where($whereauth) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { $time = time(); if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { try { $this->_submitFormVerify($params); if(isset($params['test_message'])){ unset($params['test_message']); } if(isset($params['test_channel_id'])){ unset($params['test_channel_id']); } $params['material_status'] = 1; $params['createtime'] = $time; $params['updatetime'] = $time; $params['admin_id'] = $this->auth->id; $result = $this->model->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } public function do_status(){ $params = $this->request->param(); $ids = $params['ids']; if(is_array($ids)){ foreach($ids as $id){ $result = $this->model->where('id','eq',$id)->delete(); } }else{ $result = $this->model->where('id','eq',$ids)->delete(); } if($result){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } /** * 编辑 */ public function edit($ids = NULL) { $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { try { $this->_submitFormVerify($params); if(isset($params['test_message'])){ unset($params['test_message']); } if(isset($params['test_channel_id'])){ unset($params['test_channel_id']); } $params['updatetime'] = time(); $params['admin_id'] = $this->auth->id; $result = $row->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $row['material_content_arr'] = json_decode($row['material_content'],true); $this->view->assign("row", $row); return $this->view->fetch(); } /** * 消息预览 */ public function message_preview($ids = NULL){ $row = $this->model->get($ids); if (!$row){ $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } $row['message_type'] = $row['material_type']; $row['message_content_arr'] = json_decode($row['material_content'],true); $this->view->assign("row", $row); return $this->view->fetch(); } private function _submitFormVerify($params){ if(empty($params['material_name'])){ $this->error('推送消息名称不能为空'); } if(empty($params['material_type'])){ $this->error('公众号类型不能为空'); } if(empty($params['material_content']) || $params['material_content']=='[]'){ $this->error('消息内容不能为空'); } } }