123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\common\Service\Order;
- use app\common\model\OrderGoods as OrderGoodsModel;
- use think\Db;
- class OrderGoodsService
- {
- //销量增
- public static function setGoodsSalesInc($order_sn)
- {
- $list = (new OrderGoodsModel())->where('order_sn', $order_sn)->select();
- // 启动事务
- Db::startTrans();
- try {
- foreach ($list as $item) {
- $goods = $item->goods;
- $sku = $item->sku;
- if ($goods) {
- $goods->setInc('sales', $item->nums);
- }
- if ($sku) {
- $sku->setInc('sales', $item->nums);
- }
- }
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- return true;
- }
- //销量减
- public static function setGoodsSalesDec($order_sn)
- {
- $list = (new OrderGoodsModel())->where('order_sn', $order_sn)->select();
- // 启动事务
- Db::startTrans();
- try {
- foreach ($list as $item) {
- $goods = $item->goods;
- $sku = $item->sku;
- if ($goods) {
- $goods->setDec('sales', $item->nums);
- }
- if ($sku) {
- $sku->setDec('sales', $item->nums);
- }
- }
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- return true;
- }
- //库存增
- public static function setGoodsStocksInc($order_sn)
- {
- $list = (new OrderGoodsModel())->where('order_sn', $order_sn)->select();
- // 启动事务
- Db::startTrans();
- try {
- foreach ($list as $item) {
- $goods = $item->goods;
- $sku = $item->sku;
- if ($sku) {
- $sku->setInc('stocks', $item->nums);
- }
- if ($goods) {
- $goods->setInc('stocks', $item->nums);
- }
- }
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- return true;
- }
- //库存减
- public static function setGoodsStocksDec($order_sn)
- {
- $list = (new OrderGoodsModel())->where('order_sn', $order_sn)->select();
- // 启动事务
- Db::startTrans();
- try {
- foreach ($list as $item) {
- $goods = $item->goods;
- $sku = $item->sku;
- if ($sku) {
- $sku->setDec('stocks', $item->nums);
- }
- if ($goods) {
- $goods->setDec('stocks', $item->nums);
- }
- }
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- return true;
- }
- }
|