dever há 2 anos atrás
pai
commit
7600149bf4

+ 41 - 0
lib/Price.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Scm\Lib;
+
+use Dever;
+
+class Price
+{
+    public function __construct()
+    {
+        Dever::load('manage/auth.init');
+    }
+
+    # 根据单位获取价格
+    public function getByUnit($goods_id, $sku_id, $unit_id, $num, $col = 'cost_price', $supplier_id = false)
+    {
+        $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
+        $result = array();
+
+        if ($goods_info) {
+            $where['goods_id'] = $goods_id;
+            $where['sku_id'] = $sku_id;
+
+            # 获取供应商供货价
+            if ($supplier_id) {
+                $where['supplier_id'] = $supplier_id;
+                $sku = Dever::db('scm_supplier/goods_sku')->getOne($where);
+            }
+
+            $result['unit_id'] = $unit_id;
+            $result['base_cash'] = $result['cash'] = isset($sku[$col]) && $sku[$col] ? $sku[$col] : $goods_info[$col];
+                
+            $unit = Dever::db('scm_product/info_unit')->find(array('info_id' => $goods_info['id'], 'unit_id' => $unit_id));
+            if ($unit && $unit['discount'] > 0) {
+                $result['cash'] = $result['cash'] * $unit['radio'] * $unit['discount'];
+            }
+        }
+
+        return $result;
+    }
+}

+ 28 - 13
lib/Stock.php

@@ -36,6 +36,11 @@ class Stock
     	$col = Dever::input('col');
     	$stock = Dever::input('stock');
 
+    	$goods = Dever::db($table . '_goods')->find(array('order_id' => $id));
+    	if (!$goods) {
+    		Dever::db($table)->delete($id);
+    		Dever::alert('未选择商品,新增订单失败');
+    	}
     	$info = Dever::db($table)->find($id);
     	if ($table && $type && $info && $info['status'] == 1) {
     		$audit = Dever::param('audit', $data);
@@ -65,20 +70,30 @@ class Stock
 					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'];
+
+					$result = Dever::load('scm/lib/price')->getByUnit($v['goods_id'], $v['sku_id'], $v['unit_id'], $v['num'], 'cost_price', Dever::input('supplier_id'));
+					if ($result) {
+						$v['unit_id'] = $goods_info['unit_id'];
+						$v['cash'] = $v['base_cash'];
+						$v['num'] = 1;
+					}
+
+					# 入库
+					if ($type == 'in') {
+						if (!$v['batch']) {
+							$v['batch'] = date('Ymd');
+						}
+						$update['sku_id'] = $v['sku_id'];
+						$update['batch'] = $v['batch'];
+						$goods = Dever::db($stock . '_sku')->find($update);
+						if (!$goods) {
+							$update['cash'] = $v['cash'];
+							$update['unit_id'] = $v['unit_id'];
+							$id = Dever::db($stock . '_sku')->insert($update);
+							$where['where_id'] = $id;
+						} else {
+							$where['where_id'] = $goods['id'];
 						}
-						$id = Dever::db($stock . '_sku')->insert($update);
-						$where['where_id'] = $id;
-					} else {
-						$where['where_id'] = $goods['id'];
 					}
 
 					$where[$type . '_num'] = $v['num'];

+ 1 - 1
module/scm_product/database/info.php

@@ -121,7 +121,7 @@ $config = array
 		'id' 		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '商品编码',
+			'name' 		=> '商品ID',
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',

+ 4 - 1
module/scm_product/lib/Info.php

@@ -308,7 +308,7 @@ class Info
     }
 
     # 获取商品的基本信息,只包括名称-价格等信息
-    public function getBaseInfo($info, $sku = false)
+    public function getBaseInfo($info, $sku = false, $unit_id = false)
     {
         $info = is_array($info) ? $info : Dever::db('scm_product/info')->one($info);
 
@@ -316,6 +316,9 @@ class Info
         if ($sku && $sku > 0) {
             $where['id'] = $sku;
         }
+        if ($unit_id) {
+            $info['unit_id'] = $unit_id;
+        }
 
         $info['unit'] = '';
         if ($info['unit_id']) {

+ 34 - 23
module/scm_product/lib/Manage.php

@@ -91,6 +91,7 @@ class Manage
 
     public function searchProduct_api()
     {
+        $id = Dever::input('id');
         $keyword = Dever::input('keyword');
         $where = array();
         if ($keyword) {
@@ -144,13 +145,41 @@ class Manage
             }
         }
 
-        return $data;
+        $width = '600';
+        $table = '<style>.layui-table-view{margin:10px!important}</style><table class="layui-table" lay-filter="'.$id.'">';
+
+        $table .= '<thead>
+                    <tr>
+                      <th lay-data="{field:\'value\', fixed:\'left\', width: 120}">ID</th>
+                      <th lay-data="{field:\'name\', fixed:\'left\', hide:true}">名称</th>
+                      <th lay-data="{field:\'sname\', fixed:\'left\', width: 120}">名称</th>
+                      <th lay-data="{field:\'spec\'}">规格</th>
+                    </tr> 
+                  </thead>';
+
+        $table .= '<tbody>';
+        foreach ($data as $k => $v) {
+            $table .= '<tr>
+                      <td>'.$v['id'].'</td>
+                      <td>'.$v['name'].'</td>
+                      <td>'.$v['sname'].'</td>
+                      <td>'.$v['spec'].'</td>
+                    </tr>';
+        }
+        $table .= '</tbody>';
+        $table .= '</table>';
+
+        $result['list'] = $data;
+        //$result['table'] = $table;
+        $result['table_config'] = array('width' => $width);
+
+        return $result;
     }
 
     public function getGoods($id, $table = 'scm_servicer/in_order_goods', $cash = true)
     {
         $result = array();
-        $result['head'] = array('名称', '批次', '单价', '数量', '状态');
+        $result['head'] = array('名称', '批次', '单位', '单价', '数量', '状态');
         if (!$cash) {
             unset($result['head'][1]);
         }
@@ -163,8 +192,10 @@ class Manage
             foreach ($data as $k => $v) {
                 $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
                 $status_name = Dever::status($status, $v['status']);
+                $unit = Dever::db('scm/unit')->one($v['unit_id']);
                 $result['body'][$k][] = $goods_info['aname'];
                 $result['body'][$k][] = $v['batch'];
+                $result['body'][$k][] = $unit['name'];
                 $result['body'][$k][] = $v['cash'];
                 $result['body'][$k][] = $v['num'];
                 $result['body'][$k][] = $status_name;
@@ -261,27 +292,7 @@ class Manage
         $unit = Dever::input('value');
         $goods = Dever::input('goods');
         list($goods_id, $sku_id) = explode('-', $goods);
-        $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
-        $result = array();
-
-        if ($goods_info) {
-            $where['goods_id'] = $goods_id;
-            $where['sku_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);
-            }
-            $result['cash'] = isset($sku['cost_price']) && $sku['cost_price'] ? $sku['cost_price'] : $goods_info['cost_price'];
-                
-            $unit = Dever::db('scm_product/info_unit')->find(array('info_id' => $goods_info['id'], 'unit_id' => $unit));
-            if ($unit && $unit['discount'] > 0) {
-                $result['cash'] = $result['cash'] * $unit['radio'] * $unit['discount'];
-            }
-        }
         
-        return array('data' => $result, 'html' => '');
+        return array('data' => Dever::load('scm/lib/price')->getByUnit($goods_id, $sku_id, $unit, 1, 'cost_price', Dever::input('supplier_id')), 'html' => '');
     }
 }

+ 3 - 0
module/scm_product/lib/Sku.php

@@ -36,7 +36,10 @@ class Sku
 
                     $key = str_replace('-', ',', $v['key']);
                     $spec = Dever::db('scm_product/info_spec_value')->getGroupData(array('ids' => $key));
+                    $copy['spec'] = '无';
                     if ($spec) {
+                        $copy['sname'] = $copy['name'];
+                        $copy['spec'] = $spec['name'];
                         $copy['name'] .= '-' . $spec['name'];
                         if (isset($copy['value'])) {
                             $copy['value'] = $copy['id'];

+ 0 - 93
module/scm_product/lib/Stock.php

@@ -1,93 +0,0 @@
-<?php
-
-namespace Scm_product\Lib;
-
-use Dever;
-
-class Stock
-{
-	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));
-				}
-			}
-		}
-    }
-}

+ 0 - 5
module/scm_servicer/database/in_order.php

@@ -47,11 +47,6 @@ return array
     (
     	'status' => $status,
     ),
-    # 验证供应商商品是否存在
-    'start' => array
-    (
-        'insert' => 'scm/lib/order.check',
-    ),
     'end' => array
     (
         'insert' => 'scm/lib/order.updateOrderNum?table=scm_servicer/in_order&prefix=CI',

+ 12 - 1
module/scm_servicer/database/in_order_goods.php

@@ -90,7 +90,7 @@ return array
             'desc'      => '单位',
             'match'     => 'is_numeric',
             'update'    => 'select',
-            'option'    => array(0 => '请选择商品'),
+            'option'    => array(0 => '请选择商品'),
             'bind'        => array('onchange', 'loading', array('url' => Dever::url('lib/manage.showPriceByUnit', 'scm_product'), 'col' => 'supplier_id,goods')),
         ),
 
@@ -105,6 +105,17 @@ return array
             'value'     => date('Ymd'),
         ),
 
+        'sdate'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生产日期',
+            'default'   => '',
+            'desc'      => '生产日期',
+            'match'     => 'option',
+            'update'    => 'day',
+            'callback'  => 'maketime',
+        ),
+
         'cash'      => array
         (
             'type'      => 'decimal-11,2',

+ 19 - 6
module/scm_servicer/database/out_order_goods.php

@@ -18,12 +18,12 @@ return array
     # 验证库存
     'start' => array
     (
-    	'insert' => 'scm_product/lib/stock.out_check?table=scm_servicer/store_goods_sku&col=servicer_store_id',
+    	'insert' => 'scm/lib/stock.out_check?table=scm_servicer/store_goods_sku&col=servicer_store_id',
     ),
     'end' => array
     (
-        'insert' => 'scm_product/lib/order.updateGoods?table=scm_servicer/out_order_goods',
-        'update' => 'scm_product/lib/order.updateGoods?table=scm_servicer/out_order_goods',
+        'insert' => 'scm/lib/order.updateGoods?table=scm_servicer/out_order_goods',
+        'update' => 'scm/lib/order.updateGoods?table=scm_servicer/out_order_goods',
     ),
     # 数据结构
     'struct' => array
@@ -59,13 +59,13 @@ return array
             'match'     => 'option',
             'update'    => 'select',
             'update_search' => 'scm_product/lib/manage.searchProduct?{servicer_id,servicer_store_id}',
-            'bind'        => array('onchange', 'loading', array('url' => Dever::url('lib/stock.show', 'scm_product'), 'col' => 'servicer_store_id')),
+            'bind'        => array('onchange', 'loading', array('url' => Dever::url('lib/manage.showInfo', 'scm_product'), 'col' => 'servicer_store_id')),
         ),
 
         'goods_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '商品信息',
+            'name'      => '库存',
             'default'   => '',
             'desc'      => '商品',
             'match'     => 'is_numeric',
@@ -82,14 +82,27 @@ return array
             'match'     => 'is_numeric',
         ),
 
+        'unit_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '单位',
+            'default'   => '',
+            'desc'      => '单位',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => array(0 => '请先选择商品'),
+            'bind'        => array('onchange', 'loading', array('url' => Dever::url('lib/manage.showPriceByUnit', 'scm_product'), 'col' => 'supplier_id,goods')),
+        ),
+
         'batch'      => array
         (
             'type'      => 'varchar-800',
-            'name'      => '批次号-为空将自动生成',
+            'name'      => '批次号',
             'default'   => '',
             'desc'      => '批次号',
             'match'     => 'option',
             'update'    => 'text',
+            'value'     => date('Ymd'),
         ),
 
         'cash'      => array

+ 21 - 0
module/scm_servicer/database/store_goods_sku.php

@@ -69,6 +69,16 @@ $config = array
             'match'     => 'is_numeric',
         ),
 
+        'unit_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '单位',
+            'default'   => '',
+            'desc'      => '单位',
+            'match'     => 'is_numeric',
+            //'update'    => 'select',
+        ),
+
         'batch'      => array
         (
             'type'      => 'varchar-800',
@@ -78,6 +88,17 @@ $config = array
             'match'     => 'option',
         ),
 
+        'sdate'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生产日期',
+            'default'   => '',
+            'desc'      => '生产日期',
+            'match'     => 'option',
+            'update'    => 'day',
+            'callback'  => 'maketime',
+        ),
+
         'cash'      => array
         (
             'type'      => 'decimal-11,2',

+ 1 - 1
module/scm_servicer/lib/In.php

@@ -118,7 +118,7 @@ class In
         if ($data) {
             $status = Dever::db('scm_servicer/in_order_goods')->config['status'];
             foreach ($data as $k => $v) {
-                $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
+                $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id'], $v['unit_id']);
                 $status_name = Dever::status($status, $v['status']);
 
                 $detail = array