Active.php 2.6 KB

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