StoreIntegral.php 4.3 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\integral;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\integral\StoreIntegralServices;
  14. use think\facade\App;
  15. /**
  16. * 积分商城管理
  17. * Class StoreCombination
  18. * @package app\controller\admin\v1\store
  19. */
  20. class StoreIntegral extends AuthController
  21. {
  22. /**
  23. * StoreIntegral constructor.
  24. * @param App $app
  25. * @param StoreIntegralServices $services
  26. */
  27. public function __construct(App $app, StoreIntegralServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 积分商品列表
  34. * @return mixed
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['integral_time', ''],
  40. ['is_show', ''],
  41. ['store_name', '']
  42. ]);
  43. $where['is_del'] = 0;
  44. $list = $this->services->systemPage($where);
  45. return $this->success($list);
  46. }
  47. /**
  48. * 保存商品
  49. * @param int $id
  50. */
  51. public function save($id)
  52. {
  53. $data = $this->request->postMore([
  54. [['product_id', 'd'], 0],
  55. [['title', 's'], ''],
  56. [['unit_name', 's'], ''],
  57. ['image', ''],
  58. ['images', []],
  59. [['num', 'd'], 0],
  60. [['is_host', 'd'], 0],
  61. [['is_show', 'd'], 0],
  62. [['once_num', 'd'], 0],
  63. [['sort', 'd'], 0],
  64. [['description', 's'], ''],
  65. ['attrs', []],
  66. ['items', []],
  67. ['copy', 0],
  68. ['delivery_type', []],//物流方式
  69. ['freight', 1],//运费设置
  70. ['postage', 0],//邮费
  71. ['custom_form', ''],//自定义表单
  72. ['system_form_id', 0],//系统表单ID
  73. ['product_type', 0],//商品类型
  74. ['applicable_type', 1],//适用门店类型
  75. ['applicable_store_id', []],//适用门店IDS
  76. ]);
  77. $this->validate($data, \app\validate\admin\marketing\StoreIntegralValidate::class, 'save');
  78. if ($id) {
  79. $integral = $this->services->get((int)$id);
  80. if (!$integral) {
  81. return $this->fail('数据不存在');
  82. }
  83. }
  84. if ($data['num'] < $data['once_num']) {
  85. return $this->fail('限制单次购买数量不能大于总购买数量');
  86. }
  87. if ($data['copy'] == 1) {
  88. $id = 0;
  89. unset($data['copy']);
  90. }
  91. $this->services->saveData($id, $data);
  92. return $this->success('保存成功');
  93. }
  94. /**
  95. * 批量添加商品
  96. * @return mixed
  97. */
  98. public function batch_add()
  99. {
  100. $data = $this->request->postMore([
  101. ['attrs', []],
  102. [['is_show', 'd'], 0]
  103. ]);
  104. if (!$data['attrs']) return $this->fail('请选择提交的商品');
  105. $this->services->saveBatchData($data);
  106. return $this->success('保存成功');
  107. }
  108. /**
  109. * 详情
  110. * @param $id
  111. * @return mixed
  112. */
  113. public function read($id)
  114. {
  115. $info = $this->services->getInfo($id);
  116. return $this->success(compact('info'));
  117. }
  118. /**
  119. * 修改状态
  120. * @param $id
  121. * @param $status
  122. * @return mixed
  123. */
  124. public function set_show($id, $is_show)
  125. {
  126. $this->services->update($id, ['is_show' => $is_show]);
  127. return $this->success($is_show == 0 ? '下架成功' : '上架成功');
  128. }
  129. /**
  130. * 删除指定资源
  131. *
  132. * @param int $id
  133. * @return \think\Response
  134. */
  135. public function delete($id)
  136. {
  137. if (!$id) return $this->fail('缺少参数');
  138. $this->services->update($id, ['is_del' => 1]);
  139. return $this->success('删除成功!');
  140. }
  141. }