123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace app\admin\controller\send\message;
- use app\admin\service\ExclusiveService;
- use app\common\controller\Backend;
- use app\main\constants\AdminConstants;
- use app\main\constants\BookConstants;
- use app\main\service\MiniProgramService;
- use think\Controller;
- use think\db\Query;
- use think\Request;
- /**
- * 高级群发消息图文消息
- *
- * @icon fa fa-circle-o
- */
- class Imgtext extends Backend
- {
- protected $noNeedRight = ['autocompletebookname'];
-
- /**
- * SendMessageImgtext模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- }
-
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- /*
- * 已经弃用,如果为了兼容老版可取消注释
- foreach ($params as $k => &$v)
- {
- $v = is_array($v) ? implode(',', $v) : $v;
- }
- */
- if ($this->dataLimit)
- {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- $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', ''));
- }
- $wheres['state'] = 1;
- $wheres['cansee'] = 1;
- $books = model("Book")->where($wheres)->field('id,name')->select();
- $isWrite = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
- $this->assign('isWrite',$isWrite);
- $this->view->assign("bookList", $books);
- $notids = [];
- ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$notids);
- $this->assignconfig('notids',$notids);
- return $this->view->fetch();
- }
-
- public function getactivity(){
- if($this->request->isAjax()){
- $current_time = time();
- $model = model('activity');
- if(
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) ||
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_OPERATOR)
- ){
- $where['is_system'] = 1;
- $where['type'] = 0;
- }
- elseif(
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP) ||
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR)
- ){
- $where['admin_id'] = $this->auth->id;
- $where['type'] = 1;
- }
- elseif(
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) ||
- $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)
- ){
- $where['admin_id'] = $this->auth->id;
- $where['type'] = 1;
- }
- $where['starttime'] = ['<=',$current_time];
- $where['endtime'] = ['>',$current_time];
- $where['status'] = 1;
- $list = $model->where($where)->order('id','desc')->field('id,name')->select();
- return json($list);
- }
- }
- public function getcampaign(){
- if($this->request->isAjax()){
- $current_time = time();
- $model = model('campaign_read');
- $where['start_time'] = ['<=',$current_time];
- $where['end_time'] = ['>',$current_time];
- $where['status'] = 'normal';
- $list = $model->where($where)->order('id','desc')->field('id,name')->select();
- return json($list);
- }
- }
- public function getchapter(){
- if($this->request->isAjax()) {
- $bookId = $this->request->request('book_id');
- $chapters = model("Book")::getChapterLimit($bookId, 0, 9);
- if(!empty($chapters)){
- return json($chapters);
- }else{
- return [];
- }
- }
- }
- public function getbook(){
- if($this->request->isAjax()) {
- $where['state'] = 1;
- $where['cansee'] = 1;
- $books = model("Book")->where($where)->field('id,name')->select();
- if(!empty($books)){
- return json($books);
- }else{
- return [];
- }
- }
- }
- public function autocompletebookname()
- {
- if ($this->request->isAjax()) {
- $keyword = $this->request->post('name') ?? $this->request->param('pkey_value');
- $data = [];
- $keyword = trim($keyword);
- $bookModel = model('Book');
- $map = [];
- if ($this->group > 2) {
- $map['cansee'] = 1;
- }
- //获取独家书籍id
- ExclusiveService::instance()->getExclusiveNotidsWithWhere($this->group, $this->auth->id,$map);
- if (!empty($keyword)) {
- $bookList = $bookModel
- ->where('state', 'neq', BookConstants::BOOK_STATE_OFF_SALE)
- ->where($map)
- ->where(function (Query $query) use ($keyword) {
- $query->where('name', 'like', "%{$keyword}%")
- ->whereOr('id', $keyword);
- })
- ->limit(0, 6)->select();
- } else {
- $bookList = $bookModel->where('state', 'neq',
- BookConstants::BOOK_STATE_OFF_SALE)->where($map)->order('book.idx desc,book.idxx desc')->limit(0, 6)->select();
- }
- $data = $bookList;
- return json(['list' => $data, 'total' => count($data)]);
- }
- }
- }
|