Active.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\store\controller\apps\bargain;
  3. use app\store\controller\Controller;
  4. use app\store\model\Goods as GoodsModel;
  5. use app\store\model\bargain\Active as ActiveModel;
  6. /**
  7. * 砍价活动管理
  8. * Class Active
  9. * @package app\store\controller\apps\bargain
  10. */
  11. class Active extends Controller
  12. {
  13. /**
  14. * 砍价活动列表
  15. * @param string $search
  16. * @return mixed
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function index($search = '')
  22. {
  23. $model = new ActiveModel;
  24. $list = $model->getList($search);
  25. return $this->fetch('index', compact('list'));
  26. }
  27. /**
  28. * 新增砍价活动
  29. * @return array|bool|mixed
  30. */
  31. public function add()
  32. {
  33. if (!$this->request->isAjax()) {
  34. return $this->fetch('add');
  35. }
  36. $model = new ActiveModel;
  37. // 新增记录
  38. if ($model->add($this->postData('active'))) {
  39. return $this->renderSuccess('添加成功', url('apps.bargain.active/index'));
  40. }
  41. return $this->renderError($model->getError() ?: '添加失败');
  42. }
  43. /**
  44. * 更新砍价活动
  45. * @param $active_id
  46. * @return array|mixed
  47. * @throws \think\exception\DbException
  48. */
  49. public function edit($active_id)
  50. {
  51. // 砍价活动详情
  52. $model = ActiveModel::detail($active_id);
  53. if (!$this->request->isAjax()) {
  54. // 获取商品详情
  55. $goods = GoodsModel::detail($model['goods_id']);
  56. return $this->fetch('edit', compact('model', 'goods'));
  57. }
  58. // 更新记录
  59. if ($model->edit($this->postData('active'))) {
  60. return $this->renderSuccess('更新成功', url('apps.bargain.active/index'));
  61. }
  62. return $this->renderError($model->getError() ?: '更新失败');
  63. }
  64. /**
  65. * 删除砍价活动
  66. * @param $active_id
  67. * @return array
  68. * @throws \think\exception\DbException
  69. */
  70. public function delete($active_id)
  71. {
  72. // 砍价活动详情
  73. $model = ActiveModel::detail($active_id);
  74. if (!$model->setDelete()) {
  75. return $this->renderError($model->getError() ?: '删除失败');
  76. }
  77. return $this->renderSuccess('删除成功');
  78. }
  79. }