diff --git a/app/admin/controller/Controller.php b/app/admin/controller/Controller.php index 604966a8..9fcad99f 100644 --- a/app/admin/controller/Controller.php +++ b/app/admin/controller/Controller.php @@ -79,8 +79,8 @@ class Controller extends BaseController if (strpos($this->admin['user']['channel'], 'jd') !== false) { $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select(); //苏宁账号可以看到苏宁和自营的 - } elseif($this->admin['user']['channel'] == 'sn'){ - $list = Channel::where('status', 1)->whereIn('code',['sn','zy'])->select(); + } elseif(strpos($this->admin['user']['channel'], 'sn') !== false){ + $list = Channel::where('status', 1)->whereIn('code',[$this->admin['user']['channel'],'zy'])->select(); //新阙通信账号可以看到新阙通信和自营的 } elseif($this->admin['user']['channel'] == 'xqtx'){ $list = Channel::where('status', 1)->whereIn('code',['xqtx','zy'])->select(); diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 714ab055..a4da2e11 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -349,48 +349,60 @@ class Goods extends Controller public function addPrice(array $categoryIds, int $rate){ // ini_set('memory_limit', '1024M'); // 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) { return $this->renderSuccess('没有需要加价的商品'); } - $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); - if (!$goods) { - return $this->renderSuccess('没有需要加价的商品'); + //更新总后台当前商品的价格 + GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]); + 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([ - 'categoryIds' => $categoryIds, - 'rate' => $rate, - ]); - // 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); - // } - - // } + // GoodsAddPriceJob::dispatch([ + // 'categoryIds' => $categoryIds, + // 'rate' => $rate, + // 'channels' => $channels, + // ]); return $this->renderSuccess('加价成功'); } diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index d6225f85..1068c6ac 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -455,12 +455,15 @@ class Goods extends BaseModel $params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']]; $a = 1; // 商品分类 - if ($params['categoryId'] > 0) { + if ($params['categoryId'] > 0 || (isset($params['fliter_condition']) && $params['fliter_condition'])) { // 关联商品与分类关系记录表 $GoodsCategoryRelName = (new GoodsCategoryRelModel())->getName(); $query->join($GoodsCategoryRelName, "{$GoodsCategoryRelName}.goods_id = {$this->name}.goods_id"); - // 设置分类ID条件 - $query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); + if ($params['categoryId'] > 0) { + // 设置分类ID条件 + $query->where('goods_category_rel.category_id', 'in', explode(",", (string)$params['categoryId'])); + } + } if (isset($param['goodsIds']) && $param['goodsIds'] !== '') { @@ -591,7 +594,7 @@ class Goods extends BaseModel { $channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find(); 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 { $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_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::isStore()) {//店主 diff --git a/app/common/model/sharp/Goods.php b/app/common/model/sharp/Goods.php index a58523f2..084920a2 100644 --- a/app/common/model/sharp/Goods.php +++ b/app/common/model/sharp/Goods.php @@ -112,7 +112,7 @@ class Goods extends BaseModel $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']['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); } diff --git a/app/job/controller/goods/GoodsAddPrice.php b/app/job/controller/goods/GoodsAddPrice.php index 4dd04ab0..776d28ef 100644 --- a/app/job/controller/goods/GoodsAddPrice.php +++ b/app/job/controller/goods/GoodsAddPrice.php @@ -44,6 +44,6 @@ class GoodsAddPrice extends BaseJob echo "\n ---- GoodsAddPrice ---- {$time} ---- \n"; $service = new GoodsAddPriceService; - return $service->batch($data['categoryIds'], $data['rate']); + return $service->batch($data['categoryIds'], $data['rate'], $data['channels']); } } \ No newline at end of file diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index b59078f1..62fdc707 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -260,7 +260,8 @@ class Collector extends BaseService $original['cost_price'] = $form['cost_price_min']; $data['link_other'] = $url; - $data['goods_no'] = $original['goods_sku_no']; + + $data['content'] = $original['content']; //重新计算利润和利润率 @@ -285,6 +286,7 @@ class Collector extends BaseService ]; //新阙通信的数据 if ($goods->channel == "xqtx") { + $data['goods_no'] = $original['goods_sku_no']; //goods $data['stock_total'] = $form['stock_total']; $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 = $profit_rate > 0.0001 ? bcmul((string)$profit_rate, "100", 2) : 0.00; $data['profit_rate'] = $profit_rate; + $data['link'] = $data['link_other']; unset($data['link_other']); //sku $goodsSku['stock_num'] = $form['stock_total']; //unset($goodsSku['goods_price']); + } else { + //京东价拖 + $data['goods_no_other'] = $original['goods_sku_no']; } // var_dump($data); // var_dump($goodsSku); diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php index 6bf25a7a..20460fdf 100644 --- a/app/job/service/goods/GoodsAddPrice.php +++ b/app/job/service/goods/GoodsAddPrice.php @@ -39,46 +39,58 @@ class GoodsAddPrice extends BaseService * @throws \think\db\exception\DbException * @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(); - if (!$goods) { - return true; - } - $goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); + ini_set('memory_limit', '1024M'); + set_time_limit(0); + $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) + ->order("g.goods_id asc") + ->select() + ->toArray(); if (!$goods) { return true; } + //更新总后台当前商品的价格 + GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]); 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(); + $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; } - 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); + $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); + } + return true; } diff --git a/config/log.php b/config/log.php index 0bdb0303..6fe24583 100644 --- a/config/log.php +++ b/config/log.php @@ -7,7 +7,7 @@ return [ // 默认日志记录通道 'default' => env('log.channel', 'file'), // 日志记录级别 - 'level' => [], + 'level' => ['error', 'sql', 'info'], // 日志类型记录的通道 ['error'=>'email',...] 'type_channel' => [], // 关闭全局日志写入 diff --git a/config/queue.php b/config/queue.php index 7982d77c..52900d43 100644 --- a/config/queue.php +++ b/config/queue.php @@ -27,7 +27,7 @@ return [ 'host' => env('redis.hostname', '127.0.0.1'), 'port' => env('redis.hostport', '6379'), 'password' => env('redis.password', ''), - 'select' => env('redis.select', '0'), + 'select' => 1,//env('redis.select', '0'), 'timeout' => 0, 'persistent' => false, 'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒