ReglikeController.php 1.8 KB

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