RotarytableprizeController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\RotarytablePrize;
  5. use app\model\Coupon;
  6. class RotarytableprizeController extends Base
  7. {
  8. function index()
  9. {
  10. $weid = weid();
  11. $keyword = input('post.keyword', '', 'serach_in');
  12. RotarytablePrize::datainitial();
  13. $query = RotarytablePrize::where(['weid' => $weid]);
  14. if (!empty($keyword)) {
  15. $query->where('title', 'like', '%' . $keyword . '%');
  16. }
  17. if (!empty($this->sid)) {
  18. $query->where('sid', $this->sid);
  19. }
  20. $res = $query->order('sort asc,id desc')
  21. ->paginate(getpage())
  22. ->toArray();
  23. foreach ($res['data'] as &$vo) {
  24. $vo['ptype'] = getPrizerptype($vo['ptype']);
  25. }
  26. $data['data'] = $res;
  27. return $this->json($data);
  28. }
  29. function listUpdate()
  30. {
  31. $data = only('id,status,sort');
  32. if (!$data['id']) throw new ValidateException('参数错误');
  33. RotarytablePrize::update($data);
  34. return $this->json(['msg' => '操作成功']);
  35. }
  36. public function update()
  37. {
  38. $id = $this->request->post('id');
  39. $data = input('post.');
  40. unset($data['create_time']);
  41. $data['begin_date'] = strtotime($data['begin_date']);
  42. $data['end_date'] = strtotime($data['end_date']);
  43. if (empty($id)) {
  44. $data['weid'] = weid();
  45. if (!empty($this->sid)) {
  46. $data['sid'] = $this->sid;
  47. }
  48. try {
  49. $res = RotarytablePrize::create($data);
  50. if ($res->id && empty($data['sort'])) {
  51. RotarytablePrize::update(['sort' => $res->id, 'id' => $res->id]);
  52. }
  53. $data['id'] = $res->id;
  54. } catch (\Exception $e) {
  55. throw new ValidateException($e->getMessage());
  56. }
  57. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  58. } else {
  59. try {
  60. RotarytablePrize::update($data);
  61. } catch (\Exception $e) {
  62. throw new ValidateException($e->getMessage());
  63. }
  64. return $this->json(['msg' => '修改成功']);
  65. }
  66. }
  67. function getInfo()
  68. {
  69. $id = $this->request->post('id', '', 'serach_in');
  70. if (!$id) throw new ValidateException('参数错误');
  71. $data = RotarytablePrize::field('*')->find($id)->toArray();
  72. return $this->json(['data' => $data]);
  73. }
  74. function delete()
  75. {
  76. return $this->del(new RotarytablePrize());
  77. }
  78. function getField()
  79. {
  80. $data['ptypearray'] = getPrizerptype();
  81. $data['couponarray'] = Coupon::getpcarray();
  82. return $this->json(['data' => $data]);
  83. }
  84. }