StoreAdvance.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\advance\StoreAdvanceServices;
  14. use app\services\activity\bargain\StoreBargainServices;
  15. use app\services\activity\combination\StoreCombinationServices;
  16. use app\services\activity\seckill\StoreSeckillServices;
  17. use crmeb\exceptions\AdminException;
  18. use think\facade\App;
  19. /**
  20. * 预售控制器
  21. * Class StoreAdvance
  22. * @package app\adminapi\controller\v1\marketing
  23. */
  24. class StoreAdvance extends AuthController
  25. {
  26. /**
  27. * StoreAdvance constructor.
  28. * @param App $app
  29. * @param StoreAdvanceServices $services
  30. */
  31. public function __construct(App $app, StoreAdvanceServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 管理端预售列表
  38. * @return mixed
  39. */
  40. public function index()
  41. {
  42. $where = $this->request->getMore([
  43. ['title', ''],
  44. ['type', ''],
  45. ['status', ''],
  46. ['time_type', 0]
  47. ]);
  48. return app('json')->success($this->services->getList($where));
  49. }
  50. /**
  51. * 添加/修改预售商品
  52. * @param $id
  53. * @return mixed
  54. */
  55. public function save($id)
  56. {
  57. $data = $this->request->postMore([
  58. [['product_id', 'd'], 0],
  59. [['title', 's'], ''],
  60. [['info', 's'], ''],
  61. [['unit_name', 's'], ''],
  62. ['image', ''],
  63. ['images', []],
  64. [['description', 's'], ''],
  65. [['temp_id', 'd'], 0],
  66. [['status', 'd'], 0],
  67. [['sort', 'd'], 0],
  68. [['num', 'd'], 0],
  69. [['once_num', 'd'], 1000],
  70. ['section_time', []],
  71. ['type', 0],
  72. ['deposit', 0],
  73. ['pay_time', []],
  74. ['attrs', []],
  75. ['items', []],
  76. ['deliver_time', 0],
  77. ['copy', 0]
  78. ]);
  79. if (!$id) {
  80. /** @var StoreSeckillServices $storeSeckillService */
  81. $storeSeckillService = app()->make(StoreSeckillServices::class);
  82. $res1 = $storeSeckillService->count(['product_id' => $data['product_id'], 'is_del' => 0, 'status' => 1, 'seckill_time' => 1]);
  83. if ($res1) {
  84. throw new AdminException(400506);
  85. }
  86. /** @var StoreBargainServices $storeBargainService */
  87. $storeBargainService = app()->make(StoreBargainServices::class);
  88. $res2 = $storeBargainService->count(['product_id' => $data['product_id'], 'is_del' => 0, 'status' => 1, 'bargain_time' => 1]);
  89. if ($res2) {
  90. throw new AdminException(400506);
  91. }
  92. /** @var StoreCombinationServices $storeCombinationService */
  93. $storeCombinationService = app()->make(StoreCombinationServices::class);
  94. $res3 = $storeCombinationService->count(['product_id' => $data['product_id'], 'is_del' => 0, 'is_show' => 1, 'pinkIngTime' => 1]);
  95. if ($res3) {
  96. throw new AdminException(400506);
  97. }
  98. }
  99. $this->services->saveData($id, $data);
  100. return app('json')->success(100000);
  101. }
  102. /**
  103. * 详情
  104. * @param $id
  105. * @return mixed
  106. */
  107. public function info($id)
  108. {
  109. $info = $this->services->getInfo($id);
  110. return app('json')->success(compact('info'));
  111. }
  112. /**
  113. * 删除预售
  114. * @param $id
  115. * @return mixed
  116. */
  117. public function del($id)
  118. {
  119. $res = $this->services->update($id, ['is_del' => 1]);
  120. if ($res) {
  121. return app('json')->success(100002);
  122. } else {
  123. return app('json')->fail(100008);
  124. }
  125. }
  126. /**
  127. * 预售商品上下架
  128. * @param $id
  129. * @param $status
  130. * @return mixed
  131. */
  132. public function setStatus($id, $status)
  133. {
  134. $res = $this->services->update($id, ['status' => $status]);
  135. if ($res) {
  136. return app('json')->success(100014);
  137. } else {
  138. return app('json')->fail(100015);
  139. }
  140. }
  141. }