Consult.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use library\Controller;
  16. use library\tools\Data;
  17. use think\Db;
  18. /**
  19. * 用户咨询
  20. * Class GoodsCate
  21. * @package app\store\controller
  22. */
  23. class Consult extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'store_consult';
  30. /**
  31. * 用户咨询管理
  32. * @auth true
  33. * @menu true
  34. * @throws \think\Exception
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. * @throws \think\exception\PDOException
  39. */
  40. public function index()
  41. {
  42. $this->title = '用户咨询管理';
  43. $this->engineer_id = session('user.engineer_id');
  44. $this->byWhere(1)->field('a.*,b.name,b.headimg')->order('a.id desc')->page();
  45. }
  46. /**
  47. * 搜索条件
  48. * @return \library\helper\QueryHelper
  49. */
  50. protected function byWhere($type)
  51. {
  52. if ($type == 1) {
  53. $query = $this->_query($this->table);
  54. } elseif ($type == 2) {
  55. $query = Db::name($this->table);
  56. }
  57. $query = $query->alias('a')->join('store_member b', 'a.user_id=b.id');
  58. $query->where('a.type = 1');
  59. $engineer_id = session('user.engineer_id');
  60. if($engineer_id > 0){
  61. $query->where('a.from_user_id = '.$engineer_id.' or a.is_answer = 0');
  62. }
  63. if (isset($_GET['create_time']) && $_GET['create_time']) {
  64. $time = explode(' - ', $_GET['create_time']);
  65. $start_date_time = $time[0] . ' 00:00:00';
  66. $end_date_time = $time[1] . ' 23:59:59';
  67. $query->whereBetweenTime('a.create_time', $start_date_time, $end_date_time);
  68. }
  69. if (isset($_GET['user_info']) && $_GET['user_info']) {
  70. $query->where('b.name|b.phone', '=', $_GET['user_info'] );
  71. }
  72. return $query;
  73. }
  74. /**咨询列表处理
  75. * @param array $data
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. * @throws \think\exception\DbException
  79. */
  80. protected function _index_page_filter(array &$data)
  81. {
  82. $mids = array_unique(array_merge(array_column($data, 'user_id'), array_column($data, 'from_mid')));
  83. $memberList = Db::name('StoreMember')->whereIn('id', $mids)->select();
  84. foreach ($data as &$vo) {
  85. list($vo['member'], $vo['from_member'], $vo['list']) = [[], [], []];
  86. foreach ($memberList as $member) if ($member['id'] === $vo['user_id']) {
  87. $vo['member'] = $member;
  88. }
  89. }
  90. }
  91. /**
  92. * 立即解答
  93. * @auth true
  94. * @throws \think\Exception
  95. * @throws \think\db\exception\DataNotFoundException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. * @throws \think\exception\DbException
  98. * @throws \think\exception\PDOException
  99. */
  100. public function answer()
  101. {
  102. $id = $this->app->request->get('id');
  103. $this->assign('id', $id);
  104. $post = $this->app->request->post();
  105. if (isset($post['id']) && $post['id']) {
  106. $root_consult_id = Db::name('store_consult')->where('id',$id)->value('root_consult_id');
  107. $consult_data = array(
  108. 'user_id' => session('user.engineer_id'),
  109. 'content' => $post['answer_content'],
  110. 'consult_id' => $id,
  111. 'root_consult_id' => $root_consult_id,
  112. 'type' => 2
  113. );
  114. Db::name('store_consult')->where('id',$id)->update(array('is_answer'=>1,'from_user_id'=>session('user.engineer_id')));
  115. Db::name('store_consult')->insert($consult_data);
  116. //添加消息通知
  117. $user_id = Db::name('store_consult')->where('id',$id)->value('user_id');
  118. $new_data = array(
  119. 'user_id' => $user_id,
  120. 'content' => '您咨询的问题得到了新的回复,赶紧快来查看~',
  121. 'consult_id' => $root_consult_id,
  122. 'type' => 2
  123. );
  124. Db::name('store_news')->insert($new_data);
  125. $this->success('解答成功');
  126. } else {
  127. $this->_form($this->table, 'answer');
  128. }
  129. }
  130. }