|
@@ -143,23 +143,25 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
- if ($rs->inventory != $data['inventory']) {
|
|
|
- Db::name('inventory_exchange_log')->insert([
|
|
|
- 'inventory_exchange_id' => $data['id'],
|
|
|
- 'before_inventory' => $rs->inventory,
|
|
|
- 'after_inventory' => $data['inventory'],
|
|
|
- 'good_id' => $rs->good_id,
|
|
|
- 'good_code' => $rs->good_code,
|
|
|
- 'good_name' => $rs->good_name,
|
|
|
- 'source' => CommonModel::$source_admin,
|
|
|
- 'createrid' => self::$uid,
|
|
|
- 'creater' => self::$uname,
|
|
|
- 'addtime' => $date,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
+ $inventory = bcadd($rs->inventory, bcmul($data['flag'], $data['number']));
|
|
|
+
|
|
|
+ if ($inventory < 0) throw new Exception('最终库存数少于0');
|
|
|
+
|
|
|
+ Db::name('inventory_exchange_log')->insert([
|
|
|
+ 'inventory_exchange_id' => $data['id'],
|
|
|
+ 'before_inventory' => $rs->inventory,
|
|
|
+ 'after_inventory' => $inventory,
|
|
|
+ 'flag' => $data['flag'],
|
|
|
+ 'good_id' => $rs->good_id,
|
|
|
+ 'good_code' => $rs->good_code,
|
|
|
+ 'good_name' => $rs->good_name,
|
|
|
+ 'source' => CommonModel::$source_admin,
|
|
|
+ 'createrid' => self::$uid,
|
|
|
+ 'creater' => self::$uname,
|
|
|
+ 'addtime' => $date,
|
|
|
+ ]);
|
|
|
InventoryExchangeModel::where('id', $data['id'])
|
|
|
- ->save(array_merge($data, ['updatetime' => $date, 'updaterid' => self::$uid, 'updater' => self::$uname]));
|
|
|
+ ->save(['updatetime' => $date, 'updaterid' => self::$uid, 'updater' => self::$uname, 'inventory' => $inventory]);
|
|
|
|
|
|
Db::commit();
|
|
|
|