ConsultDetail.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 ConsultDetail 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. $consult_id = input('consult_id');
  44. if(empty($consult_id)){
  45. $this->error('非法操作');
  46. }
  47. $this->engineer_id = session('user.engineer_id');
  48. $query = $this->_query($this->table);
  49. $query->where('root_consult_id',$consult_id)->dateBetween('create_at')->order('id desc')->page();
  50. }
  51. /**咨询列表处理
  52. * @param array $data
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. protected function _index_page_filter(array &$data)
  58. {
  59. $type_arr = array('1'=>'提问','2'=>'解答','3'=>'追问');
  60. foreach ($data as &$vo) {
  61. if($vo['type'] == 2){
  62. $table_name = 'store_engineer';
  63. }else{
  64. $table_name = 'store_member';
  65. }
  66. $vo['member'] = Db::name($table_name)->field('headimg,name,phone')->where('id',$vo['user_id'])->find();
  67. $vo['type_name'] = $type_arr[$vo['type']];
  68. }
  69. }
  70. /**
  71. * 立即解答
  72. * @auth true
  73. * @throws \think\Exception
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. * @throws \think\exception\DbException
  77. * @throws \think\exception\PDOException
  78. */
  79. public function answer()
  80. {
  81. $id = $this->app->request->get('id');
  82. $this->assign('id', $id);
  83. $post = $this->app->request->post();
  84. if (isset($post['id']) && $post['id']) {
  85. $root_consult_id = Db::name('store_consult')->where('id',$id)->value('root_consult_id');
  86. $data = array(
  87. 'user_id' => session('user.engineer_id'),
  88. 'content' => $post['answer_content'],
  89. 'consult_id' => $id,
  90. 'root_consult_id' => $root_consult_id,
  91. 'type' => 2
  92. );
  93. Db::name('store_consult')->where('id',$id)->update(array('is_answer'=>1,'from_user_id'=>session('user.engineer_id')));
  94. Db::name('store_consult')->insert($data);
  95. //添加消息通知
  96. $user_id = Db::name('store_consult')->where('id',$id)->value('user_id');
  97. $new_data = array(
  98. 'user_id' => $user_id,
  99. 'content' => '您咨询的问题得到了新的回复,赶紧快来查看~',
  100. 'consult_id' => $root_consult_id,
  101. 'type' => 2
  102. );
  103. Db::name('store_news')->insert($new_data);
  104. $this->success('解答成功');
  105. } else {
  106. $this->_form($this->table, 'answer');
  107. }
  108. }
  109. }