dever 3 years ago
parent
commit
874eeec2bb

+ 255 - 0
app/cash/database/shop.php

@@ -0,0 +1,255 @@
+<?php
+
+$type = array
+(
+    1 => '订货结算',
+    2 => '退款结算',
+);
+
+$status = array
+(
+    1 => '未入账',
+    2 => '已入账',
+);
+
+$audit = array
+(
+	1 => '待审核',
+	2 => '审核通过',
+	3 => '审核未通过',
+);
+
+$audit_type = array
+(
+	1 => '系统',
+	2 => '人工',
+);
+
+$shop = function()
+{
+	$array = array();
+	$info = Dever::db('shop/info')->select();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+    # 表名
+    'name' => 'shop',
+    # 显示给用户看的名称
+    'lang' => '门店结算单',
+    'order' => 100,
+    'config_type' => $type,
+    'config_status' => $status,
+    'config_audit' => $audit,
+    'config_audit_type' => $audit_type,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ), 
+
+        'order_num'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '结算单号',
+            'default'   => '',
+            'desc'      => '结算单号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '结算门店',
+            'default'   => '',
+            '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'      => 'int-11',
+            'name'      => '订货单id',
+            'default'   => '',
+            'desc'      => '订货单id',
+            'match'     => 'is_numeric',
+        ),
+
+        'buy_order_num'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订货单编号',
+            'default'   => '',
+            'desc'      => '订货单编号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '数量',
+            'default'   => '',
+            'desc'      => '数量',
+            'match'     => 'is_numeric',
+            'list'        => true,
+        ),
+
+        'cash'        => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '结算金额',
+            'default'   => '0',
+            'desc'      => '结算金额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '结算类型',
+            'default'   => '1',
+            'desc'      => '结算类型',
+            'match'     => 'is_numeric',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '入账状态',
+            'default'   => '1',
+            'desc'      => '入账状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'audit'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '审核状态',
+            'default'   => '1',
+            'desc'      => '审核状态',
+            'match'     => 'is_numeric',
+            'option'    => $audit,
+            'search'    => 'select',
+            'list'      => 'Dever::load("cash/lib/manage.info", "{audit_type}", "{audit}")',
+        ),
+
+        'audit_type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '审核类型',
+            'default'   => '1',
+            'desc'      => '审核类型',
+            'match'     => 'is_numeric',
+            'option'    => $audit_type,
+        ),
+
+        'operdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '结算时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'    => 'date',
+            'list'      => '"{operdate}" ? date("Y-m-d H:i:s", {operdate}) : ""',
+        ),
+
+        'desc'        => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '未通过原因',
+            'default'   => '',
+            'desc'      => '未通过原因',
+            'match'     => 'option',
+            'update'    => 'textarea',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生成时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'    => 'date',
+            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+        'excel'	=> true,
+
+        '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'),
+        ),
+    ),
+
+    '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' => '*',
+        ),
+    ),
+);

+ 8 - 0
app/cash/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'cash');
+define('DEVER_APP_LANG', '结算对账');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 200);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-form');
+include(DEVER_APP_PATH . '../boot.php');

+ 15 - 0
app/cash/lib/Manage.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace Cash\Lib;
+
+use Dever;
+
+class Manage
+{
+    public function info($audit_type, $audit)
+    {
+        $config = Dever::db('cash/shop')->config;
+
+        return $config['config_audit_type'][$audit_type] . $config['config_audit'][$audit];
+    }
+}

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

@@ -0,0 +1,49 @@
+<?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'];
+        $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();
+        }
+    }
+}

+ 26 - 6
app/mshop/lib/Buy.php

@@ -375,15 +375,15 @@ class Buy
         $msg = $send['pay_msg'];
 
         $order = Dever::db('shop/buy_order')->one(array('id' => $product_id, 'time' => time()));
-        if ($order && $order['status'] == 1) {
-
-            if ($status == 2) {
-                
-            }
-
+        if ($order && $order['status'] == 1 && $status == 2) {
             $update['status'] = 2;
             $update['where_id'] = $order['id'];
             Dever::db('shop/buy_order')->update($update);
+
+            # 生成结算单
+            if ($order['type'] == 1) {
+                Dever::load('cash/lib/shop')->up($order, 1, 1, 1, 1);
+            }
         }
 
         return 'ok';
@@ -435,6 +435,11 @@ class Buy
                 if ($goods) {
                     Dever::load('shop/lib/goods')->oper($data, 1, 1, $goods);
                 }
+
+                # 生成结算单
+                if ($data['type'] == 1) {
+                    Dever::load('cash/lib/shop')->up($data, 1, 2, 2, 1);
+                }
             }
 
             return 'ok';
@@ -449,6 +454,10 @@ class Buy
         $data = $this->getView($id, $order_id, false);
         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);
+            }
             return 'ok';
         } else {
             Dever::alert('当前订单状态不允许取消');
@@ -985,6 +994,10 @@ class Buy
                     $num = $order['num'] - $num;
                     Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'price' => $price, 'num' => $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, 2, 1, 1, 2);
+                    }
                 }
             }
         } else {
@@ -995,6 +1008,13 @@ class Buy
         if ($this->order_id) {
             foreach ($this->order_id as $k => $v) {
                 $this->sendMsg($v[0], $v[1], $k);
+
+                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);
+                    }
+                }
             }
         }
 

+ 2 - 1
app/shop/database/info.php

@@ -479,7 +479,8 @@ return array
             'default'   => '',
             'desc'      => '参与活动',
             'match'     => 'option',
-            //'update'    => 'checkbox',
+            'update'    => 'checkbox',
+            'update'    => Dever::input('col') ? 'checkbox' : false,
             'data'      => 'parent',
             //'option'    => $act,
         ),

+ 13 - 1
app/shop/database/sell_order.php

@@ -42,6 +42,17 @@ $refund_status = array
     2 => '已申请',
 );
 
+$shop = function()
+{
+    $array = array();
+    $info = Dever::db('shop/info')->select();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 return array
 (
     # 表名
@@ -75,7 +86,8 @@ return array
             'default'   => '',
             'desc'      => '所属门店',
             'match'     => 'is_numeric',
-            //'search'    => '',
+            'search'    => 'select',
+            'option'    => $shop,
             'update'    => 'hidden',
             'value'     => Dever::input('search_option_shop_id'),
             'list'      => 'Dever::load("shop/info-find#name", {shop_id})',

+ 27 - 3
app/shop/lib/Refund.php

@@ -144,10 +144,26 @@ class Refund
             if ($cash > 0) {
                 $log = $this->up($data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
 
-                if ($this->type == 'buy' && ($data['status'] == 5 || $data['status'] == 6)) {
+                if ($this->type == 'buy') {
                     # 如果是采购单,这里要把库存先减掉
-                    $oper_data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $log['order_goods_id']));
-                    Dever::load('shop/lib/goods')->oper($data, 2, 1, $oper_data);
+                    if ($data['status'] == 5 || $data['status'] == 6) {
+                        $oper_data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $log['order_goods_id']));
+                        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'] && Dever::project('message')) {
+                        $msg = '您的订单'.$data['order_num'].',有新的商品问题。';
+                        $msg_param['type'] = 1;
+                        $msg_param['id'] = $data['id'];
+                        $msg_param = Dever::json_encode($msg_param);
+                        $pid = $data['source_type'] + 1;
+                        Dever::load('message/lib/data')->push(-1, $data['source_id'], '退货与报损通知', $msg, 2, $pid, false, $msg_param);
+                    }
                 }
 
                 $update = array();
@@ -213,6 +229,10 @@ class Refund
             if ($info['type'] == 2) {
                 Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 1));
             }
+
+            if ($this->type == 'buy' && $order['type'] == 1) {
+                Dever::load('cash/lib/shop')->up($order, 2, 1, 3, 2);
+            }
         } else {
             if ($info['type'] == 2) {
                 $state = Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
@@ -246,6 +266,10 @@ class Refund
                     }
                 }
             }
+
+            if ($this->type == 'buy' && $order['type'] == 1) {
+                Dever::load('cash/lib/shop')->up($order, 2, 2, 2, 2);
+            }
         }
 
         $data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $info['order_goods_id']));

+ 4 - 0
package/wechat_applet/index.php

@@ -0,0 +1,4 @@
+<?php
+define('DEVER_PACKAGE',  'wechat_applet');
+define('DEVER_APP_SETUP', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../boot.php');