StoreDiscounts.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\marketing\discounts;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\discounts\StoreDiscountsServices;
  14. use think\facade\App;
  15. /**
  16. * 优惠套餐
  17. * Class StoreDiscounts
  18. * @package app\controller\admin\v1\marketing\discounts
  19. */
  20. class StoreDiscounts extends AuthController
  21. {
  22. /**
  23. * StoreDiscounts constructor.
  24. * @param App $app
  25. * @param StoreDiscountsServices $services
  26. */
  27. public function __construct(App $app, StoreDiscountsServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 新增修改优惠
  34. * @return mixed
  35. */
  36. public function save()
  37. {
  38. $data = $this->request->getMore([
  39. ['id', 0],
  40. ['title', ''],
  41. ['image', ''],
  42. ['type', 0],
  43. ['is_limit', 0],
  44. ['limit_num', 0],
  45. ['link_ids', ''],
  46. ['is_time', 0],
  47. ['time', []],
  48. ['sort', 0],
  49. ['free_shipping', 0],
  50. ['status', 0],
  51. ['products', []],
  52. ['delivery_type', []],//物流方式
  53. ['freight', 1],//运费设置
  54. ['postage', 0],//邮费
  55. ['custom_form', ''],//自定义表单
  56. ['system_form_id', 0],//系统表单ID
  57. ]);
  58. if ($data['title'] == '') return $this->fail('请填写套餐名称');
  59. if ($data['image'] == '') return $this->fail('请选择套餐主图');
  60. if ($data['is_limit'] && !$data['limit_num']) return $this->fail('套餐限量不能为0');
  61. if (!count($data['products'])) $this->fail('请添加套餐商品');
  62. foreach ($data['products'] as $item) {
  63. if (!isset($item['items'])) $this->fail('请选择' . $item['store_name'] . '的规格');
  64. }
  65. if ($data['is_time'] && is_array($data['is_time'])) {
  66. [$start, $end] = $data['is_time'];
  67. $start = strtotime($start);
  68. $end = strtotime($end);
  69. if($start > $end){
  70. return $this->fail('开始时间必须小于结束时间');
  71. }
  72. if($start < time() || $end < time()){
  73. return $this->fail('套餐时间不能小于当前时间');
  74. }
  75. }
  76. $msg = $data['id'] ? '编辑' : '添加';
  77. $res = $this->services->saveDiscounts($data);
  78. if ($res) {
  79. return $this->success($msg . '成功');
  80. } else {
  81. return $this->fail($msg . '失败');
  82. }
  83. }
  84. /**
  85. * 获取优惠商品列表
  86. * @return mixed
  87. */
  88. public function getList()
  89. {
  90. $where = $this->request->getMore([
  91. ['type', 0],
  92. ['status', ''],
  93. ['title', '']
  94. ]);
  95. $info = $this->services->getList($where);
  96. return $this->success($info);
  97. }
  98. /**
  99. * 获取优惠商品数据
  100. * @param int $id
  101. * @return mixed
  102. */
  103. public function getInfo($id = 0)
  104. {
  105. if (!$id) return $this->fail('参数错误');
  106. $info = $this->services->getInfo($id);
  107. if ($info) {
  108. return $this->success($info);
  109. } else {
  110. return $this->fail('获取失败');
  111. }
  112. }
  113. /**
  114. * 修改状态
  115. * @param $id
  116. * @param $status
  117. * @return mixed
  118. */
  119. public function setStatus($id, $status)
  120. {
  121. if (!$id) return $this->fail('参数错误');
  122. $res = $this->services->setStatus($id, $status);
  123. if ($res) {
  124. return $this->success('设置成功');
  125. } else {
  126. return $this->fail('设置失败');
  127. }
  128. }
  129. /**
  130. * 删除优惠套餐
  131. * @param $id
  132. * @return mixed
  133. */
  134. public function del($id)
  135. {
  136. if (!$id) return $this->fail('参数错误');
  137. $res = $this->services->del($id);
  138. if ($res) {
  139. return $this->success('删除成功');
  140. } else {
  141. return $this->fail('删除失败');
  142. }
  143. }
  144. }