123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\store\controller;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- /**
- * 用户咨询
- * Class GoodsCate
- * @package app\store\controller
- */
- class Consult extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'store_consult';
- /**
- * 用户咨询管理
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '用户咨询管理';
- $this->engineer_id = session('user.engineer_id');
- $this->byWhere(1)->field('a.*,b.name,b.headimg')->order('a.id desc')->page();
- }
- /**
- * 搜索条件
- * @return \library\helper\QueryHelper
- */
- protected function byWhere($type)
- {
- if ($type == 1) {
- $query = $this->_query($this->table);
- } elseif ($type == 2) {
- $query = Db::name($this->table);
- }
- $query = $query->alias('a')->join('store_member b', 'a.user_id=b.id');
- $query->where('a.type = 1');
- $engineer_id = session('user.engineer_id');
- if($engineer_id > 0){
- $query->where('a.from_user_id = '.$engineer_id.' or a.is_answer = 0');
- }
- if (isset($_GET['create_time']) && $_GET['create_time']) {
- $time = explode(' - ', $_GET['create_time']);
- $start_date_time = $time[0] . ' 00:00:00';
- $end_date_time = $time[1] . ' 23:59:59';
- $query->whereBetweenTime('a.create_time', $start_date_time, $end_date_time);
- }
- if (isset($_GET['user_info']) && $_GET['user_info']) {
- $query->where('b.name|b.phone', '=', $_GET['user_info'] );
- }
- return $query;
- }
- /**咨询列表处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(array &$data)
- {
- $mids = array_unique(array_merge(array_column($data, 'user_id'), array_column($data, 'from_mid')));
- $memberList = Db::name('StoreMember')->whereIn('id', $mids)->select();
- foreach ($data as &$vo) {
- list($vo['member'], $vo['from_member'], $vo['list']) = [[], [], []];
- foreach ($memberList as $member) if ($member['id'] === $vo['user_id']) {
- $vo['member'] = $member;
- }
- }
- }
- /**
- * 立即解答
- * @auth true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function answer()
- {
- $id = $this->app->request->get('id');
- $this->assign('id', $id);
- $post = $this->app->request->post();
- if (isset($post['id']) && $post['id']) {
- $root_consult_id = Db::name('store_consult')->where('id',$id)->value('root_consult_id');
- $consult_data = array(
- 'user_id' => session('user.engineer_id'),
- 'content' => $post['answer_content'],
- 'consult_id' => $id,
- 'root_consult_id' => $root_consult_id,
- 'type' => 2
- );
- Db::name('store_consult')->where('id',$id)->update(array('is_answer'=>1,'from_user_id'=>session('user.engineer_id')));
- Db::name('store_consult')->insert($consult_data);
- //添加消息通知
- $user_id = Db::name('store_consult')->where('id',$id)->value('user_id');
- $new_data = array(
- 'user_id' => $user_id,
- 'content' => '您咨询的问题得到了新的回复,赶紧快来查看~',
- 'consult_id' => $root_consult_id,
- 'type' => 2
- );
- Db::name('store_news')->insert($new_data);
- $this->success('解答成功');
- } else {
- $this->_form($this->table, 'answer');
- }
- }
- }
|