StoreIntegral.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\marketing\integral;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\integral\StoreIntegralServices;
  14. use think\facade\App;
  15. /**
  16. * 积分商城管理
  17. * Class StoreCombination
  18. * @package app\admin\controller\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 app('json')->success($list);
  46. }
  47. /**
  48. * 保存商品
  49. * @param int $id
  50. */
  51. public function save($id = 0)
  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. ]);
  69. $this->validate($data, \app\adminapi\validate\marketing\StoreIntegralValidate::class, 'save');
  70. if ($id) {
  71. $integral = $this->services->get((int)$id);
  72. if (!$integral) {
  73. return app('json')->fail(100026);
  74. }
  75. }
  76. if ($data['copy'] == 1) {
  77. $id = 0;
  78. unset($data['copy']);
  79. }
  80. $this->services->saveData($id, $data);
  81. return app('json')->success(100000);
  82. }
  83. /**
  84. * 批量添加商品
  85. * @return mixed
  86. */
  87. public function batch_add()
  88. {
  89. $data = $this->request->postMore([
  90. ['attrs', []],
  91. [['is_show', 'd'], 0]
  92. ]);
  93. $this->services->saveBatchData($data);
  94. return app('json')->success(100000);
  95. }
  96. /**
  97. * 详情
  98. * @param $id
  99. * @return mixed
  100. */
  101. public function read($id)
  102. {
  103. $info = $this->services->getInfo($id);
  104. return app('json')->success(compact('info'));
  105. }
  106. /**
  107. * 修改状态
  108. * @param $id
  109. * @param $status
  110. * @return mixed
  111. */
  112. public function set_show($id, $is_show)
  113. {
  114. $this->services->update($id, ['is_show' => $is_show]);
  115. return app('json')->success(100014);
  116. }
  117. /**
  118. * 删除指定资源
  119. *
  120. * @param int $id
  121. * @return \think\Response
  122. */
  123. public function delete($id)
  124. {
  125. if (!$id) return app('json')->fail(100100);
  126. $this->services->update($id, ['is_del' => 1]);
  127. return app('json')->success(100002);
  128. }
  129. }