diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 2e549818..998c36e5 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/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('更新成功'); } diff --git a/app/job/controller/goods/AdminGoodsUpdate.php b/app/job/controller/goods/AdminGoodsUpdate.php new file mode 100644 index 00000000..6138fbe6 --- /dev/null +++ b/app/job/controller/goods/AdminGoodsUpdate.php @@ -0,0 +1,40 @@ +batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/controller/goods/StoreGoodsUpdate.php b/app/job/controller/goods/StoreGoodsUpdate.php new file mode 100644 index 00000000..336e8b51 --- /dev/null +++ b/app/job/controller/goods/StoreGoodsUpdate.php @@ -0,0 +1,40 @@ +batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/service/goods/AdminGoodsUpdate.php b/app/job/service/goods/AdminGoodsUpdate.php new file mode 100644 index 00000000..dbb45781 --- /dev/null +++ b/app/job/service/goods/AdminGoodsUpdate.php @@ -0,0 +1,100 @@ +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; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/StoreGoodsDelete.php b/app/job/service/goods/StoreGoodsDelete.php index dfa763f4..685c9355 100644 --- a/app/job/service/goods/StoreGoodsDelete.php +++ b/app/job/service/goods/StoreGoodsDelete.php @@ -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; } diff --git a/app/job/service/goods/StoreGoodsOffline.php b/app/job/service/goods/StoreGoodsOffline.php index 4a65abd0..5ed83546 100644 --- a/app/job/service/goods/StoreGoodsOffline.php +++ b/app/job/service/goods/StoreGoodsOffline.php @@ -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; diff --git a/app/job/service/goods/StoreGoodsOnline.php b/app/job/service/goods/StoreGoodsOnline.php index a4303bbc..02f50395 100644 --- a/app/job/service/goods/StoreGoodsOnline.php +++ b/app/job/service/goods/StoreGoodsOnline.php @@ -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; } diff --git a/app/job/service/goods/StoreGoodsUpdate.php b/app/job/service/goods/StoreGoodsUpdate.php new file mode 100644 index 00000000..47e14edb --- /dev/null +++ b/app/job/service/goods/StoreGoodsUpdate.php @@ -0,0 +1,97 @@ +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; + + } + + +} \ No newline at end of file diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 51cd2c58..d5df75ee 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -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() ?: '更新失败');