ServicetimeController.php 1.8 KB

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