AgentteamawardController.php 1.7 KB

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