123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- namespace app\admin\controller\send\message;
- use app\common\controller\Backend;
- use app\main\service\AdminService;
- use app\main\constants\AdminConstants;
- use think\Controller;
- use think\Request;
- /**
- * 高级群发消息素材库
- *
- * @icon fa fa-circle-o
- */
- class Materiallibrary extends Backend
- {
- /**
- * SendMessageMaterialLibrary模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- if($this->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('消息内容不能为空');
- }
- }
- }
|