lqmac 4 months ago
parent 80b46c3d28
commit da3786b169
  1. 8
      app/job/controller/goods/StoreGoodsDelete.php
  2. 6
      app/job/controller/goods/StoreGoodsOffline.php
  3. 6
      app/job/controller/goods/StoreGoodsOnline.php
  4. 2
      app/job/service/goods/StoreGoodsDelete.php
  5. 0
      app/job/service/goods/StoreGoodsOffline.php
  6. 2
      app/job/service/goods/StoreGoodsOnline.php
  7. 11
      app/store/controller/Goods.php

@ -4,7 +4,7 @@ declare (strict_types=1);
namespace app\job\controller\goods; namespace app\job\controller\goods;
use app\job\service\goods\GoodsDelete as GoodsDeleteService; use app\job\service\goods\StoreGoodsDelete as StoreGoodsDeleteService;
use cores\BaseJob; use cores\BaseJob;
use cores\traits\QueueTrait; use cores\traits\QueueTrait;
use cores\exception\BaseException; use cores\exception\BaseException;
@ -17,7 +17,7 @@ use think\db\exception\ModelNotFoundException;
* Class Import * Class Import
* @package app\job\controller * @package app\job\controller
*/ */
class GoodsDelete extends BaseJob class StoreGoodsDelete extends BaseJob
{ {
use QueueTrait; use QueueTrait;
@ -33,9 +33,9 @@ class GoodsDelete extends BaseJob
public function handle(array $data): bool public function handle(array $data): bool
{ {
$time = date('H:i:s'); $time = date('H:i:s');
echo "\n ---- GoodsDelete ---- {$time} ---- \n"; echo "\n ---- StoreGoodsDelete ---- {$time} ---- \n";
$service = new GoodsDeleteService; $service = new StoreGoodsDeleteService;
return $service->batch($data['list']); return $service->batch($data['list']);
} }
} }

@ -3,7 +3,7 @@ declare (strict_types=1);
namespace app\job\controller\goods; namespace app\job\controller\goods;
use app\job\service\goods\GoodsOffline as GoodsOfflineService; use app\job\service\goods\StoreGoodsOffline as StoreGoodsOfflineService;
use cores\BaseJob; use cores\BaseJob;
use cores\traits\QueueTrait; use cores\traits\QueueTrait;
use cores\exception\BaseException; use cores\exception\BaseException;
@ -16,7 +16,7 @@ use think\db\exception\ModelNotFoundException;
* Class Import * Class Import
* @package app\job\controller * @package app\job\controller
*/ */
class GoodsOffline extends BaseJob class StoreGoodsOffline extends BaseJob
{ {
use QueueTrait; use QueueTrait;
@ -34,7 +34,7 @@ class GoodsOffline extends BaseJob
$time = date('H:i:s'); $time = date('H:i:s');
echo "\n ---- GoodsOffline ---- {$time} ---- \n"; echo "\n ---- GoodsOffline ---- {$time} ---- \n";
$service = new GoodsOfflineService; $service = new StoreGoodsOfflineService;
return $service->batch($data['list']); return $service->batch($data['list']);
} }
} }

@ -3,7 +3,7 @@ declare (strict_types=1);
namespace app\job\controller\goods; namespace app\job\controller\goods;
use app\job\service\goods\GoodsOnline as GoodsOnlineService; use app\job\service\goods\StoreGoodsOnline as StoreGoodsOnlineService;
use cores\BaseJob; use cores\BaseJob;
use cores\traits\QueueTrait; use cores\traits\QueueTrait;
use cores\exception\BaseException; use cores\exception\BaseException;
@ -16,7 +16,7 @@ use think\db\exception\ModelNotFoundException;
* Class Import * Class Import
* @package app\job\controller * @package app\job\controller
*/ */
class GoodsOnline extends BaseJob class StoreGoodsOnline extends BaseJob
{ {
use QueueTrait; use QueueTrait;
@ -34,7 +34,7 @@ class GoodsOnline extends BaseJob
$time = date('H:i:s'); $time = date('H:i:s');
echo "\n ---- GoodsOnline ---- {$time} ---- \n"; echo "\n ---- GoodsOnline ---- {$time} ---- \n";
$service = new GoodsOnlineService; $service = new StoreGoodsOnlineService;
return $service->batch($data['list']); return $service->batch($data['list']);
} }
} }

@ -17,7 +17,7 @@ use app\common\model\Region;
* Class Import * Class Import
* @package app\job\service\goods * @package app\job\service\goods
*/ */
class GoodsDelete extends BaseService class StoreGoodsDelete extends BaseService
{ {
/** /**
* 批量导入商品 * 批量导入商品

@ -17,7 +17,7 @@ use app\common\model\Region;
* Class Import * Class Import
* @package app\job\service\goods * @package app\job\service\goods
*/ */
class GoodsOnline extends BaseService class StoreGoodsOnline extends BaseService
{ {
/** /**
* 批量导入商品 * 批量导入商品

@ -297,6 +297,17 @@ class Goods extends Controller
if (!$model->setDelete($goodsIds)) { if (!$model->setDelete($goodsIds)) {
return $this->renderError($model->getError() ?: '删除失败'); return $this->renderError($model->getError() ?: '删除失败');
} }
// 分批每次导入20条
$limit = 20;
// 根据商品总数量计算需要的队列任务数量
$jobCount = \count($goodsIds) / $limit;
// 逐次发布队列任务
for ($i = 0; $i < $jobCount; $i++) {
$data = array_slice($goodsIds, $i * $limit, $limit);
StoreGoodsDeleteJob::dispatch([
'list' => $data,
]);
}
return $this->renderSuccess('删除成功'); return $this->renderSuccess('删除成功');
} }
public function export(){ public function export(){

Loading…
Cancel
Save