DomainreplaceController.php 1.7 KB

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