mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]修改微信商城数据处理
This commit is contained in:
parent
4af495ab83
commit
6c620c8b09
@ -104,24 +104,24 @@ class GoodsService
|
|||||||
}
|
}
|
||||||
// 统计入库信息
|
// 统计入库信息
|
||||||
$stockField = 'goods_id,goods_spec,ifnull(sum(goods_stock), 0) goods_stock';
|
$stockField = 'goods_id,goods_spec,ifnull(sum(goods_stock), 0) goods_stock';
|
||||||
$stockWhere = ['status' => '1', 'is_deleted' => '0', 'goods_id' => $goods_id, 'mch_id' => $mch_id];
|
$stockWhere = ['status' => '1', 'is_deleted' => '0', 'goods_id' => $goods_id];
|
||||||
$stockList = (array)Db::name('StoreGoodsStock')->field($stockField)->where($stockWhere)->group('goods_id,goods_spec')->select();
|
$stockList = (array)Db::name('StoreGoodsStock')->field($stockField)->where($stockWhere)->group('goods_id,goods_spec')->select();
|
||||||
// 统计销售信息
|
// 统计销售信息
|
||||||
$saleField = 'goods_id,goods_spec,ifnull(sum(number), 0) goods_sale';
|
$saleField = 'goods_id,goods_spec,ifnull(sum(number), 0) goods_sale';
|
||||||
$saleWhere = ['status' => '1', 'is_deleted' => '0', 'goods_id' => $goods_id, 'mch_id' => $mch_id];
|
$saleWhere = ['status' => '1', 'is_deleted' => '0', 'goods_id' => $goods_id];
|
||||||
$saleList = (array)Db::name('StoreOrderList')->field($saleField)->where($saleWhere)->group('goods_id,goods_spec')->select();
|
$saleList = (array)Db::name('StoreOrderList')->field($saleField)->where($saleWhere)->group('goods_id,goods_spec')->select();
|
||||||
// 库存置零
|
// 库存置零
|
||||||
list($where, $total_sale) = [['goods_id' => $goods_id], 0];
|
list($where, $total_sale) = [['goods_id' => $goods_id], 0];
|
||||||
Db::name('StoreGoodsList')->where($where)->update(['goods_stock' => 0, 'goods_sale' => 0, 'mch_id' => $mch_id]);
|
Db::name('StoreGoodsList')->where($where)->update(['goods_stock' => 0, 'goods_sale' => 0]);
|
||||||
// 更新商品库存
|
// 更新商品库存
|
||||||
foreach ($stockList as $stock) {
|
foreach ($stockList as $stock) {
|
||||||
$where = ['goods_id' => $goods_id, 'goods_spec' => $stock['goods_spec'], 'mch_id' => $mch_id];
|
$where = ['goods_id' => $goods_id, 'goods_spec' => $stock['goods_spec']];
|
||||||
Db::name('StoreGoodsList')->where($where)->update(['goods_stock' => $stock['goods_stock']]);
|
Db::name('StoreGoodsList')->where($where)->update(['goods_stock' => $stock['goods_stock']]);
|
||||||
}
|
}
|
||||||
// 更新商品销量
|
// 更新商品销量
|
||||||
foreach ($saleList as $sale) {
|
foreach ($saleList as $sale) {
|
||||||
$total_sale += intval($sale['goods_sale']);
|
$total_sale += intval($sale['goods_sale']);
|
||||||
$where = ['goods_id' => $goods_id, 'goods_spec' => $sale['goods_spec'], 'mch_id' => $mch_id];
|
$where = ['goods_id' => $goods_id, 'goods_spec' => $sale['goods_spec']];
|
||||||
Db::name('StoreGoodsList')->where($where)->update(['goods_sale' => $sale['goods_sale']]);
|
Db::name('StoreGoodsList')->where($where)->update(['goods_sale' => $sale['goods_sale']]);
|
||||||
}
|
}
|
||||||
return ['code' => 1, 'msg' => '同步商品库存成功!'];
|
return ['code' => 1, 'msg' => '同步商品库存成功!'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user