lqmac 3 weeks ago
parent 4993d2d560
commit e65f1ffc3e
  1. 117
      app/admin/controller/Goods.php
  2. 40
      app/job/controller/goods/AdminGoodsUpdate.php
  3. 40
      app/job/controller/goods/StoreGoodsUpdate.php
  4. 100
      app/job/service/goods/AdminGoodsUpdate.php
  5. 4
      app/job/service/goods/StoreGoodsDelete.php
  6. 4
      app/job/service/goods/StoreGoodsOffline.php
  7. 4
      app/job/service/goods/StoreGoodsOnline.php
  8. 97
      app/job/service/goods/StoreGoodsUpdate.php
  9. 4
      app/store/controller/Goods.php

@ -23,6 +23,7 @@ use app\job\controller\goods\GoodsAddPrice as GoodsAddPriceJob;
use app\job\controller\goods\GoodsOffline as GoodsOfflineJob;
use app\job\controller\goods\GoodsOnline as GoodsOnlineJob;
use app\job\controller\goods\GoodsDelete as GoodsDeleteJob;
use app\job\controller\goods\AdminGoodsUpdate as AdminGoodsUpdateJob;
/**
* 商品管理控制器
@ -142,67 +143,71 @@ class Goods extends Controller
// exit();
// 更新记录
if ($model->edit($params, $model)) {
//更新来源数据为当前数据的商品
AdminGoodsUpdateJob::dispatch([
'list' => [$goodsId],
]);
// //更新来源数据为当前数据的商品
$list = GoodsModel::where('origin_goods_id', $goodsId)->field('goods_id')->select();
if (!$list) {
return $this->renderSuccess('更新成功');
}
$goods_sku = GoodsModel::where('goods_id', $goodsId)->where('store_id', 0)->find();
// var_dump($goods_sku->cost_price_min);
// var_dump($goods_sku->markup_rate);
//成本价加价之后的处理
list($cost_price, $profit, $profit_rate) = getGoodsCostAndProfitAndProfitRate($goods_sku->goods_price_min, $goods_sku->cost_price_min, $goods_sku->markup_rate);
$goods_sku->cost_price_min = $cost_price;
$goods_sku->profit = $profit;
$goods_sku->profit_rate = $profit_rate;
// $list = GoodsModel::where('origin_goods_id', $goodsId)->field('goods_id')->select();
// if (!$list) {
// return $this->renderSuccess('更新成功');
// }
// $goods_sku = GoodsModel::where('goods_id', $goodsId)->where('store_id', 0)->find();
// // var_dump($goods_sku->cost_price_min);
// // var_dump($goods_sku->markup_rate);
// //成本价加价之后的处理
// list($cost_price, $profit, $profit_rate) = getGoodsCostAndProfitAndProfitRate($goods_sku->goods_price_min, $goods_sku->cost_price_min, $goods_sku->markup_rate);
// $goods_sku->cost_price_min = $cost_price;
// $goods_sku->profit = $profit;
// $goods_sku->profit_rate = $profit_rate;
// var_dump($cost_price);
// var_dump($profit);
// var_dump($profit_rate);
// exit();
$goods_data = [
'goods_name' => $goods_sku->name,
'content' => $goods_sku->content,
'selling_point' => $goods_sku->selling_point,
'goods_price_min' => $goods_sku->goods_price_min,
'goods_price_max' => $goods_sku->goods_price_max,
'line_price_min' => $goods_sku->line_price_min,
'line_price_max' => $goods_sku->line_price_max,
'cost_price_min' => $goods_sku->cost_price_min,
'profit_rate' => $goods_sku->profit_rate,
'profit' => $goods_sku->profit,
'goods_source' => $goods_sku->goods_source,
'is_check' => $goods_sku->is_check,
'delivery_time' => $goods_sku->delivery_time,
'is_use_jd_stock' => $goods_sku->is_use_jd_stock,
'is_jd_remove' => $goods_sku->is_jd_remove,
'goods_no_other' => $goods_sku->goods_no_other,
'link_other' => $goods_sku->link_other,
'data_type' => $goods_sku->data_type,
// 'is_pool' => $goods_sku->is_pool,
// 'is_sale' => $goods_sku->is_sale,
'update_time' => time(),
];
if ($goods_sku->is_pool != 1 || $goods_sku->is_sale == 0) {
$goods_data['status'] = 20;
$goods_data['is_jd_remove'] = 1;
}
if ($goods_sku->is_pool == 1 && $goods_sku->is_sale == 1) {
$goods_data['status'] = 10;
$goods_data['is_jd_remove'] = 0;
}
GoodsModel::where('origin_goods_id', $goodsId)->update($goods_data);
$goods_sku_data = [
'goods_price' => $goods_sku->goods_price_min,
'cost_price' => $goods_sku->cost_price_min,
'update_time' => time(),
];
// // var_dump($cost_price);
// // var_dump($profit);
// // var_dump($profit_rate);
// // exit();
// $goods_data = [
// 'goods_name' => $goods_sku->name,
// 'content' => $goods_sku->content,
// 'selling_point' => $goods_sku->selling_point,
// 'goods_price_min' => $goods_sku->goods_price_min,
// 'goods_price_max' => $goods_sku->goods_price_max,
// 'line_price_min' => $goods_sku->line_price_min,
// 'line_price_max' => $goods_sku->line_price_max,
// 'cost_price_min' => $goods_sku->cost_price_min,
// 'profit_rate' => $goods_sku->profit_rate,
// 'profit' => $goods_sku->profit,
// 'goods_source' => $goods_sku->goods_source,
// 'is_check' => $goods_sku->is_check,
// 'delivery_time' => $goods_sku->delivery_time,
// 'is_use_jd_stock' => $goods_sku->is_use_jd_stock,
// 'is_jd_remove' => $goods_sku->is_jd_remove,
// 'goods_no_other' => $goods_sku->goods_no_other,
// 'link_other' => $goods_sku->link_other,
// 'data_type' => $goods_sku->data_type,
// // 'is_pool' => $goods_sku->is_pool,
// // 'is_sale' => $goods_sku->is_sale,
// 'update_time' => time(),
// ];
// if ($goods_sku->is_pool != 1 || $goods_sku->is_sale == 0) {
// $goods_data['status'] = 20;
// $goods_data['is_jd_remove'] = 1;
// }
// if ($goods_sku->is_pool == 1 && $goods_sku->is_sale == 1) {
// $goods_data['status'] = 10;
// $goods_data['is_jd_remove'] = 0;
// }
// GoodsModel::where('origin_goods_id', $goodsId)->update($goods_data);
// $goods_sku_data = [
// 'goods_price' => $goods_sku->goods_price_min,
// 'cost_price' => $goods_sku->cost_price_min,
// 'update_time' => time(),
// ];
GoodsSku::whereIn('goods_id', array_column($list->toArray(), "goods_id"))->update($goods_sku_data);
// GoodsSku::whereIn('goods_id', array_column($list->toArray(), "goods_id"))->update($goods_sku_data);
//同步到批发商城
// //同步到批发商城
return $this->renderSuccess('更新成功');
}

@ -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;
}
}

@ -55,12 +55,12 @@ class StoreGoodsDelete extends BaseService
GoodsModel::whereIn('origin_goods_id', $platformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
//删除批发商城总后台的商品
$wholesalePlatformGoodsList = Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->field(['goods_id','is_sale','is_pool'])->select();
if ($wholesalePlatformGoodsList->isEmpty()) {
if (!$wholesalePlatformGoodsList) {
return true;
}
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
//删除批发商城-商城端的商品
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList->toArray(), "goods_id");
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList, "goods_id");
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $wholesalePlatformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
return true;
}

@ -53,12 +53,12 @@ class StoreGoodsOffline extends BaseService
GoodsModel::whereIn('origin_goods_id', $platformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
//删除批发商城总后台的商品
$wholesalePlatformGoodsList = Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->field(['goods_id','is_sale','is_pool'])->select();
if ($wholesalePlatformGoodsList->isEmpty()) {
if (!$wholesalePlatformGoodsList) {
return true;
}
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
//删除批发商城-商城端的商品
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList->toArray(), "goods_id");
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList, "goods_id");
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $wholesalePlatformGoodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
return true;

@ -64,12 +64,12 @@ class StoreGoodsOnline extends BaseService
GoodsModel::whereIn('origin_goods_id', $platformGoodsIds)->update($up_data);
//上架批发商城总后台的商品
$wholesalePlatformGoodsList = Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->field(['goods_id','is_sale','is_pool'])->select();
if ($wholesalePlatformGoodsList->isEmpty()) {
if (!$wholesalePlatformGoodsList) {
return true;
}
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $platformGoodsIds)->update($up_data);
//上架批发商城-商城端的商品
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList->toArray(), "goods_id");
$wholesalePlatformGoodsIds = array_column($wholesalePlatformGoodsList, "goods_id");
Db::connect("dataCenterMysql")->table('yoshop_goods')->whereIn('origin_goods_id', $wholesalePlatformGoodsIds)->update($up_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;
}
}

@ -23,6 +23,7 @@ use app\common\model\Tipoff as ModelTipoff;
use app\job\controller\goods\StoreGoodsOffline as StoreGoodsOfflineJob;
use app\job\controller\goods\StoreGoodsOnline as StoreGoodsOnlineJob;
use app\job\controller\goods\StoreGoodsDelete as StoreGoodsDeleteJob;
use app\job\controller\goods\StoreGoodsUpdate as StoreGoodsUpdateJob;
use app\common\service\Jd;
use app\common\model\wxapp\Setting as WxappSettingModel;
use EasyWeChat\Factory;
@ -197,6 +198,9 @@ class Goods extends Controller
//$params['store_id'] = $this->storeId;
// 更新记录
if ($model->edit($params)) {
StoreGoodsUpdateJob::dispatch([
'list' => [$goodsId],
]);
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');

Loading…
Cancel
Save