lqmac 6 months ago
parent 9042626a77
commit 1c592065a0
  1. 4
      app/admin/controller/Controller.php
  2. 88
      app/admin/controller/Goods.php
  3. 14
      app/common/model/Goods.php
  4. 2
      app/common/model/sharp/Goods.php
  5. 2
      app/job/controller/goods/GoodsAddPrice.php
  6. 8
      app/job/service/goods/Collector.php
  7. 70
      app/job/service/goods/GoodsAddPrice.php
  8. 2
      config/log.php
  9. 2
      config/queue.php

@ -79,8 +79,8 @@ class Controller extends BaseController
if (strpos($this->admin['user']['channel'], 'jd') !== false) { if (strpos($this->admin['user']['channel'], 'jd') !== false) {
$list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select(); $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select();
//苏宁账号可以看到苏宁和自营的 //苏宁账号可以看到苏宁和自营的
} elseif($this->admin['user']['channel'] == 'sn'){ } elseif(strpos($this->admin['user']['channel'], 'sn') !== false){
$list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select(); $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select();
//新阙通信账号可以看到新阙通信和自营的 //新阙通信账号可以看到新阙通信和自营的
} elseif($this->admin['user']['channel'] == 'xqtx'){ } elseif($this->admin['user']['channel'] == 'xqtx'){
$list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select(); $list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select();

@ -349,48 +349,60 @@ class Goods extends Controller
public function addPrice(array $categoryIds, int $rate){ public function addPrice(array $categoryIds, int $rate){
// ini_set('memory_limit', '1024M'); // ini_set('memory_limit', '1024M');
// set_time_limit(0); // set_time_limit(0);
$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray(); $platform = $this->getUserPlatform();
$channels = $platform ? array_column($platform->toArray(), "code") : [];
$goods = GoodsModel::alias('g')
->join('goods_category_rel c', 'g.goods_id = c.goods_id')
->where('c.store_id',0)
->where('g.is_delete',0)
->whereIn('c.category_id',$categoryIds)
->whereIn('g.channel', $channels)
->limit(100)
->select()
->toArray();
if (!$goods) { if (!$goods) {
return $this->renderSuccess('没有需要加价的商品'); return $this->renderSuccess('没有需要加价的商品');
} }
$goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); //更新总后台当前商品的价格
if (!$goods) { GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]);
return $this->renderSuccess('没有需要加价的商品'); foreach ($goods as $key => $value) {
//更新origin_goods_id为当前商品id的价格
$goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])
->where('is_delete', 0)
->field(['goods_id','cost_price_min','goods_price_min','markup_rate'])
->select()
->toArray();
if (!$goods_list) {
continue;
}
$item = $goods_list[0];
if ($item['markup_rate'] > 0) {
$item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
}
$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()
];
GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData);
$goodsSkuData = [
'cost_price' => $cost_price,
'update_time' => time()
];
GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData);
} }
GoodsAddPriceJob::dispatch([ // GoodsAddPriceJob::dispatch([
'categoryIds' => $categoryIds, // 'categoryIds' => $categoryIds,
'rate' => $rate, // 'rate' => $rate,
]); // 'channels' => $channels,
// 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 $this->renderSuccess('加价成功'); return $this->renderSuccess('加价成功');
} }

@ -455,12 +455,15 @@ class Goods extends BaseModel
$params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']]; $params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']];
$a = 1; $a = 1;
// 商品分类 // 商品分类
if ($params['categoryId'] > 0) { if ($params['categoryId'] > 0 || (isset($params['fliter_condition']) && $params['fliter_condition'])) {
// 关联商品与分类关系记录表 // 关联商品与分类关系记录表
$GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName(); $GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName();
$query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id"); $query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id");
// 设置分类ID条件 if ($params['categoryId'] > 0) {
$query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); // 设置分类ID条件
$query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId']));
}
} }
if (isset($param['goodsIds']) && $param['goodsIds'] !== '') { if (isset($param['goodsIds']) && $param['goodsIds'] !== '') {
@ -591,7 +594,7 @@ class Goods extends BaseModel
{ {
$channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find(); $channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find();
if (isset($goodsInfo['dic']) && $goodsInfo['dic'] == 'admin') { if (isset($goodsInfo['dic']) && $goodsInfo['dic'] == 'admin') {
$goodsInfo['channel_name'] = $channel['name'] ?? ""; $goodsInfo['channel_name'] = (isset($channel['name'])&& $channel['name']) ? $channel['alias']."-".$channel['name'] : "";
} else { } else {
$goodsInfo['channel_name'] = $channel['alias'] ?? ""; $goodsInfo['channel_name'] = $channel['alias'] ?? "";
} }
@ -602,6 +605,9 @@ class Goods extends BaseModel
$goodsInfo['goods_image'] = $goodsInfo['goods_images'] ? current($goodsInfo['goods_images'])['preview_url'] : ""; $goodsInfo['goods_image'] = $goodsInfo['goods_images'] ? current($goodsInfo['goods_images'])['preview_url'] : "";
// 商品销量(实际显示=初始虚拟销量+实际销量) // 商品销量(实际显示=初始虚拟销量+实际销量)
$goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual']; $goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual'];
if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other']) {
$goodsInfo['link'] = $goodsInfo['link_other'];
}
// //商品价格判断 // //商品价格判断
// if (UserService::isLogin()) { // if (UserService::isLogin()) {
// if (UserService::isStore()) {//店主 // if (UserService::isStore()) {//店主

@ -112,7 +112,7 @@ class Goods extends BaseModel
$item['goods_image'] = !empty($item['goods']['goods_image']) ? $item['goods']['goods_image'] : ''; $item['goods_image'] = !empty($item['goods']['goods_image']) ? $item['goods']['goods_image'] : '';
// 秒杀商品原价 (获取主商品价格) // 秒杀商品原价 (获取主商品价格)
//$item['original_price'] = !empty($item['goods']['original_price']) ? $item['goods']['original_price']: $item['goods']['goods_price_min']; //$item['original_price'] = !empty($item['goods']['original_price']) ? $item['goods']['original_price']: $item['goods']['goods_price_min'];
$item['original_price'] = !empty($item['goods']['original_price']) ?? $item['goods']['goods_price_min']; $item['original_price'] = isset($item['goods']['original_price']) ? $item['goods']['original_price'] : $item['goods']['goods_price_min'];
// 回调函数 // 回调函数
is_callable($callback) && call_user_func($callback, $item); is_callable($callback) && call_user_func($callback, $item);
} }

@ -44,6 +44,6 @@ class GoodsAddPrice extends BaseJob
echo "\n ---- GoodsAddPrice ---- {$time} ---- \n"; echo "\n ---- GoodsAddPrice ---- {$time} ---- \n";
$service = new GoodsAddPriceService; $service = new GoodsAddPriceService;
return $service->batch($data['categoryIds'], $data['rate']); return $service->batch($data['categoryIds'], $data['rate'], $data['channels']);
} }
} }

@ -260,7 +260,8 @@ class Collector extends BaseService
$original['cost_price'] = $form['cost_price_min']; $original['cost_price'] = $form['cost_price_min'];
$data['link_other'] = $url; $data['link_other'] = $url;
$data['goods_no'] = $original['goods_sku_no'];
$data['content'] = $original['content']; $data['content'] = $original['content'];
//重新计算利润和利润率 //重新计算利润和利润率
@ -285,6 +286,7 @@ class Collector extends BaseService
]; ];
//新阙通信的数据 //新阙通信的数据
if ($goods->channel == "xqtx") { if ($goods->channel == "xqtx") {
$data['goods_no'] = $original['goods_sku_no'];
//goods //goods
$data['stock_total'] = $form['stock_total']; $data['stock_total'] = $form['stock_total'];
$data['goods_name'] = $original['goods_name']; $data['goods_name'] = $original['goods_name'];
@ -294,11 +296,15 @@ class Collector extends BaseService
$profit_rate = (float)$original['goods_price'] > 0 ? ($original['goods_price'] - $original['cost_price']) / $original['goods_price'] : 0.00; $profit_rate = (float)$original['goods_price'] > 0 ? ($original['goods_price'] - $original['cost_price']) / $original['goods_price'] : 0.00;
$profit_rate = $profit_rate > 0.0001 ? bcmul((string)$profit_rate, "100", 2) : 0.00; $profit_rate = $profit_rate > 0.0001 ? bcmul((string)$profit_rate, "100", 2) : 0.00;
$data['profit_rate'] = $profit_rate; $data['profit_rate'] = $profit_rate;
$data['link'] = $data['link_other'];
unset($data['link_other']); unset($data['link_other']);
//sku //sku
$goodsSku['stock_num'] = $form['stock_total']; $goodsSku['stock_num'] = $form['stock_total'];
//unset($goodsSku['goods_price']); //unset($goodsSku['goods_price']);
} else {
//京东价拖
$data['goods_no_other'] = $original['goods_sku_no'];
} }
// var_dump($data); // var_dump($data);
// var_dump($goodsSku); // var_dump($goodsSku);

@ -39,46 +39,58 @@ class GoodsAddPrice extends BaseService
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function batch(array $categoryIds, int $rate): bool public function batch(array $categoryIds, int $rate, array $channels): bool
{ {
$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray(); ini_set('memory_limit', '1024M');
if (!$goods) { set_time_limit(0);
return true; $goods = GoodsModel::alias('g')
} ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
$goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); ->where('c.store_id',0)
->where('g.is_delete',0)
->whereIn('c.category_id', $categoryIds)
->whereIn('g.channel',$channels)
->order("g.goods_id asc")
->select()
->toArray();
if (!$goods) { if (!$goods) {
return true; return true;
} }
//更新总后台当前商品的价格
GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]);
foreach ($goods as $key => $value) { 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的价格 //更新origin_goods_id为当前商品id的价格
$goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select(); $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])
->where('is_delete', 0)
->field(['goods_id','cost_price_min','goods_price_min','markup_rate'])
->select()
->toArray();
if (!$goods_list) { if (!$goods_list) {
continue; continue;
} }
foreach ($goods_list as $item) { $item = $goods_list[0];
$cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0); if ($item['markup_rate'] > 0) {
$profit = (float)$item['goods_price_min'] - (float)$cost_price; $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0);
$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);
} }
$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()
];
GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData);
$goodsSkuData = [
'cost_price' => $cost_price,
'update_time' => time()
];
GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData);
} }
return true; return true;
} }

@ -7,7 +7,7 @@ return [
// 默认日志记录通道 // 默认日志记录通道
'default' => env('log.channel', 'file'), 'default' => env('log.channel', 'file'),
// 日志记录级别 // 日志记录级别
'level' => [], 'level' => ['error', 'sql', 'info'],
// 日志类型记录的通道 ['error'=>'email',...] // 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [], 'type_channel' => [],
// 关闭全局日志写入 // 关闭全局日志写入

@ -27,7 +27,7 @@ return [
'host' => env('redis.hostname', '127.0.0.1'), 'host' => env('redis.hostname', '127.0.0.1'),
'port' => env('redis.hostport', '6379'), 'port' => env('redis.hostport', '6379'),
'password' => env('redis.password', ''), 'password' => env('redis.password', ''),
'select' => env('redis.select', '0'), 'select' => 1,//env('redis.select', '0'),
'timeout' => 0, 'timeout' => 0,
'persistent' => false, 'persistent' => false,
'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒 'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒

Loading…
Cancel
Save