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(); } }