You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
4.4 KiB
101 lines
4.4 KiB
<?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 AdminGoodsUpdate 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,goods_name,cmmdty_model,goods_source,delivery_time,is_check,is_use_jd_stock,is_pool,is_sale,goods_price_min,cost_price_min,profit,profit_rate,stock_total,content,selling_point,remark,region,region_text,goods_price_max,line_price_min,line_price_max,is_jd_remove,goods_no_other,link_other,data_type,markup_rate')
|
|
->select();
|
|
if ($goods_list->isEmpty()) {
|
|
return true;
|
|
}
|
|
$goods_list = $goods_list->toArray();
|
|
foreach ($goods_list as &$item) {
|
|
$platformGoodsId = $item['goods_id'];
|
|
if ($item['is_pool'] == 1 && $item['is_sale'] == 1) {
|
|
$item['is_delete'] = 0;
|
|
$item['status'] = 10;
|
|
$item['is_jd_remove'] = 0;
|
|
} else {
|
|
$item['is_delete'] = 1;
|
|
}
|
|
list($cost_price, $profit, $profit_rate) = getGoodsCostAndProfitAndProfitRate($item['goods_price_min'],$item['cost_price_min'],$item['markup_rate']);
|
|
|
|
$item['cost_price_min'] = $cost_price;
|
|
$item['profit'] = $profit;
|
|
$item['profit_rate'] = $profit_rate;
|
|
$item['update_time'] = time();
|
|
$item['sale_time'] = time();
|
|
unset($item['goods_id']);
|
|
unset($item['goods_sales']);
|
|
|
|
$sku_data = [
|
|
'goods_price' => $item['goods_price_min'],
|
|
'cost_price' => $item['cost_price_min'],
|
|
'stock_num' => $item['stock_total'],
|
|
];
|
|
//上架零售商城-商城端的商品
|
|
$goods = GoodsModel::where('origin_goods_id', $platformGoodsId)->field(['goods_id','is_sale','is_pool'])->select();
|
|
if (!$goods->isEmpty()) {
|
|
$goodsIds = array_column($goods->toArray(), "goods_id");
|
|
GoodsModel::whereIn('goods_id', $goodsIds)->update($item);
|
|
GoodsSku::whereIn('goods_id', $goodsIds)->update($sku_data);
|
|
}
|
|
|
|
|
|
//上架批发商城总后台的商品
|
|
$wholesalePlatformGoods = Db::connect("dataCenterMysql")->table('yoshop_goods')->where('origin_goods_id', $platformGoodsId)->field(['goods_id','is_sale','is_pool'])->find();
|
|
if (!$wholesalePlatformGoods) {
|
|
continue;
|
|
}
|
|
$wholesalePlatformGoodsId = $wholesalePlatformGoods['goods_id'];
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods')->where('goods_id', $wholesalePlatformGoodsId)->update($item);
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods_sku')->where('goods_id', $wholesalePlatformGoodsId)->update($sku_data);
|
|
//上架批发商城-商城端的商品
|
|
$wholesaleGoods = Db::connect("dataCenterMysql")->table('yoshop_goods')->where('origin_goods_id', $wholesalePlatformGoodsId)->field(['goods_id','is_sale','is_pool'])->select();
|
|
if (!$wholesaleGoods) {
|
|
$wholesaleGoodsIds = array_column($wholesaleGoods, "goods_id");
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('goods_id', $wholesaleGoodsIds)->update($item);
|
|
Db::connect("dataCenterMysql")->table('yoshop_goods_sku')->whereIn('goods_id', $wholesaleGoodsIds)->update($sku_data);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
} |