Imgtext.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\admin\controller\send\message;
  3. use app\admin\service\ExclusiveService;
  4. use app\common\controller\Backend;
  5. use app\main\constants\AdminConstants;
  6. use app\main\constants\BookConstants;
  7. use app\main\service\MiniProgramService;
  8. use think\Controller;
  9. use think\db\Query;
  10. use think\Request;
  11. /**
  12. * 高级群发消息图文消息
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class Imgtext extends Backend
  17. {
  18. protected $noNeedRight = ['autocompletebookname'];
  19. /**
  20. * SendMessageImgtext模型对象
  21. */
  22. protected $model = null;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 添加
  34. */
  35. public function add()
  36. {
  37. if ($this->request->isPost())
  38. {
  39. $params = $this->request->post("row/a");
  40. if ($params)
  41. {
  42. /*
  43. * 已经弃用,如果为了兼容老版可取消注释
  44. foreach ($params as $k => &$v)
  45. {
  46. $v = is_array($v) ? implode(',', $v) : $v;
  47. }
  48. */
  49. if ($this->dataLimit)
  50. {
  51. $params[$this->dataLimitField] = $this->auth->id;
  52. }
  53. try
  54. {
  55. //是否采用模型验证
  56. if ($this->modelValidate)
  57. {
  58. $name = basename(str_replace('\\', '/', get_class($this->model)));
  59. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  60. $this->model->validate($validate);
  61. }
  62. $result = $this->model->allowField(true)->save($params);
  63. if ($result !== false)
  64. {
  65. $this->success();
  66. }
  67. else
  68. {
  69. $this->error($this->model->getError());
  70. }
  71. }
  72. catch (\think\exception\PDOException $e)
  73. {
  74. $this->error($e->getMessage());
  75. }
  76. }
  77. $this->error(__('Parameter %s can not be empty', ''));
  78. }
  79. $wheres['state'] = 1;
  80. $wheres['cansee'] = 1;
  81. $books = model("Book")->where($wheres)->field('id,name')->select();
  82. $isWrite = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
  83. $this->assign('isWrite',$isWrite);
  84. $this->view->assign("bookList", $books);
  85. $notids = [];
  86. ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$notids);
  87. $this->assignconfig('notids',$notids);
  88. return $this->view->fetch();
  89. }
  90. public function getactivity(){
  91. if($this->request->isAjax()){
  92. $current_time = time();
  93. $model = model('activity');
  94. if(
  95. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) ||
  96. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_OPERATOR)
  97. ){
  98. $where['is_system'] = 1;
  99. $where['type'] = 0;
  100. }
  101. elseif(
  102. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP) ||
  103. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR)
  104. ){
  105. $where['admin_id'] = $this->auth->id;
  106. $where['type'] = 1;
  107. }
  108. elseif(
  109. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) ||
  110. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)
  111. ){
  112. $where['admin_id'] = $this->auth->id;
  113. $where['type'] = 1;
  114. }
  115. $where['starttime'] = ['<=',$current_time];
  116. $where['endtime'] = ['>',$current_time];
  117. $where['status'] = 1;
  118. $list = $model->where($where)->order('id','desc')->field('id,name')->select();
  119. return json($list);
  120. }
  121. }
  122. public function getcampaign(){
  123. if($this->request->isAjax()){
  124. $current_time = time();
  125. $model = model('campaign_read');
  126. $where['start_time'] = ['<=',$current_time];
  127. $where['end_time'] = ['>',$current_time];
  128. $where['status'] = 'normal';
  129. $list = $model->where($where)->order('id','desc')->field('id,name')->select();
  130. return json($list);
  131. }
  132. }
  133. public function getchapter(){
  134. if($this->request->isAjax()) {
  135. $bookId = $this->request->request('book_id');
  136. $chapters = model("Book")::getChapterLimit($bookId, 0, 9);
  137. if(!empty($chapters)){
  138. return json($chapters);
  139. }else{
  140. return [];
  141. }
  142. }
  143. }
  144. public function getbook(){
  145. if($this->request->isAjax()) {
  146. $where['state'] = 1;
  147. $where['cansee'] = 1;
  148. $books = model("Book")->where($where)->field('id,name')->select();
  149. if(!empty($books)){
  150. return json($books);
  151. }else{
  152. return [];
  153. }
  154. }
  155. }
  156. public function autocompletebookname()
  157. {
  158. if ($this->request->isAjax()) {
  159. $keyword = $this->request->post('name') ?? $this->request->param('pkey_value');
  160. $data = [];
  161. $keyword = trim($keyword);
  162. $bookModel = model('Book');
  163. $map = [];
  164. if ($this->group > 2) {
  165. $map['cansee'] = 1;
  166. }
  167. //获取独家书籍id
  168. ExclusiveService::instance()->getExclusiveNotidsWithWhere($this->group, $this->auth->id,$map);
  169. if (!empty($keyword)) {
  170. $bookList = $bookModel
  171. ->where('state', 'neq', BookConstants::BOOK_STATE_OFF_SALE)
  172. ->where($map)
  173. ->where(function (Query $query) use ($keyword) {
  174. $query->where('name', 'like', "%{$keyword}%")
  175. ->whereOr('id', $keyword);
  176. })
  177. ->limit(0, 6)->select();
  178. } else {
  179. $bookList = $bookModel->where('state', 'neq',
  180. BookConstants::BOOK_STATE_OFF_SALE)->where($map)->order('book.idx desc,book.idxx desc')->limit(0, 6)->select();
  181. }
  182. $data = $bookList;
  183. return json(['list' => $data, 'total' => count($data)]);
  184. }
  185. }
  186. }