dever 3 years ago
parent
commit
99b907400e
2 changed files with 49 additions and 27 deletions
  1. 39 25
      app/mshop/lib/Buy.php
  2. 10 2
      app/shop/src/Excel.php

+ 39 - 25
app/mshop/lib/Buy.php

@@ -1575,39 +1575,47 @@ class Buy
 
         $info = Dever::db('shop/buy_order')->one($id);
         if ($audit > 1 && $info && $info['status'] == 2) {
+
+            $shop = Dever::db('shop/info')->find($info['type_id']);
+            if (strstr($info['order_num'], '_')) {
+                $temp = explode('_', $info['order_num']);
+                $info['order_num'] = $temp[0];
+                $info['order_index'] = $temp[1];
+            } else {
+                $info['order_index'] = 0;
+            }
             $goods = explode(',', $goods);
-            $data = array();
+            $data = $other = array();
             foreach ($goods as $k => $v) {
                 list($source_type, $source_id, $name, $goods_id) = explode('_', $v);
+                $gv = Dever::db('shop/buy_order_goods')->find($goods_id);
                 if ($source_id > 0) {
                     $key = $source_type . '_' . $source_id;
                     $data[$key][] = array
                     (
-                        'source_id' => $source_id,
+                        'area' => $shop['area'],
+                        'order_id' => $info['id'],
+                        'order_type' => $info['type'],
+                        'order_num' => $info['order_num'],
+                        'order_index' => $info['order_index'],
+                        'type' => 1,
+                        'type_id' => $shop['id'],
                         'source_type' => $source_type,
-                        'goods_id' => $goods_id,
+                        'source_id' => $source_id,
+                        'order_goods_id' => $gv['id'],
+                        'goods_id' => $gv['goods_id'],
+                        'sku_id' => $gv['sku_id'],
+                        'price' => $gv['price'],
+                        'p_price' => $gv['price'],
+                        'num' => $gv['num'],
                     );
+                } else {
+                    $other[] = $gv;
                 }
             }
-            $num = count($data);
-            if ($num <= 0) {
-                Dever::db('shop/buy_order')->update(array('where_id' => $id, 'audit' => 1));
-                Dever::alert('未选择供货商,该订单进入重新审核状态');
-            } else {
-                if ($num == 1) {
-                    foreach ($data as $k => $v) {
-                        $k = explode('_', $k);
-
-                        $p_price = 0;
-                        foreach ($v as $k1 => $v1) {
-                            Dever::db('shop/buy_order_goods')->update(array('where_id' => $v1['order_goods_id'], 'set_p_price' => $v1['p_price']));
-                            $p_price += $v1['p_price'];
-                            $send[$order['id']] = $v1;
-                        }
-                        Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'source_type' => $k[0], 'source_id' =>  $k[1], 'p_price' => $p_price, 'operdate' => time()));
-                    }
-                }
-            }
+
+            $this->audit_action($data, $other, $info, $shop);
+
             Dever::db('shop/buy_order')->update(array('where_id' => $info['id'], 'audit' => $audit, 'audit_desc' => $audit_text));
             if ($audit == 2) {
                 # 成功
@@ -1642,6 +1650,14 @@ class Buy
         $shop = Dever::db('shop/info')->find($order['type_id']);
 
         $data = $this->assign($goods, $order, $shop);
+        
+        $this->audit_action($data, $goods, $order, $shop);
+
+        return 'ok';
+    }
+
+    private function audit_action($data, $goods, $order, $shop, $alert = '供货商库存不足,请联系供货商备货')
+    {
         $send = array();
 
         if ($data) {
@@ -1683,7 +1699,7 @@ class Buy
             }
         } else {
             Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'audit' => 1));
-            Dever::alert('供货商库存不足,请联系供货商备货,该订单进入重新审核状态');
+            Dever::alert(',该订单进入重新审核状态');
         }
 
         if ($send) {
@@ -1710,8 +1726,6 @@ class Buy
                 }
             }
         }
-
-        return 'ok';
     }
 
     public function assign(&$goods, &$order, $shop, $state = false)

+ 10 - 2
app/shop/src/Excel.php

@@ -97,6 +97,10 @@ class Excel
                         if ($v2['code']) {
                             //$v2['code'] = '-' . $v2['code'];
                         }
+                        $p = $v2['price'];
+                        if (is_numeric($v2['num'])) {
+                            $p = $v2['price']*$v2['num'];
+                        }
                         $d = array
                         (
                             $info['sid'],
@@ -111,7 +115,7 @@ class Excel
                             $sku,
                             $v2['price'],
                             $v2['num'],
-                            $v2['price']*$v2['num'],
+                            $p,
 
 
                             $method[$v['method']],
@@ -227,6 +231,10 @@ class Excel
                         if ($v2['code']) {
                             //$v2['code'] = '-' . $v2['code'];
                         }
+                        $p = $v2['price'];
+                        if (is_numeric($v2['num'])) {
+                            $p = $v2['price']*$v2['num'];
+                        }
                         $d = array
                         (
                             $v['order_num'],
@@ -240,7 +248,7 @@ class Excel
                             $sku,
                             $v2['price'],
                             $v2['num'],
-                            $v2['price']*$v2['num'],
+                            $p,
 
                             $cdate,
                             $paydate,