123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Scm_product\Lib;
- use Dever;
- class Stock
- {
- # 更新库存
- public function update_commit($id, $name, $data)
- {
- $table = Dever::input('table');
- $type = Dever::input('type');
- $col = Dever::input('col');
- $stock = Dever::input('stock');
- $info = Dever::db($table)->find($id);
- if ($table && $type && $info && $info['status'] == 1) {
- $audit = Dever::param('audit', $data);
- $admin = Dever::load('manage/auth.info');
- if ($admin) {
- $update['audit_admin'] = $admin['id'];
- }
- $update['status'] = $audit;
- $update['where_id'] = $id;
- Dever::db($table)->update($update);
- if ($audit == 2) {
- # 审核通过 更新库存
- $this->up($table, $type, $col, $stock, $info);
- }
- }
- }
- public function up($table, $type, $col, $stock, $info)
- {
- if ($col && $stock && isset($info[$col])) {
- $order_goods = Dever::db($table . '_goods')->select(array('order_id' => $info['id'], 'status' => 1));
- if ($order_goods) {
- foreach ($order_goods as $k => $v) {
- $update = array('goods_id' => $v['goods_id'], $col => $info[$col]);
- $goods = Dever::db($stock)->find($update);
- if (!$goods) {
- Dever::db($stock)->insert($update);
- }
- $update['sku_id'] = $v['sku_id'];
- $goods = Dever::db($stock . '_sku')->find($update);
- if (!$goods) {
- $id = Dever::db($stock . '_sku')->insert($update);
- $where['where_id'] = $id;
- } else {
- $where['where_id'] = $goods['id'];
- }
- $where[$type . '_num'] = $v['num'];
- $method = $type . 'Update';
- Dever::db($stock . '_sku')->$method($where);
- }
- }
- }
- }
- }
|