RefundaddressController.php 1.6 KB

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