123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2020/3/23
- * Time: 下午5:51
- */
- namespace app\admin\controller\wechat;
- use app\common\controller\Backend;
- use app\main\constants\ErrorCodeConstants;
- use app\main\constants\SubscribeDelayConstants;
- use app\main\service\AdminService;
- use app\main\service\MiniProgramService;
- use app\main\service\SubscribeVipDelayService;
- class Vipsubscribedelay extends Backend
- {
- protected $noNeedRight = ['index'];
- public function index()
- {
- $data = model('subscribe_delay_push')->where('status', 'normal')->where('admin_id', $this->auth->id)->select();
- usort($data, function($v1, $v2){
- if ($v1['type'] == '1') {
- $v1Delay = $v1['delay'];
- } else {
- $v1Delay = $v1['delay'] * 60;
- }
- if ($v2['type'] == '1') {
- $v2Delay = $v2['delay'];
- } else {
- $v2Delay = $v2['delay'] * 60;
- }
- if ($v1Delay > $v2Delay) {
- return 1;
- }
- });
- $return = [];
- $groups = [];
- $miniOpen = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
- foreach ($data as $index=>$item) {
- $tmp_data = json_decode($item['news_set'], true);
- if (isset($tmp_data['deploy_type']) && ($tmp_data['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP)) {
- $groups = array_merge($groups, $tmp_data['admin_group']);
- }
- $tmp_data['selected'] = [];
- $tmp_data['channelGroupList'] = [];
- $tmp_data['content_type'] = $item['content_type']??1;
- $tmp_data['id'] = $item['id'];
- $tmp_data['mini_open'] = 1;
- $tmp_data['text_tip_word'] = $tmp_data['text_tip_word'] ?? '欢迎关注「$gzh_name」,点击下方继续阅读';
- $tmp_data['mobile_system'] = $tmp_data['mobile_system']??0;
- $tmp_data['user_type'] = $tmp_data['user_type']??1;
- $tmp_data['text_content'] = $tmp_data['text_content'] ?? [];
- $tmp_data['is_sign'] = (int)($tmp_data['is_sign'] ?? 1);
- $tmp_data['sex'] = (int)($tmp_data['sex'] ?? 0);
- $return[] = $tmp_data;
- }
- if ($groups) {
- $groupList = model('vip_group')->whereIn('id', $groups)->column('id,id,name,createtime,updatetime');
- foreach ($return as $index=>$tmp_data){
- if (isset($tmp_data['deploy_type']) && ($tmp_data['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP)) {
- foreach($tmp_data['admin_group'] as $groupId){
- if (array_key_exists($groupId, $groupList)) {
- $tmp_data['selected'][$groupId] = $groupList[$groupId];
- $tmp_data['channelGroupList'][] = $groupList[$groupId];
- }
- }
- }
- $return[$index] = $tmp_data;
- }
- }
- if ($this->request->isPost()) {
- return json([
- 'data' => $return,
- 'mini_open'=> $miniOpen,
- ]);
- }
- $this->assignconfig('mini_open',$miniOpen);
- $this->assignconfig('data', $return);
- return $this->view->fetch();
- }
- public function add()
- {
- $params = json_decode($this->request->post('data'), true);
- $params['admin_group'] = [];
- $params['deploy_type'] = (int)$params['deploy_type'];
- if ($params['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP) {
- $params['admin_group'] = [];
- foreach ($params['selected'] as $index=>$value) {
- if ($value) {
- $params['admin_group'][] = $index;
- }
- }
- }
- if ($params['content_type'] == 2 && empty($params['text_content'])){
- $this->error('文本消息不能为空');
- }
- $result = SubscribeVipDelayService::instance()->createDelayReply($params, $this->auth->id);
- if ($result->code == ErrorCodeConstants::SUCCESS) {
- $this->success('','', ['id' => $result->data]);
- } else {
- $this->error($result->msg);
- }
- }
- /**
- * 删除
- */
- public function delete($ids = "")
- {
- model('subscribe_delay_push')->where('id', $ids)
- ->update(['status' => 'hidden']);
- $channel_ids = AdminService::instance()->getAdminId($this->auth->id)->data;
- //清除缓存
- foreach ($channel_ids as $channel_id) {
- model('subscribe_delay_push')->delCache($channel_id);
- }
- $this->success();
- }
- }
|