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