MiaoshatimeController.php 1.5 KB

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