AgreementController.php 1.6 KB

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