Message.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <?php
  2. namespace app\admin\controller\send\message;
  3. use app\common\controller\Backend;
  4. use app\main\constants\AdminConstants;
  5. use app\main\service\AdminService;
  6. use app\main\service\HigeMessageService;
  7. use app\main\service\MiniProgramService;
  8. use think\Controller;
  9. use think\Log;
  10. use think\Request;
  11. /**
  12. * 高级群发消息
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class Message extends Backend
  17. {
  18. /**
  19. * SendMessage模型对象
  20. */
  21. protected $model = null;
  22. public $processTime = 7200;
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. if($this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)){
  27. $is_distributor = AdminService::instance()->checkAdminIsDistributor($this->auth->id);
  28. // 如果登录用户仅仅是代理商,不是配号代理商
  29. if (!$is_distributor) {
  30. $this->error('您没有访问权限');
  31. }
  32. }
  33. $this->model = model('SendMessage');
  34. $this->view->assign("messageTypeList", $this->model->getMessageTypeList());
  35. $this->view->assign("subscriptionTypeList", $this->model->getSubscriptionTypeList());
  36. $this->view->assign("sendStatusList", $this->model->getSendStatusList());
  37. $this->view->assign("messageStatusList", $this->model->getMessageStatusList());
  38. $this->view->assign("currentMonthCountList", $this->model->getCurrentMonthCountList());
  39. $this->view->assign("isSaveToLibraryList", $this->model->getIsSaveToLibraryList());
  40. $this->view->assign("userGroupIds", $this->auth->getGroupIds());
  41. }
  42. /**
  43. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  44. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  45. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  46. */
  47. /**
  48. * 查看
  49. */
  50. public function index()
  51. {
  52. //设置过滤方法
  53. $this->request->filter(['strip_tags']);
  54. if ($this->request->isAjax())
  55. {
  56. //如果发送的来源是Selectpage,则转发到Selectpage
  57. if ($this->request->request('pkey_name'))
  58. {
  59. return $this->selectpage();
  60. }
  61. //用户组
  62. // $whereauth = [];
  63. // if(
  64. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT) ||
  65. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) ||
  66. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) ||
  67. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_OPERATOR)
  68. // ){
  69. // $whereauth['sm.admin_id'] = ['eq',$this->auth->id];
  70. // }elseif(
  71. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP) ||
  72. // $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR)
  73. // ){
  74. // $wheretmp['flag'] = ['eq',1];
  75. // $wheretmp['admin_id_master'] = ['eq',$this->auth->id];
  76. // $vab_ids = model('vip_admin_bind')->where($wheretmp)->column('admin_id_slave');
  77. // if(count($vab_ids) == 1){
  78. // $whereauth['sm.admin_id'] = ['eq',$vab_ids[0]];
  79. // }else{
  80. // $whereauth['sm.admin_id'] = ['in',implode(',',$vab_ids)];
  81. // }
  82. // }
  83. $whereauth['sm.admin_id'] = ['eq',$this->auth->id];
  84. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  85. $total = $this->model->alias('sm')
  86. ->where($where)
  87. ->where($whereauth)
  88. ->order($sort, $order)
  89. ->count();
  90. $list = $this->model->alias('sm')
  91. ->join('send_user_group sug','sm.user_group_ids=sug.id','left')
  92. ->where($where)
  93. ->where($whereauth)
  94. ->field('sm.*,sug.group_type')
  95. ->order($sort, $order)
  96. ->limit($offset, $limit)
  97. ->select();
  98. $result = array("total" => $total, "rows" => $list);
  99. return json($result);
  100. }
  101. return $this->view->fetch();
  102. }
  103. /**
  104. * 添加
  105. */
  106. public function add()
  107. {
  108. if ($this->request->isPost())
  109. {
  110. $params = $this->request->post("row/a");
  111. if ($params)
  112. {
  113. try
  114. {
  115. $this->_submitFormVerify($params);
  116. //公众号类型,如果是渠道商或代理商自己,不需要选择公众号
  117. if(
  118. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) ||
  119. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)
  120. ){
  121. $params['subscription_ids'] = $this->auth->id;
  122. }
  123. if(isset($params['test_message'])){
  124. unset($params['test_message']);
  125. }
  126. if(isset($params['test_channel_id'])){
  127. unset($params['test_channel_id']);
  128. }
  129. //全部公众号
  130. if(isset($params['subscription_type'])){
  131. if($params['subscription_type'] == 1){
  132. $bl = model('SendAdminBlack')->column('admin_id');
  133. if(!empty($bl)){
  134. $whereall['admin_id'] = ['neq',$bl[0]];
  135. if(count($bl) == 1){
  136. $whereall['admin_id'] = ['neq',$bl[0]];
  137. }else{
  138. $whereall['admin_id'] = ['not in',implode(',',$bl)];
  139. }
  140. }else{
  141. $whereall = [];
  142. }
  143. $admin_ids = model("admin_config")
  144. ->join('admin a','admin_id= a.id','left')
  145. ->where('json','neq','')
  146. ->where($whereall)
  147. ->order('admin_id', 'desc')
  148. ->column('admin_id');
  149. if(empty($admin_ids)){
  150. $this->error('公众号列表出错');
  151. }
  152. $params['subscription_ids'] = implode(',',$admin_ids);
  153. }
  154. }
  155. $time = time();
  156. //存入素材库
  157. if($params['is_save_to_library'] == 1){
  158. $lib['material_name'] = $params['message_name'];
  159. $lib['material_type'] = $params['message_type'];
  160. $lib['material_status'] = 1;
  161. $lib['material_content'] = $params['message_content'];
  162. $lib['createtime'] = $time;
  163. $lib['updatetime'] = $time;
  164. $lib['admin_id'] = $this->auth->id;
  165. model('SendMessageMaterialLibrary')->save($lib);
  166. }
  167. $params['send_status'] = 1;
  168. $params['send_time'] = strtotime($params['send_time']);
  169. $params['createtime'] = $time;
  170. $params['updatetime'] = $time;
  171. $params['admin_id'] = $this->auth->id;
  172. if(!empty($params['current_month_count'])){
  173. foreach($params['current_month_count'] as &$cu){
  174. $cu = $cu-1;
  175. }
  176. }
  177. $params['current_month_count'] = implode(',', $params['current_month_count']);
  178. $result = $this->model->allowField(true)->save($params);
  179. if ($result !== false)
  180. {
  181. $this->success();
  182. }
  183. else
  184. {
  185. $this->error($this->model->getError());
  186. }
  187. }
  188. catch (\think\exception\PDOException $e)
  189. {
  190. $this->error($e->getMessage());
  191. }
  192. }
  193. $this->error(__('Parameter %s can not be empty', ''));
  194. }
  195. return $this->view->fetch();
  196. }
  197. /**
  198. * 编辑
  199. */
  200. public function edit($ids = NULL)
  201. {
  202. $row = $this->model->get($ids);
  203. if (!$row){
  204. $this->error(__('No Results were found'));
  205. }
  206. $current = explode(',',$row['current_month_count']);
  207. foreach($current as &$ii){
  208. $ii = $ii + 1;
  209. }
  210. $row['current_month_count'] = implode(',',$current);
  211. $row['current_month_count'] = rtrim($row['current_month_count'],',');
  212. if (!$row){
  213. $this->error(__('No Results were found'));
  214. }
  215. $time = time();
  216. $adminIds = $this->getDataLimitAdminIds();
  217. if (is_array($adminIds))
  218. {
  219. if (!in_array($row[$this->dataLimitField], $adminIds))
  220. {
  221. $this->error(__('You have no permission'));
  222. }
  223. }
  224. if ($this->request->isPost())
  225. {
  226. $params = $this->request->post("row/a");
  227. if ($params)
  228. {
  229. try
  230. {
  231. $this->_submitFormVerify($params);
  232. //公众号类型,如果是渠道商自己,不需要选择公众号
  233. if(
  234. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) ||
  235. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)
  236. ){
  237. $params['subscription_ids'] = $this->auth->id;
  238. }
  239. if(isset($params['test_message'])){
  240. unset($params['test_message']);
  241. }
  242. if(isset($params['test_channel_id'])){
  243. unset($params['test_channel_id']);
  244. }
  245. //全部公众号
  246. if(isset($params['subscription_type'])){
  247. if($params['subscription_type'] == 1){
  248. $bl = model('SendAdminBlack')->column('admin_id');
  249. if(!empty($bl)){
  250. $whereall['admin_id'] = ['neq',$bl[0]];
  251. if(count($bl) == 1){
  252. $whereall['admin_id'] = ['neq',$bl[0]];
  253. }else{
  254. $whereall['admin_id'] = ['not in',implode(',',$bl)];
  255. }
  256. }else{
  257. $whereall = [];
  258. }
  259. $admin_ids = model("admin_config")
  260. ->join('admin a','admin_id= a.id','left')
  261. ->where('json','neq','')
  262. ->where($whereall)
  263. ->order('admin_id', 'desc')
  264. ->column('admin_id');
  265. if(empty($admin_ids)){
  266. $this->error('公众号列表出错');
  267. }
  268. $params['subscription_ids'] = implode(',',$admin_ids);
  269. }
  270. }
  271. //存入素材库
  272. if($params['is_save_to_library'] == 1){
  273. $lib['material_name'] = $params['message_name'];
  274. $lib['material_type'] = $params['message_type'];
  275. $lib['material_status'] = 1;
  276. $lib['material_content'] = $params['message_content'];
  277. $lib['createtime'] = $time;
  278. $lib['updatetime'] = $time;
  279. $lib['admin_id'] = $this->auth->id;
  280. model('SendMessageMaterialLibrary')->save($lib);
  281. }
  282. $params['send_status'] = 1;
  283. $params['send_time'] = strtotime($params['send_time']);
  284. $params['updatetime'] = $time;
  285. $params['admin_id'] = $this->auth->id;
  286. if(!empty($params['current_month_count'])){
  287. foreach($params['current_month_count'] as &$cu){
  288. $cu = $cu-1;
  289. }
  290. }
  291. $params['current_month_count'] = implode(',',$params['current_month_count']);
  292. $result = $row->allowField(true)->save($params);
  293. if ($result !== false)
  294. {
  295. $this->success();
  296. }
  297. else
  298. {
  299. $this->error($row->getError());
  300. }
  301. }
  302. catch (\think\exception\PDOException $e)
  303. {
  304. $this->error($e->getMessage());
  305. }
  306. }
  307. $this->error(__('Parameter %s can not be empty', ''));
  308. }
  309. if(count(explode(',',$row['subscription_ids'])) == 1){
  310. $wheresub['admin_id'] = ['eq',$row['subscription_ids']];
  311. }else{
  312. $wheresub['admin_id'] = ['in',$row['subscription_ids']];
  313. }
  314. $whereuser['id'] = ['eq',$row['user_group_ids']];
  315. $sublist = model('AdminConfig')
  316. ->join('admin a','admin_id= a.id','left')
  317. ->where($wheresub)
  318. ->field(['a.username,a.nickname,admin_id'])
  319. ->field(['REPLACE (JSON_EXTRACT(JSON_EXTRACT( admin_config.json, "$.authorizer_info"),"$.nick_name"), "\"", "")' => 'sub_nickname'])
  320. ->order('admin_id', 'desc')
  321. ->select();
  322. $usergroup = model('SendUserGroup')
  323. ->where($whereuser)
  324. ->order('id', 'desc')
  325. ->select();
  326. $row['message_content_arr'] = json_decode($row['message_content'],true);
  327. $this->view->assign("row", $row);
  328. $this->view->assign("sublist", $sublist);
  329. $this->view->assign("usergroup", $usergroup);
  330. return $this->view->fetch();
  331. }
  332. /**
  333. * 修改状态
  334. */
  335. public function do_status(){
  336. $params = $this->request->param();
  337. $ids = $params['ids'];
  338. $message_status = $params['message_status'];
  339. $time = time();
  340. if(is_array($ids)){
  341. foreach($ids as $id){
  342. $row = $this->model->get($id);
  343. $res = $this->_handlerVerify($message_status,$row,$time);
  344. if($res['code'] == 0){
  345. $this->error($res['msg'],'/admin/send/message/message');
  346. }
  347. if($message_status==1){//生效
  348. $result = $this->model->update(['message_status'=>$message_status,'updatetime'=>$time,'admin_id'=>$this->auth->id],['id'=>$id]);
  349. }elseif($message_status==2){//失效
  350. if(!in_array($row['send_status'],[1,2])){
  351. $result = 1;
  352. }else{
  353. $result = $this->model->update(['message_status'=>$message_status,'updatetime'=>$time,'admin_id'=>$this->auth->id],['id'=>$id]);
  354. }
  355. }elseif($message_status==3){
  356. if(!in_array($row['send_status'],[1,2])){
  357. $result = 1;
  358. }else{
  359. $result = $this->model->update(['message_status'=>$message_status,'updatetime'=>$time,'admin_id'=>$this->auth->id],['id'=>$id]);
  360. }
  361. }
  362. }
  363. }else{
  364. $row = $this->model->get($ids);
  365. $res = $this->_handlerVerify($message_status,$row,$time);
  366. if($res['code'] == 0){
  367. $this->error($res['msg'],'/admin/send/message/message');
  368. }
  369. if($message_status==1){
  370. $result = $this->model->update(['message_status'=>$message_status,'updatetime'=>$time,'admin_id'=>$this->auth->id],['id'=>$ids]);
  371. }elseif($message_status==2) {
  372. if (!in_array($row['send_status'], [1, 2])) {
  373. $result = 1;
  374. } else {
  375. $result = $this->model->update(['message_status' => $message_status, 'updatetime' => $time, 'admin_id' => $this->auth->id], ['id' => $ids]);
  376. }
  377. }elseif($message_status==3){
  378. if (!in_array($row['send_status'], [1, 2])) {
  379. $result = 1;
  380. } else {
  381. $result = $this->model->update(['message_status' => $message_status, 'updatetime' => $time, 'admin_id' => $this->auth->id], ['id' => $ids]);
  382. }
  383. }
  384. }
  385. if($result){
  386. $this->success('设置成功');
  387. }else{
  388. $this->error('设置失败');
  389. }
  390. }
  391. /**
  392. * 删除微信历史消息
  393. */
  394. public function del_wx_previous_news()
  395. {
  396. $params = $this->request->param();
  397. $ids = $params['ids'];
  398. $send_status = $params['send_status'];
  399. $del_ids = model('send_message')->alias('sm')
  400. ->join('send_channel_message scm','sm.id=scm.mass_id','left')
  401. ->where('sm.id','eq',$ids)
  402. ->where('sm.send_status','eq',5)
  403. ->where('sm.message_status','eq',1)
  404. ->where('scm.send_status','eq',2)
  405. ->where('scm.wx_msg_id','neq','')
  406. ->field('scm.channel_id,scm.wx_msg_id')
  407. ->select();
  408. Log::info('删除微信历史关系id:'.json_encode($del_ids, JSON_UNESCAPED_UNICODE).'删除微信历史消息sql:'.model('send_message')->getLastSql() . ",message_id: ".$ids);
  409. if(empty($del_ids)){
  410. $this->error('消息错误,请检查');
  411. }else{
  412. $error = 0;
  413. foreach($del_ids as $id){
  414. $res = HigeMessageService::instance()->delWechatHistoryMessage($id['channel_id'],$id['wx_msg_id']);
  415. if ($res['errmsg'] != 'ok') {
  416. Log::error("删除微信历史消息失败:res:". json_encode($res, JSON_UNESCAPED_UNICODE) . "msgId: {$id['wx_msg_id']}");
  417. $error++;
  418. }
  419. }
  420. if($error>0){
  421. $this->error('删除失败');
  422. }
  423. $result = $this->model->update(['send_status'=>$send_status,'updatetime'=>time(),'admin_id'=>$this->auth->id],['id'=>$ids]);
  424. if($result){
  425. $this->success('删除成功');
  426. }else{
  427. $this->error('删除失败');
  428. }
  429. }
  430. }
  431. /**
  432. * 消息预览
  433. */
  434. public function message_preview($ids = NULL){
  435. $row = $this->model->get($ids);
  436. if (!$row){
  437. $this->error(__('No Results were found'));
  438. }
  439. $adminIds = $this->getDataLimitAdminIds();
  440. if (is_array($adminIds))
  441. {
  442. if (!in_array($row[$this->dataLimitField], $adminIds))
  443. {
  444. $this->error(__('You have no permission'));
  445. }
  446. }
  447. $row['message_content_arr'] = json_decode($row['message_content'],true);
  448. $this->view->assign("row", $row);
  449. return $this->view->fetch();
  450. }
  451. /**
  452. * 带素材添加
  453. */
  454. public function add_with_material($ids = NULL)
  455. {
  456. $model = model('SendMessageMaterialLibrary');
  457. if ($this->request->isPost())
  458. {
  459. $params = $this->request->post("row/a");
  460. if ($params)
  461. {
  462. if ($this->dataLimit)
  463. {
  464. $params[$this->dataLimitField] = $this->auth->id;
  465. }
  466. try
  467. {
  468. $this->_submitFormVerify($params,true);
  469. //是否采用模型验证
  470. if ($this->modelValidate)
  471. {
  472. $name = basename(str_replace('\\', '/', get_class($this->model)));
  473. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  474. $this->model->validate($validate);
  475. }
  476. //公众号类型,如果是渠道商自己,不需要选择公众号
  477. if($this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL)){
  478. $params['subscription_ids'] = $this->auth->id;
  479. }
  480. //全部公众号
  481. if(isset($params['subscription_type']) && $params['subscription_type'] == 1){
  482. $admin_ids = model("admin_config")
  483. ->join('admin a','admin_id= a.id','left')
  484. ->where('json','neq','')
  485. ->order('admin_id', 'desc')
  486. ->column('admin_id');
  487. if(empty($admin_ids)){
  488. $this->error('公众号列表出错');
  489. }
  490. $id_str = rtrim(',',implode(',',$admin_ids));
  491. $params['subscription_ids'] = $id_str;
  492. }
  493. if(empty($params['message_content_id'])){
  494. $this->error('参数错误');
  495. }
  496. $mrow = $model->get($params['message_content_id']);
  497. $params['message_content'] = $mrow['material_content'];
  498. $params['message_type'] = $mrow['material_type'];
  499. $time = time();
  500. $params['is_save_to_library'] = 2;
  501. $params['send_status'] = 1;
  502. $params['send_time'] = strtotime($params['send_time']);
  503. $params['createtime'] = $time;
  504. $params['updatetime'] = $time;
  505. $params['admin_id'] = $this->auth->id;
  506. if(!empty($params['current_month_count'])){
  507. foreach($params['current_month_count'] as &$cu){
  508. $cu = $cu-1;
  509. }
  510. }
  511. $params['current_month_count'] = implode(',', $params['current_month_count']);
  512. $result = $this->model->allowField(true)->save($params);
  513. if ($result !== false)
  514. {
  515. $this->success();
  516. }
  517. else
  518. {
  519. $this->error($this->model->getError());
  520. }
  521. }
  522. catch (\think\exception\PDOException $e)
  523. {
  524. $this->error($e->getMessage());
  525. }
  526. }
  527. $this->error(__('Parameter %s can not be empty', ''));
  528. }
  529. $row = $model->get($ids);
  530. if (!$row){
  531. $this->error(__('No Results were found'));
  532. }
  533. $adminIds = $this->getDataLimitAdminIds();
  534. if (is_array($adminIds))
  535. {
  536. if (!in_array($row[$this->dataLimitField], $adminIds))
  537. {
  538. $this->error(__('You have no permission'));
  539. }
  540. }
  541. $this->view->assign("row", $row);
  542. return $this->view->fetch();
  543. }
  544. /**
  545. * 验证修改
  546. */
  547. public function verifyEdit($ids = NULL){
  548. $time = time();
  549. $row = $this->model->get($ids);
  550. if (!$row){
  551. $this->error('没找到该条记录');
  552. }
  553. if($row['message_status'] == 1 && $row['send_status'] != 1){
  554. $this->error('已经开始处理的消息不支持编辑');
  555. }
  556. $rs = $this->_handlerVerify('',$row,$time);
  557. if($rs['code'] == 0){
  558. $this->error($rs['msg']);
  559. }else{
  560. $this->success($rs['msg'],'',$ids);
  561. }
  562. }
  563. /**
  564. * 测试用户消息
  565. */
  566. public function testMessageToUser(){
  567. $params = $this->request->param();
  568. if(isset($params['message_id'])){
  569. $message = model('SendMessageMaterialLibrary')->get($params['message_id']);
  570. if(empty($message)){
  571. $this->error('素材不存在');
  572. }
  573. $content = json_decode($message['material_content'],true);
  574. $message_type = $message['material_type'];
  575. }else{
  576. $content = $params['message_content'];
  577. $message_type = $params['message_type'];
  578. }
  579. if(!is_numeric($params['user_id'])){
  580. $this->error('用户ID应为纯数字');
  581. }
  582. if(isset($params['channel_id'])){
  583. $channel_id = $params['channel_id'];
  584. }else{
  585. $channel_id = $this->auth->id;
  586. }
  587. $rs = HigeMessageService::instance()->sent([$channel_id], (int)$params['user_id'], (int)$message_type, $content);
  588. if($rs['error'] == 0){
  589. $this->success($rs['msg']);
  590. }else{
  591. $this->error($rs['msg']);
  592. }
  593. }
  594. private function _handlerVerify($message_status = '',$row,$time){
  595. if($row['send_status'] == 4 || $row['send_status'] == 5 ){
  596. return ['code'=>0,'msg'=>'消息状态为发送中、发送完成时不支持切换失效状态'];
  597. }
  598. if(!empty($message_status)){
  599. if($message_status ==1 && $row['send_time'] - $this->processTime < $time){
  600. return ['code'=>0,'msg'=>'消息在发送前两小时不允许生效,请修改后切换状态'];
  601. }
  602. }else{
  603. if($row['message_status']==1 && ($row['send_time'] > $time && ($row['send_time'] - $this->processTime<$time))){
  604. return ['code'=>0,'msg'=>'消息在发送前两小时不允许编辑'];
  605. }
  606. }
  607. return ['code'=>1,'msg'=>'OK'];
  608. }
  609. private function _submitFormVerify($params,$with_material = false){
  610. if(empty($params['message_name'])){
  611. $this->error('推送消息名称不能为空');
  612. }
  613. if(isset($params['message_type']) && empty($params['message_type'])){
  614. $this->error('消息类型不能为空');
  615. }
  616. if(
  617. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN) ||
  618. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_OPERATOR) ||
  619. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP) ||
  620. $this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR)
  621. ){
  622. if(empty($params['subscription_type'])){
  623. $this->error('公众号类型不能为空');
  624. }
  625. }
  626. if(!$this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_CHANNEL) && !$this->auth->checkGroupId(AdminConstants::ADMIN_GROUP_ID_AGENT)){
  627. if($params['subscription_type']==2 && empty($params['subscription_ids'])){
  628. $this->error('公众号ID不能为空');
  629. }
  630. }
  631. if(empty($params['user_group_ids'])){
  632. $this->error('用户组ID不能为空');
  633. }
  634. if(empty($params['current_month_count'])){
  635. $this->error('本月收取消息次数不能为空');
  636. }else{
  637. $n = 0;
  638. foreach($params['current_month_count'] as $c){
  639. if(!empty($c)){
  640. $n++;
  641. }
  642. }
  643. if($n==0){
  644. $this->error('本月收取消息次数不能为空');
  645. }
  646. }
  647. if(empty($params['send_time'])){
  648. $this->error('定时发送时间不能为空');
  649. }else{
  650. if(strtotime($params['send_time']) - $this->processTime < time()){
  651. $this->error('发送时间需大于当前时间的两小时以上');
  652. }
  653. }
  654. if(!$with_material){
  655. if(empty($params['is_save_to_library'])){
  656. $this->error('是否保存至素材库不能为空');
  657. }
  658. if(empty($params['message_content'])){
  659. $this->error('消息内容不能为空');
  660. }
  661. }
  662. }
  663. }