123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?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\common\library\Redis;
- use app\common\model\AutoreplyCollect;
- use app\common\model\WechatAutoreply;
- use app\main\constants\AdminConstants;
- use app\main\constants\CacheConstants;
- use app\main\constants\ErrorCodeConstants;
- use app\main\constants\SubscribeDelayConstants;
- use app\main\service\AdminService;
- use app\main\service\AutoreplyService;
- use app\main\service\ReplyVipService;
- use app\main\service\SubscribeVipDelayService;
- use app\main\service\UrlService;
- use app\main\service\VisitLimitService;
- use think\Collection;
- class Vipreply extends Backend
- {
- /**
- * @var WechatAutoreply
- */
- protected $model = null;
- protected $noNeedRight = ['detail'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('WechatAutoreply');
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->whereNotIn('title', ['签到', 'subscribe'])
- ->where('admin_id', $this->auth->id)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->whereNotIn('title', ['签到', 'subscribe'])
- ->where('admin_id', $this->auth->id)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- if ($list) {
- $collect = new AutoreplyCollect();
- $ids = array_column($list, 'id');
- $rs = model('wechat_autoreply')->whereIn('pid', $ids)->column('id,pid');
- $ids = array_keys($rs);
- if (VisitLimitService::instance()->checkMigratedV2()) {
- $collect_list = AutoreplyService::instance()->getMigrateData($ids)->data;
- } else {
- $collect_list = $collect->whereIn('id', $ids)->column('id,uv,subscribe,money');
- }
- $list = Collection::make($list)->toArray();
- foreach ($list as $index => $item) {
- $list[$index]['uv'] = $list[$index]['subscribe'] = $list[$index]['money'] = 0;
- foreach ($rs as $id => $pid) {
- if ($pid == $item['id'] && array_key_exists($id, $collect_list)) {
- $list[$index]['uv'] += $collect_list[$id]['uv'];
- $list[$index]['subscribe'] += $collect_list[$id]['subscribe'];
- $list[$index]['money'] += $collect_list[$id]['money'];
- }
- }
- if (array_key_exists('books', $item) && $item['books']) {
- $list[$index]['books'] = json_decode($item['books'], true);
- }
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = NULL)
- {
- $row = $this->model->get(['id' => $ids, 'admin_id' => $this->auth->id]);
- if (!$row)
- $this->error(__('No Results were found'));
- if ($row['title'] == 'subscribe')
- $this->error(__('请在新版被关注回复中设置关注回复内容'));
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- $params['title'] = $params['text'];
- $row->save($params);
- $this->success();
- }
- $this->error();
- }
- $channel_id = $this->auth->agent_id ? $this->auth->agent_id : $this->auth->channel_id;
- if ($row['type'] == 'text') {
- $data = json_decode($row['text_content'], true);
- $data['news_content'] = [];
- } else {
- $data = json_decode($row['news_content'], true);
- $data['text_content'] = [];
- }
- if ($data['deploy_type'] == SubscribeDelayConstants::VIP_DEPLOY_GROUP) {
- $groupList = model('vip_group')->whereIn('id', $data['admin_group'])->column('id,id,name,createtime,updatetime');
- foreach($data['admin_group'] as $groupId){
- if (array_key_exists($groupId, $groupList)) {
- $data['selected'][$groupId] = $groupList[$groupId];
- }
- }
- }
- $data['text_tip_word'] = json_decode($data['text_tip_word'], true);
- $data['id'] = $row['id'];
- $data = UrlService::instance()->replaceReferralHost($channel_id, $data, false)->data;
- // echo \GuzzleHttp\json_encode($data, JSON_UNESCAPED_UNICODE);exit;
- $this->assignconfig("row", $data);
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $params = json_decode($this->request->param('data'), true);
- $result = ReplyVipService::instance()->createReply($params, $this->auth->id);
- if ($result->code == ErrorCodeConstants::SUCCESS) {
- $this->success();
- } else {
- $this->error($result->msg);
- }
- }
- return $this->view->fetch();
- }
- public function detail($ids)
- {
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams(false,true);
- $total = $this->model->where('pid', $ids)
- ->alias('wa')
- ->join('admin a', 'a.id=wa.admin_id')
- ->where($where)
- ->limit($offset, $limit)
- ->count();
- if ($total) {
- $list = $this->model->where('pid', $ids)
- ->alias('wa')
- ->join('admin a', 'a.id=wa.admin_id')
- ->where($where)
- ->limit($offset, $limit)
- ->field('wa.id,wa.title,wa.createtime,wa.status,a.nickname')
- ->select();
- $collect = new AutoreplyCollect();
- $ids = array_column($list, 'id');
- $collect_list = $collect->whereIn('id', $ids)->column('id,uv,subscribe,money');
- foreach ($list as $index => $item) {
- $list[$index]['uv'] = $list[$index]['subscribe'] = $list[$index]['money'] = 0;
- if (array_key_exists($item['id'], $collect_list)) {
- $list[$index] = array_merge($list[$index]->getData(), $collect_list[$item['id']]);
- }
- }
- } else {
- $list = [];
- }
- return json(['total'=>$total, 'rows'=>$list]);
- }
- $this->assignconfig('ids', $ids);
- return $this->view->fetch();
- }
- }
|