CommonlyController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\admin\controller\kefu;
  3. use think\exception\ValidateException;
  4. use app\model\kefu\Commonly;
  5. class CommonlyController 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 = Commonly::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. Commonly::update($data);
  32. return $this->json(['msg' => '操作成功']);
  33. }
  34. public function update()
  35. {
  36. $id = $this->request->post('id');
  37. $data = input('post.');
  38. if (empty($id)) {
  39. $weid = weid();
  40. $data['weid'] = $weid;
  41. $res = Commonly::create($data);
  42. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  43. } else {
  44. Commonly::update($data);
  45. return $this->json(['msg' => '修改成功']);
  46. }
  47. }
  48. function getInfo()
  49. {
  50. $id = $this->request->post('id', '', 'serach_in');
  51. if (!$id) $this->error('参数错误');
  52. $res = Commonly::find($id);
  53. return $this->json(['data' => $res]);
  54. }
  55. function delete()
  56. {
  57. return $this->del(new Commonly());
  58. }
  59. }