Table.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\shop\controller\plus\table;
  3. use app\shop\controller\Controller;
  4. use app\shop\model\plus\table\Table as TableModel;
  5. /**
  6. * 表单控制器
  7. */
  8. class Table extends Controller
  9. {
  10. /**
  11. * 优惠券列表
  12. */
  13. public function index()
  14. {
  15. $model = new TableModel();
  16. $list = $model->getList($this->postData());
  17. return $this->renderSuccess('', compact('list'));
  18. }
  19. /**
  20. * 添加优惠券
  21. */
  22. public function add()
  23. {
  24. $model = new TableModel();
  25. // 新增记录
  26. if ($model->add($this->postData())) {
  27. return $this->renderSuccess('添加成功');
  28. }
  29. return $this->renderError($model->getError()?:'添加失败');
  30. }
  31. /**
  32. * 更新优惠券
  33. */
  34. public function edit($table_id)
  35. {
  36. $model = TableModel::detail($table_id);
  37. if($this->request->isGet()){
  38. return $this->renderSuccess('', compact('model'));
  39. }
  40. // 更新记录
  41. if ($model->edit($this->postData())) {
  42. return $this->renderSuccess('更新成功');
  43. }
  44. return $this->renderError('更新失败');
  45. }
  46. /**
  47. * 删除优惠券
  48. */
  49. public function delete($table_id)
  50. {
  51. $model = TableModel::detail($table_id);
  52. // 更新记录
  53. if ($model->setDelete()) {
  54. return $this->renderSuccess('删除成功');
  55. }
  56. return $this->renderError($model->getError()?:'删除失败');
  57. }
  58. }