|
|
|
<?php
|
|
|
|
declare (strict_types=1);
|
|
|
|
|
|
|
|
namespace app\job\service\goods;
|
|
|
|
|
|
|
|
use app\common\library\helper;
|
|
|
|
use app\common\service\BaseService;
|
|
|
|
use app\common\model\Goods as GoodsModel;
|
|
|
|
use app\common\model\GoodsSku;
|
|
|
|
use app\store\model\GoodsCategoryRel;
|
|
|
|
use cores\exception\BaseException;
|
|
|
|
use think\facade\Log;
|
|
|
|
use app\common\model\Channel;
|
|
|
|
use app\common\model\Region;
|
|
|
|
use think\facade\Db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 服务类:商品批量导入
|
|
|
|
* Class Import
|
|
|
|
* @package app\job\service\goods
|
|
|
|
*/
|
|
|
|
class StoreGoodsOnline extends BaseService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 批量导入商品
|
|
|
|
* @param array $list
|
|
|
|
* @param int $recordId
|
|
|
|
* @param int $storeId
|
|
|
|
* @return bool
|
|
|
|
* @throws BaseException
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
*/
|
|
|
|
public function batch(array $goodsIds): bool
|
|
|
|
{
|
|
|
|
$goods_list = GoodsModel::whereIn('goods_id', $goodsIds)
|
|
|
|
->where('is_delete',0)
|
|
|
|
->where('status',10)
|
|
|
|
->where('is_pool',1)
|
|
|
|
->field(['goods_id','is_sale','is_pool'])
|
|
|
|
->select();
|
|
|
|
if ($goods_list->isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$goodsIds = array_column($goods_list->toArray(), "goods_id");
|
|
|
|
$platformGoodsList = GoodsModel::whereIn('origin_goods_id', $goodsIds)->field(['goods_id','is_sale','is_pool'])->select();
|
|
|
|
if ($platformGoodsList->isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$up_data = [
|
|
|
|
'is_sale' => 1,
|
|
|
|
'is_pool' => 1,
|
|
|
|
'status' => 10,
|
|
|
|
'is_jd_remove' => 0,
|
|
|
|
'update_time' => time(),
|
|
|
|
'is_delete' => 0
|
|
|
|
];
|
|
|
|
//上架零售商城总后台的商品
|
|
|
|
GoodsModel::whereIn('origin_goods_id', $goodsIds)->update($up_data);
|
|
|
|
//上架零售商城-商城端的商品
|
|
|
|
$platformGoodsIds = array_column($platformGoodsList->toArray(), "goods_id");
|
|
|
|
GoodsModel::whereIn('origin_goods_id', $platformGoodsIds)->update($up_data);
|
|
|
|
//上架批发商城总后台的商品
|
|
|
|
$wholesalePlatformGoodsList = Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->field(['goods_id','is_sale','is_pool'])->select();
|
|
|
|
if ($wholesalePlatformGoodsList->isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->update($up_data);
|
|
|
|
//上架批发商城-商城端的商品
|
|
|
|
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList->toArray(), "goods_id");
|
|
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $wholesalePlatformGoodsIds)->update($up_data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|