ReplyController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\admin\controller\kefu;
  3. use think\exception\ValidateException;
  4. use app\model\kefu\Reply;
  5. class ReplyController extends Base
  6. {
  7. function index()
  8. {
  9. $keyword = trim(input('post.keyword', '', 'serach_in'));
  10. $status = trim(input('post.status', '', 'serach_in'));
  11. $weid = weid();
  12. $where = [];
  13. $where['weid'] = $weid;
  14. if ($status !== '') {
  15. $where['status'] = $status;
  16. }
  17. $query = Reply::where($where);
  18. if (!empty($keyword)) {
  19. $query->where('content', 'like', '%' . $keyword . '%');
  20. }
  21. $res = $query->order('id desc')
  22. ->paginate(getpage())
  23. ->toArray();
  24. $data['data'] = $res;
  25. return $this->json($data);
  26. }
  27. function listUpdate()
  28. {
  29. $data = only('id,status');
  30. if (!$data['id']) throw new ValidateException('参数错误');
  31. Reply::update($data);
  32. return $this->json(['msg' => '操作成功']);
  33. }
  34. public function update()
  35. {
  36. $id = $this->request->post('id');
  37. $data = input('post.');
  38. unset($data['create_time']);
  39. if (empty($id)) {
  40. $weid = weid();
  41. $data['weid'] = $weid;
  42. $res = Reply::create($data);
  43. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  44. } else {
  45. Reply::update($data);
  46. return $this->json(['msg' => '修改成功']);
  47. }
  48. }
  49. function getInfo()
  50. {
  51. $id = $this->request->post('id', '', 'serach_in');
  52. if (!$id) $this->error('参数错误');
  53. $res = Reply::find($id);
  54. return $this->json(['data' => $res]);
  55. }
  56. function delete()
  57. {
  58. return $this->del(new Reply());
  59. }
  60. }