dever 3 years ago
parent
commit
b3e4e0348a

+ 117 - 34
app/cash/database/shop.php → app/cash/database/order.php

@@ -1,6 +1,6 @@
 <?php
 
-$type = array
+$jstype = array
 (
     1 => '订货结算',
     2 => '退款结算',
@@ -25,6 +25,8 @@ $audit_type = array
 	2 => '人工',
 );
 
+$source = Dever::config('base')->source;
+
 $shop = function()
 {
 	$array = array();
@@ -36,17 +38,62 @@ $shop = function()
 	return $array;
 };
 
+$store = function()
+{
+    $array = array();
+    $info = Dever::db('store/info')->select();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+$factory = function()
+{
+    $array = array();
+    $info = Dever::db('factory/info')->select();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+# 1是门店 2是仓库 但仓库没有结算单 3是工厂
+$search = Dever::input('search', 1);
+
+if ($search == 1) {
+    $search_name = '结算门店';
+    $search_option = $shop;
+    $search_url = 'shop/lib/manage.search';
+} elseif ($search == 2) {
+    $search_name = '结算仓库';
+    $search_option = $store;
+    $search_url = 'store/lib/manage.search';
+} if ($search == 3) {
+    $search_name = '结算工厂';
+    $search_option = $factory;
+    $search_url = 'factory/lib/manage.search';
+}
+
 return array
 (
     # 表名
-    'name' => 'shop',
+    'name' => 'order',
     # 显示给用户看的名称
-    'lang' => '门店结算单',
+    'lang' => '结算单',
     'order' => 100,
-    'config_type' => $type,
+    'config_jstype' => $jstype,
     'config_status' => $status,
     'config_audit' => $audit,
     'config_audit_type' => $audit_type,
+    'config_source' => $source,
+    'end' => array
+    (
+        'insert' => 'cash/lib/manage.orderUpdate',
+        'update' => 'cash/lib/manage.orderUpdate',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -74,21 +121,51 @@ return array
             'list'      => true,
         ),
 
-        'shop_id'      => array
+        'type'      => array
         (
             'type'      => 'int-11',
-            'name'      => '结算门店',
+            'name'      => '采购人类型',
             'default'   => '',
-            'desc'      => '结算门店',
+            'desc'      => '采购人类型',
             'match'     => 'is_numeric',
-            'search'    => 'select',
-            'update'    => 'hidden',
-            'option'	=> $shop,
-            'value'     => Dever::input('search_option_shop_id'),
-            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
         ),
 
-        'buy_order_id'      => array
+        'type_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => $search_name,
+            'default'   => '',
+            'desc'      => '采购人',
+            'match'     => 'is_numeric',
+            'search'    => $search == 3 ? '' : 'select',
+            'option'    => $search_option,
+            //'update_search' => $search_url,
+            'list'      => $search == 3 ? false : 'Dever::load("shop/lib/manage.buyInfo", "{type}", "{type_id}")',
+        ),
+
+        'source_type'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '供货商类型',
+            'default'   => '',
+            'desc'      => '供货商类型',
+            'match'     => 'is_numeric',
+        ),
+
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => $search_name,
+            'default'   => '',
+            'desc'      => '供货商',
+            'match'     => 'is_numeric',
+            'search'    => $search == 3 ? 'select' : '',
+            'option'    => $search_option,
+            //'update_search' => $search_url,
+            'list'      => $search == 3 ? 'Dever::load("shop/lib/manage.buyInfo", "{source_type}", "{source_id}")' : false,
+        ),
+
+        'source_order_id'      => array
         (
             'type'      => 'int-11',
             'name'      => '订货单id',
@@ -97,7 +174,7 @@ return array
             'match'     => 'is_numeric',
         ),
 
-        'buy_order_num'      => array
+        'source_order_num'      => array
         (
             'type'      => 'varchar-100',
             'name'      => '订货单编号',
@@ -109,6 +186,15 @@ return array
             'list'      => true,
         ),
 
+        'refund_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '退款id',
+            'default'   => '-1',
+            'desc'      => '退款id',
+            'match'     => 'is_numeric',
+        ),
+
         'num'        => array
         (
             'type'      => 'int-11',
@@ -116,7 +202,7 @@ return array
             'default'   => '',
             'desc'      => '数量',
             'match'     => 'is_numeric',
-            'list'        => true,
+            'list'      => true,
         ),
 
         'cash'        => array
@@ -127,17 +213,28 @@ return array
             'desc'      => '结算金额',
             'match'     => 'option',
             'update'    => 'text',
-            'list'      => true,
+            'list'      => $search == 1 ? true : false,
         ),
 
-        'type'        => array
+        'p_cash'        => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '结算金额',
+            'default'   => '0',
+            'desc'      => '结算金额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => $search == 3 ? true : false,
+        ),
+
+        'jstype'        => array
         (
             'type'      => 'tinyint-1',
             'name'      => '结算类型',
             'default'   => '1',
             'desc'      => '结算类型',
             'match'     => 'is_numeric',
-            'option'    => $type,
+            'option'    => $jstype,
             'search'    => 'select',
             'list'      => true,
         ),
@@ -231,26 +328,12 @@ return array
 
         'list_button' => array
         (
-            'fast' => array('审核', '"shop&where_id={id}&col=audit,desc&oper_save_jump=shop&oper_table=shop&oper_parent=shop"', '{audit_type} == 2 && {audit} == 1'),
+            'fast' => array('审核', '"order&where_id={id}&col=audit,desc&oper_save_jump=order&oper_table=order&oper_parent=order"', '{audit_type} == 2 && {audit} == 1'),
         ),
     ),
 
     'request' => array
     (
-        # 获取总金额
-        'getAll' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'start' => array('yes-month', '>='),
-                'end' => array('yes-month', '<='),
-                'shop_id' => 'yes',
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'page' => array(10, 'list'),
-            'col' => '*',
-        ),
+        
     ),
 );

+ 21 - 1
app/cash/lib/Manage.php

@@ -8,8 +8,28 @@ class Manage
 {
     public function info($audit_type, $audit)
     {
-        $config = Dever::db('cash/shop')->config;
+        $config = Dever::db('cash/order')->config;
 
         return $config['config_audit_type'][$audit_type] . $config['config_audit'][$audit];
     }
+
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function orderUpdate($id, $name, $data)
+    {
+        Dever::config('base')->hook = true;
+        $update = array();
+        $audit = Dever::param('audit', $data);
+        $info = Dever::db('cash/order')->one($id);
+        if ($audit > 1 && $info['refund_id'] && $info['refund_id'] > 0) {
+            Dever::load('shop/lib/refund')->set('buy')->action($info['refund_id'], $audit, false, false);
+
+            if ($audit == 2) {
+                Dever::db('cash/order')->update(array('where_id' => $id, 'status' => 2));
+            }
+        }
+    }
 }

+ 80 - 0
app/cash/lib/Order.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace Cash\Lib;
+
+use Dever;
+
+class Order
+{
+	# 更新结算单
+    public function up($order, $jstype = 1, $audit = 1, $refund_id = -1)
+    {
+        if (!$order) {
+            return false;
+        }
+        if ($audit == 2) {
+            $status = 2;
+        } else {
+            $status = 1;
+        }
+        if ($jstype == 1) {
+            $audit_type = 1;
+        } else {
+            $audit_type = 2;
+        }
+        $where['source_order_id'] = $order['id'];
+        $where['jstype'] = $jstype;
+        $where['refund_id'] = $refund_id;
+
+        $info = Dever::db('cash/order')->find($where);
+
+        $update = $where;
+        $update['type'] = $order['type'];
+        $update['type_id'] = $order['type_id'];
+        if ($order['source_type']) {
+            $update['source_type'] = $order['source_type'];
+            $update['source_id'] = $order['source_id'];
+        }
+        
+        $update['status'] = $status;
+        $update['audit'] = $audit;
+        $update['audit_type'] = $audit_type;
+
+        if ($update['status'] == 2) {
+        	$update['operdate'] = time();
+        }
+        if ($info) {
+        	$update['where_id'] = $info['id'];
+        	Dever::db('cash/order')->update($update);
+        } else {
+            $update['source_order_num'] = $order['order_num'];
+            $update['num'] = $order['num'];
+
+            if ($audit == 2) {
+                $order['price'] -= $order['refund_cash'];
+                $order['p_price'] -= $order['refund_p_cash'];
+            }
+            $update['cash'] = $order['price'];
+            $update['p_cash'] = $order['p_price'];
+            if ($jstype == 2) {
+                $update['cash'] = -1*$update['cash'];
+                $update['p_cash'] = -1*$update['p_cash'];
+            }
+        
+        	$update['order_num'] = $this->getOrderId();
+        	Dever::db('cash/order')->insert($update);
+        }
+    }
+
+    # 生成订单号
+    public function getOrderId()
+    {
+        $where['order_num'] = Dever::order('JS');
+        $state = Dever::db('cash/order')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderId();
+        }
+    }
+}

+ 0 - 52
app/cash/lib/Shop.php

@@ -1,52 +0,0 @@
-<?php
-
-namespace Cash\Lib;
-
-use Dever;
-
-class Shop
-{
-	# 更新结算单
-    public function up($order, $type = 1, $status = 1, $audit = 1, $audit_type = 1)
-    {
-        $where['buy_order_id'] = $order['id'];
-        $where['type'] = $type;
-
-        $info = Dever::db('cash/shop')->find($where);
-
-        $update = $where;
-        $update['shop_id'] = $order['type_id'];
-        $update['buy_order_num'] = $order['order_num'];
-        $update['num'] = $order['num'];
-        $update['cash'] = $order['price'];
-        if ($type == 2) {
-            $update['cash'] = -1*$update['cash'];
-        }
-        $update['status'] = $status;
-        $update['audit'] = $audit;
-        $update['audit_type'] = $audit_type;
-
-        if ($update['status'] == 2) {
-        	$update['operdate'] = time();
-        }
-        if ($info) {
-        	$update['where_id'] = $info['id'];
-        	Dever::db('cash/shop')->update($update);
-        } else {
-        	$update['order_num'] = $this->getOrderId();
-        	Dever::db('cash/shop')->insert($update);
-        }
-    }
-
-    # 生成订单号
-    public function getOrderId()
-    {
-        $where['order_num'] = Dever::order('JS');
-        $state = Dever::db('cash/shop')->one($where);
-        if (!$state) {
-            return $where['order_num'];
-        } else {
-            return $this->getOrderId();
-        }
-    }
-}

+ 4 - 0
app/factory/lib/Order.php

@@ -78,6 +78,8 @@ class Order
             Dever::alert('下单失败');
         }
 
+        $order_data['id'] = $id;
+
         foreach($this->data['list'] as $k => $v) {
             $data['order_id'] = $id;
             $data['goods_id'] = $v['id'];
@@ -89,6 +91,8 @@ class Order
             $state = Dever::db('shop/buy_order_goods')->insert($data);
         }
 
+        Dever::load('cash/lib/order')->up($order_data, 1, 1);
+
         return Dever::url('project/database/list&project=shop&&table=buy_order&menu=shop&menu_id=77&search_option_state=1&search_option_type=2', 'manage');
     }
 

+ 8 - 19
app/mshop/lib/Buy.php

@@ -381,9 +381,7 @@ class Buy
             Dever::db('shop/buy_order')->update($update);
 
             # 生成结算单
-            if ($order['type'] == 1) {
-                Dever::load('cash/lib/shop')->up($order, 1, 1, 1, 1);
-            }
+            Dever::load('cash/lib/order')->up($order, 1, 1);
         }
 
         return 'ok';
@@ -437,9 +435,7 @@ class Buy
                 }
 
                 # 生成结算单
-                if ($data['type'] == 1) {
-                    Dever::load('cash/lib/shop')->up($data, 1, 2, 2, 1);
-                }
+                Dever::load('cash/lib/order')->up($data, 1, 2);
             }
 
             return 'ok';
@@ -455,8 +451,8 @@ class Buy
         if ($data['status'] == 1) {
             $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
             # 生成结算单
-            if ($state && $data['type'] == 1) {
-                Dever::load('cash/lib/shop')->up($data, 1, 1, 3, 1);
+            if ($state) {
+                //Dever::load('cash/lib/order')->up($data, 1, 3);
             }
             return 'ok';
         } else {
@@ -817,7 +813,7 @@ class Buy
 
         if ($type == 1) {
             # 门店结算单
-            $cash_order = Dever::db('cash/shop')->select(array('shop_id' => $info['type_id'], 'buy_order_id' => $info['id']));
+            $cash_order = Dever::db('cash/order')->select(array('type' => $info['type'], 'type_id' => $info['type_id'], 'source_order_id' => $info['id']));
         } elseif ($type == 2) {
             # 工厂结算单
         }
@@ -988,9 +984,7 @@ class Buy
             } else {
                 if (!$yes) {
                     Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'state' => 2));
-                    if ($order['type'] == 1) {
-                        Dever::load('cash/lib/shop')->up($order, 1, 1, 3, 1);
-                    }
+                    Dever::load('cash/lib/order')->up($order, 1, 3);
                 } else {
                     $price = 0;
                     $num = 0;
@@ -1004,10 +998,7 @@ class Buy
                     $order['num'] = $order['num'] - $num;
                     Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'price' => $order['price'], 'num' => $order['num']));
                     Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $order_id, false, 3, 0, '供货商库存不足');
-
-                    if ($order['type'] == 1) {
-                        Dever::load('cash/lib/shop')->up($order, 1, 1, 3, 1);
-                    }
+                    Dever::load('cash/lib/order')->up($order, 1, 3);
                 }
             }
         } else {
@@ -1021,9 +1012,7 @@ class Buy
 
                 if ($k != $order['id']) {
                     $order_info = Dever::db('shop/buy_order')->find($k);
-                    if ($order_info['type'] == 1) {
-                        Dever::load('cash/lib/shop')->up($order_info, 1, 1, 1, 1);
-                    }
+                    Dever::load('cash/lib/order')->up($order_info, 1, 1);
                 }
             }
         }

+ 2 - 2
app/mshop/src/Buy.php

@@ -89,7 +89,7 @@ class Buy extends Core
     }
 
     # 开始下单
-    public function pay()
+    public function pay_commit()
     {
         $refer = Dever::input('refer');
         
@@ -102,7 +102,7 @@ class Buy extends Core
     }
 
     # 再次付款
-    public function r_pay()
+    public function r_pay_commit()
     {
         $refer = Dever::input('refer');
         $order_id = Dever::input('order_id');

+ 8 - 0
app/mshop/src/Main.php

@@ -6,6 +6,14 @@ use Dever;
 
 class Main
 {
+    public function config()
+    {
+        $config = Dever::db('main/manage_config')->find();
+        $this->data['config'] = $config;
+
+        return $this->data;
+    }
+    
     # 登录
     public function login()
     {

+ 1 - 0
app/mshop/src/My.php

@@ -10,6 +10,7 @@ class My extends Core
     public function home()
     {
         $config = Dever::db('main/manage_config')->find();
+        $this->data['config'] = $config;
         $this->data['phone'] = $config['phone'];
         $this->data['user'] = $this->user;
         $this->data['shop'] = $this->shop;

+ 12 - 7
app/shop/database/buy_order.php

@@ -19,12 +19,7 @@ $refund_status = array
     2 => '已申请',
 );
 
-$type = array
-(
-    1 => '门店',
-    2 => '仓库',
-    3 => '工厂',
-);
+$type = Dever::config('base')->source;
 
 $search_option_type = Dever::input('search_option_type', 1);
 
@@ -156,7 +151,17 @@ return array
         'refund_cash'      => array
         (
             'type'      => 'varchar-50',
-            'name'      => '退款合计金额',
+            'name'      => '退款合计金额-采购价格',
+            'default'   => '0',
+            'desc'      => '退款合计金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'refund_p_cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '退款合计金额-出厂价格',
             'default'   => '0',
             'desc'      => '退款合计金额',
             'match'     => 'option',

+ 11 - 1
app/shop/database/buy_order_refund.php

@@ -65,7 +65,17 @@ return array
         'cash'      => array
         (
             'type'      => 'varchar-300',
-            'name'      => '退款金额',
+            'name'      => '退款金额-采购价',
+            'default'   => '',
+            'desc'      => '退款金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'p_cash'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款金额-出厂价',
             'default'   => '',
             'desc'      => '退款金额',
             'match'     => 'option',

+ 6 - 0
app/shop/lib/Manage.php

@@ -256,4 +256,10 @@ class Manage
             Dever::db('shop/buy_order')->update($update);
         }
     }
+
+    # 获取门店
+    public function search_api()
+    {
+        return Dever::search('shop/info');
+    }
 }

+ 38 - 10
app/shop/lib/Refund.php

@@ -52,7 +52,7 @@ class Refund
     }
 
     # 更新退款记录
-    public function up($order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '', $process = 1)
+    public function up($order_id, $order_goods_id, $status, $price, $p_price, $num = false, $desc = '', $pic = '', $process = 1)
     {
         $data['order_id'] = $order_id;
         if (!$order_goods_id) {
@@ -70,6 +70,10 @@ class Refund
 
         $data['status'] = $status;
         $data['cash'] = $price;
+        if ($p_price && $p_price > 0) {
+            $data['p_cash'] = $p_price;
+        }
+        
         if ($num) {
             $data['num'] = $num;
         }
@@ -80,6 +84,7 @@ class Refund
             $data['where_id'] = $info['id'];
             $state = Dever::db($this->refund_table)->update($data);
             if ($state) {
+                $data['id'] = $info['id'];
                 return $data;
             }
         } else {
@@ -120,8 +125,10 @@ class Refund
                     Dever::db($this->goods_table)->update(array('where_id' => $info['id'], 'status' => 2));
                 	if (isset($info['coupon_cash']) && $info['coupon_cash']) {
                 		$cash = $info['price'] - $info['coupon_cash'];
+                        $p_cash = 0;
                 	} else {
                 		$cash = $info['price'];
+                        $p_cash = $info['p_price'];
                 	}
                     if ($num > 0) {
                         $dec = $num;
@@ -133,17 +140,30 @@ class Refund
                         $dec = $info['num'];
                         $price = round($cash / $info['num'], 2);
                         $cash = round($price * $num, 2);
+
+                        if ($p_cash > 0) {
+                            $price = round($p_cash / $info['num'], 2);
+                            $p_cash = round($price * $num, 2);
+                        }
                     }
                 } else {
                     Dever::alert('您没有权限操作');
                 }
             } else {
                 $cash = $data['price'] - $data['refund_cash'];
+                if (isset($data['refund_p_cash'])) {
+                    $p_cash = $data['p_price'] - $data['refund_p_cash'];
+                } else {
+                    $p_cash = 0;
+                }
             }
 
             if ($cash > 0) {
-                $log = $this->up($data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
+                $log = $this->up($data['id'], $order_goods_id, $status, $cash, $p_cash, $dec, $desc, $pic, $process);
 
+                if (!$log) {
+                    Dever::alert('退款失败');
+                }
                 if ($this->type == 'buy') {
                     # 如果是采购单,这里要把库存先减掉
                     if ($data['status'] == 5 || $data['status'] == 6) {
@@ -151,8 +171,10 @@ class Refund
                         Dever::load('shop/lib/goods')->oper($data, 2, 1, $oper_data);
                     }
 
-                    if ($data['type'] == 1) {
-                        Dever::load('cash/lib/shop')->up($data, 2, 1, 1, 2);
+                    if ($data['source_id'] && $data['source_id'] > 0) {
+                        Dever::load('cash/lib/order')->up($data, 2, 1, $log['id']);
+                    } else {
+                        Dever::load('cash/lib/order')->up($data, 1, 3);
                     }
 
                     # 发消息给供应商
@@ -169,9 +191,12 @@ class Refund
                 $update = array();
                 $update['where_id'] = $data['id'];
                 $update['refund_cash'] = $data['refund_cash'] + $cash;
+                if (isset($data['refund_p_cash'])) {
+                    $update['refund_p_cash'] = $data['refund_p_cash'] + $cash;
+                }
                 $update['refund_status'] = 2;
                 if ($dec > 0) {
-                    $update['num'] = $data['num'] - $dec;
+                    //$update['num'] = $data['num'] - $dec;
                 }
                 
                 Dever::db($this->order_table)->update($update);
@@ -216,9 +241,12 @@ class Refund
         $update = array();
         if ($process == 3) {
             if ($info['num'] && $info['num'] > 0) {
-                $update['num'] = $order['num'] + $info['num'];
+                //$update['num'] = $order['num'] + $info['num'];
             }
             $update['refund_cash'] = $order['refund_cash'] - $info['cash'];
+            if (isset($order['refund_p_cash'])) {
+                $update['refund_p_cash'] = $order['refund_p_cash'] - $info['p_cash'];
+            }
             $update['where_id'] = $order['id'];
             if ($update['refund_cash'] <= 0) {
                 $update['refund_status'] = 1;
@@ -230,8 +258,8 @@ class Refund
                 Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 1));
             }
 
-            if ($cash && $this->type == 'buy' && $order['type'] == 1) {
-                Dever::load('cash/lib/shop')->up($order, 2, 1, 3, 2);
+            if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
+                Dever::load('cash/lib/order')->up($order, 2, 3, $info['id']);
             }
         } else {
             if ($info['type'] == 2) {
@@ -267,8 +295,8 @@ class Refund
                 }
             }
 
-            if ($cash && $this->type == 'buy' && $order['type'] == 1) {
-                Dever::load('cash/lib/shop')->up($order, 2, 2, 2, 2);
+            if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
+                Dever::load('cash/lib/order')->up($order, 2, 2, $info['id']);
             }
         }