es
parent
a3ce788013
commit
9042626a77
@ -0,0 +1,49 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
declare (strict_types=1); |
||||
|
||||
namespace app\job\controller\goods; |
||||
|
||||
use app\job\service\goods\GoodsAddPrice as GoodsAddPriceService; |
||||
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 GoodsAddPrice 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 ---- GoodsAddPrice ---- {$time} ---- \n"; |
||||
|
||||
$service = new GoodsAddPriceService; |
||||
return $service->batch($data['categoryIds'], $data['rate']); |
||||
} |
||||
} |
@ -0,0 +1,86 @@ |
||||
<?php |
||||
// +---------------------------------------------------------------------- |
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ] |
||||
// +---------------------------------------------------------------------- |
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved. |
||||
// +---------------------------------------------------------------------- |
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行 |
||||
// +---------------------------------------------------------------------- |
||||
// | Author: 萤火科技 <admin@yiovo.com> |
||||
// +---------------------------------------------------------------------- |
||||
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; |
||||
/** |
||||
* 服务类:商品批量导入 |
||||
* Class Import |
||||
* @package app\job\service\goods |
||||
*/ |
||||
class GoodsAddPrice 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 $categoryIds, int $rate): bool |
||||
{ |
||||
$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray(); |
||||
if (!$goods) { |
||||
return true; |
||||
} |
||||
$goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); |
||||
if (!$goods) { |
||||
return true; |
||||
} |
||||
foreach ($goods as $key => $value) { |
||||
//更新总后台当前商品的价格 |
||||
GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]); |
||||
//更新origin_goods_id为当前商品id的价格 |
||||
$goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select(); |
||||
if (!$goods_list) { |
||||
continue; |
||||
} |
||||
foreach ($goods_list as $item) { |
||||
$cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0); |
||||
$profit = (float)$item['goods_price_min'] - (float)$cost_price; |
||||
$profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00; |
||||
$goodsData = [ |
||||
'cost_price_min' => $cost_price, |
||||
'profit_rate' => $profit_rate, |
||||
'profit' => $profit, |
||||
'markup_rate' => $rate, |
||||
'update_time' => time() |
||||
]; |
||||
// var_dump($goodsData); |
||||
// exit(); |
||||
GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData); |
||||
$goodsSkuData = [ |
||||
'cost_price' => $cost_price, |
||||
'update_time' => time() |
||||
]; |
||||
GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData); |
||||
} |
||||
|
||||
} |
||||
return true; |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue