Vipsubscribedelay.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2020/3/23
  6. * Time: 下午5:51
  7. */
  8. namespace app\admin\controller\wechat;
  9. use app\common\controller\Backend;
  10. use app\main\constants\ErrorCodeConstants;
  11. use app\main\constants\SubscribeDelayConstants;
  12. use app\main\service\AdminService;
  13. use app\main\service\MiniProgramService;
  14. use app\main\service\SubscribeVipDelayService;
  15. class Vipsubscribedelay extends Backend
  16. {
  17. protected $noNeedRight = ['index'];
  18. public function index()
  19. {
  20. $data = model('subscribe_delay_push')->where('status', 'normal')->where('admin_id', $this->auth->id)->select();
  21. usort($data, function($v1, $v2){
  22. if ($v1['type'] == '1') {
  23. $v1Delay = $v1['delay'];
  24. } else {
  25. $v1Delay = $v1['delay'] * 60;
  26. }
  27. if ($v2['type'] == '1') {
  28. $v2Delay = $v2['delay'];
  29. } else {
  30. $v2Delay = $v2['delay'] * 60;
  31. }
  32. if ($v1Delay > $v2Delay) {
  33. return 1;
  34. }
  35. });
  36. $return = [];
  37. $groups = [];
  38. $miniOpen = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
  39. foreach ($data as $index=>$item) {
  40. $tmp_data = json_decode($item['news_set'], true);
  41. if (isset($tmp_data['deploy_type']) && ($tmp_data['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP)) {
  42. $groups = array_merge($groups, $tmp_data['admin_group']);
  43. }
  44. $tmp_data['selected'] = [];
  45. $tmp_data['channelGroupList'] = [];
  46. $tmp_data['content_type'] = $item['content_type']??1;
  47. $tmp_data['id'] = $item['id'];
  48. $tmp_data['mini_open'] = 1;
  49. $tmp_data['text_tip_word'] = $tmp_data['text_tip_word'] ?? '欢迎关注「$gzh_name」,点击下方继续阅读';
  50. $tmp_data['mobile_system'] = $tmp_data['mobile_system']??0;
  51. $tmp_data['user_type'] = $tmp_data['user_type']??1;
  52. $tmp_data['text_content'] = $tmp_data['text_content'] ?? [];
  53. $tmp_data['is_sign'] = (int)($tmp_data['is_sign'] ?? 1);
  54. $tmp_data['sex'] = (int)($tmp_data['sex'] ?? 0);
  55. $return[] = $tmp_data;
  56. }
  57. if ($groups) {
  58. $groupList = model('vip_group')->whereIn('id', $groups)->column('id,id,name,createtime,updatetime');
  59. foreach ($return as $index=>$tmp_data){
  60. if (isset($tmp_data['deploy_type']) && ($tmp_data['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP)) {
  61. foreach($tmp_data['admin_group'] as $groupId){
  62. if (array_key_exists($groupId, $groupList)) {
  63. $tmp_data['selected'][$groupId] = $groupList[$groupId];
  64. $tmp_data['channelGroupList'][] = $groupList[$groupId];
  65. }
  66. }
  67. }
  68. $return[$index] = $tmp_data;
  69. }
  70. }
  71. if ($this->request->isPost()) {
  72. return json([
  73. 'data' => $return,
  74. 'mini_open'=> $miniOpen,
  75. ]);
  76. }
  77. $this->assignconfig('mini_open',$miniOpen);
  78. $this->assignconfig('data', $return);
  79. return $this->view->fetch();
  80. }
  81. public function add()
  82. {
  83. $params = json_decode($this->request->post('data'), true);
  84. $params['admin_group'] = [];
  85. $params['deploy_type'] = (int)$params['deploy_type'];
  86. if ($params['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP) {
  87. $params['admin_group'] = [];
  88. foreach ($params['selected'] as $index=>$value) {
  89. if ($value) {
  90. $params['admin_group'][] = $index;
  91. }
  92. }
  93. }
  94. if ($params['content_type'] == 2 && empty($params['text_content'])){
  95. $this->error('文本消息不能为空');
  96. }
  97. $result = SubscribeVipDelayService::instance()->createDelayReply($params, $this->auth->id);
  98. if ($result->code == ErrorCodeConstants::SUCCESS) {
  99. $this->success('','', ['id' => $result->data]);
  100. } else {
  101. $this->error($result->msg);
  102. }
  103. }
  104. /**
  105. * 删除
  106. */
  107. public function delete($ids = "")
  108. {
  109. model('subscribe_delay_push')->where('id', $ids)
  110. ->update(['status' => 'hidden']);
  111. $channel_ids = AdminService::instance()->getAdminId($this->auth->id)->data;
  112. //清除缓存
  113. foreach ($channel_ids as $channel_id) {
  114. model('subscribe_delay_push')->delCache($channel_id);
  115. }
  116. $this->success();
  117. }
  118. }