master
parent
4993d2d560
commit
e65f1ffc3e
@ -0,0 +1,40 @@ |
||||
<?php |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\job\controller\goods; |
||||
|
||||
use app\job\service\goods\AdminGoodsUpdate as AdminGoodsUpdateService; |
||||
use cores\BaseJob; |
||||
use cores\traits\QueueTrait; |
||||
use cores\exception\BaseException; |
||||
use think\db\exception\DataNotFoundException; |
||||
use think\db\exception\DbException; |
||||
use think\db\exception\ModelNotFoundException; |
||||
|
||||
/** |
||||
* 队列任务:商品批量导入 |
||||
* Class Import |
||||
* @package app\job\controller |
||||
*/ |
||||
class AdminGoodsUpdate extends BaseJob |
||||
{ |
||||
use QueueTrait; |
||||
|
||||
/** |
||||
* 消费队列任务:商品导入 |
||||
* @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] |
||||
* @return bool 返回结果 |
||||
* @throws BaseException |
||||
* @throws DataNotFoundException |
||||
* @throws DbException |
||||
* @throws ModelNotFoundException |
||||
*/ |
||||
public function handle(array $data): bool |
||||
{ |
||||
$time = date('H:i:s'); |
||||
echo "\n ---- AdminGoodsUpdate ---- {$time} ---- \n"; |
||||
|
||||
$service = new AdminGoodsUpdateService; |
||||
return $service->batch($data['list']); |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
<?php |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\job\controller\goods; |
||||
|
||||
use app\job\service\goods\StoreGoodsUpdate as StoreGoodsUpdateService; |
||||
use cores\BaseJob; |
||||
use cores\traits\QueueTrait; |
||||
use cores\exception\BaseException; |
||||
use think\db\exception\DataNotFoundException; |
||||
use think\db\exception\DbException; |
||||
use think\db\exception\ModelNotFoundException; |
||||
|
||||
/** |
||||
* 队列任务:商品批量导入 |
||||
* Class Import |
||||
* @package app\job\controller |
||||
*/ |
||||
class StoreGoodsUpdate extends BaseJob |
||||
{ |
||||
use QueueTrait; |
||||
|
||||
/** |
||||
* 消费队列任务:商品导入 |
||||
* @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] |
||||
* @return bool 返回结果 |
||||
* @throws BaseException |
||||
* @throws DataNotFoundException |
||||
* @throws DbException |
||||
* @throws ModelNotFoundException |
||||
*/ |
||||
public function handle(array $data): bool |
||||
{ |
||||
$time = date('H:i:s'); |
||||
echo "\n ---- StoreGoodsUpdate ---- {$time} ---- \n"; |
||||
|
||||
$service = new StoreGoodsUpdateService; |
||||
return $service->batch($data['list']); |
||||
} |
||||
} |
@ -0,0 +1,100 @@ |
||||
<?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'], |
||||
]; |
||||
//上架零售商城-商城端的商品 |
||||
$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; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,97 @@ |
||||
<?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 StoreGoodsUpdate 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,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') |
||||
->select(); |
||||
if ($goods_list->isEmpty()) { |
||||
return true; |
||||
} |
||||
$goods_list = $goods_list->toArray(); |
||||
foreach ($goods_list as &$item) { |
||||
$goods_id = $item['goods_id']; |
||||
$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'], |
||||
]; |
||||
$platformGoods = GoodsModel::where('origin_goods_id', $goods_id)->field(['goods_id','is_sale','is_pool'])->find(); |
||||
if (!$platformGoods) { |
||||
continue; |
||||
} |
||||
$platformGoodsId = $platformGoods->goods_id; |
||||
//上架零售商城总后台的商品 |
||||
GoodsModel::where('goods_id', $platformGoodsId)->update($item); |
||||
GoodsSku::where('goods_id', $platformGoodsId)->update($sku_data); |
||||
//上架零售商城-商城端的商品 |
||||
$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; |
||||
|
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue