123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace Scm\Lib;
- use Dever;
- class Stock
- {
- public function show_api()
- {
- $goods = Dever::input('value');
- list($goods_id, $sku_id) = explode('-', $goods);
- $where['goods_id'] = $goods_id;
- $where['sku_id'] = $sku_id;
- $where['servicer_store_id'] = Dever::input('servicer_store_id');
- $info = Dever::db('scm_servicer/store_goods_sku')->getOne($where);
- $result = array();
- $result['goods_id'] = '暂无';
- $result['cash'] = '0.00';
- if ($info) {
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
- $supplier_id = Dever::input('supplier_id');
- if ($supplier_id) {
- $where['supplier_id'] = $supplier_id;
- $sku = Dever::db('scm_supplier/goods_sku')->getOne($where);
- $info['cash'] = isset($sku['cost_price']) && $sku['cost_price'] ? $sku['cost_price'] : $goods_info['cost_price'];
- }
- $result['goods_id'] = '库存:' . $info['total'] . $goods_info['unit'];
- $result['cash'] = $info['cash'];
- }
- return array('data' => $result, 'html' => '');
- }
- public function out_check($id, $name, $data)
- {
- $table = Dever::input('table');
- $col = Dever::input('col');
- $goods = Dever::param('goods', $data);
- list($goods_id, $sku_id) = explode('-', $goods);
- $where['goods_id'] = $goods_id;
- $where['sku_id'] = $sku_id;
- $where[$col] = Dever::input('update_' . $col);
- $info = Dever::db($table)->getOne($where);
- if ($info) {
- $num = Dever::param('num', $data);
- if ($info['total'] < $num) {
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
- return Dever::alert('【' . $goods_info['aname'] . '】剩余库存:' . $info['total'] . $goods_info['unit'] . ',已不足出库');
- }
- } else {
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
- return Dever::alert('【' . $goods_info['aname'] . '】剩余库存:0' . $goods_info['unit'] . ',已不足出库');
- }
- }
- # 更新库存
- 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);
- }
- Dever::db($table . '_goods')->updates(array('option_order_id' => $info['id'], 'set_status' => $update['status']));
- }
- }
- 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) {
- if ($type == 'in') {
- if (!$v['batch']) {
- $v['batch'] = date('Ymd');
- }
- $where['batch'] = $v['batch'];
- $where['cash'] = $v['cash'];
- }
- $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);
- //Dever::db($table . '_goods')->update(array('where_id' => $v['id'], 'status' => 2));
- }
- }
- }
- }
- }
|