dever 3 years ago
parent
commit
0d3669424c

+ 2 - 2
app/card/database/add.php

@@ -10,8 +10,8 @@ return array
     'menu' => false,
     'end' => array
     (
-        'update' => 'card/lib/manage.createCard',
-        'insert' => 'card/lib/manage.createCard',
+        'update' => 'card/lib/code.createCard',
+        'insert' => 'card/lib/code.createCard',
     ),
     # 数据结构
     'struct' => array

+ 26 - 22
app/card/database/code.php

@@ -75,7 +75,7 @@ return array
         (
             'type'      => 'varchar-50',
             'name'      => '总额',
-            'default'   => '',
+            'default'   => '0',
             'desc'      => '总额',
             'match'     => 'option',
             'update'    => 'text',
@@ -85,7 +85,7 @@ return array
         (
             'type'      => 'varchar-50',
             'name'      => '已使用',
-            'default'   => '',
+            'default'   => '0',
             'desc'      => '已使用',
             'match'     => 'option',
             'update'    => 'text',
@@ -94,20 +94,29 @@ return array
         'uid'       => array
         (
             'type'      => 'int-11',
-            'name'      => '用户信息',
+            'name'      => '下单用户',
+            'default'   => '0',
+            'desc'      => '下单用户',
+            'match'     => 'is_numeric',
+            'list_name' => '更多信息',
+            'list'      => 'Dever::load("card/lib/manage.showUserInfo", "{id}")',
+        ),
+
+        'dh_uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换用户',
             'default'   => '0',
-            'desc'      => '用户信息',
+            'desc'      => '兑换用户',
             'match'     => 'is_numeric',
-            'list_name' => '兑换信息',
-            //'list'      => 'Dever::load("goods/lib/manage.showUserInfo", "{id}")',
         ),
 
         'shop_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '兑换门店',
+            'name'      => '下单门店',
             'default'   => '',
-            'desc'      => '兑换门店',
+            'desc'      => '下单门店',
             'match'     => 'is_numeric',
         ),
 
@@ -149,16 +158,6 @@ return array
             //'search'  => 'date',
         ),
 
-        'edate'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '失效时间',
-            'match'     => 'is_numeric',
-            'default'   => '',
-            'desc'      => '',
-            'list'      => 'date("Y-m-d H:i:s", {edate})',
-        ),
-
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -202,7 +201,9 @@ return array
         # 索引名 => 索引id
         1 => array
         (
-            'card' => 'card'
+            'card' => 'card',
+            'uid' => 'uid',
+            'dh_uid' => 'dh_uid',
         ),
         'version' => 1,
     ),
@@ -214,13 +215,15 @@ return array
             # 匹配的正则或函数 选填项
             'option' => array
             (
+                'uid' => 'yes',
+                'dh_uid' => 'yes',
                 'card_id' => 'yes',
                 'status' => 'yes',
                 'state' => 1,
             ),
             'type' => 'all',
             'limit' => '0,10',
-            'order' => array('cdate' => 'asc'),
+            'order' => array('ddate' => 'desc'),
             'col' => '*',
         ),
 
@@ -230,13 +233,14 @@ return array
             'option' => array
             (
                 'uid' => 'yes',
+                'dh_uid' => 'yes',
                 'status' => 'yes',
                 'state' => 1,
             ),
             'type' => 'all',
             'page' => array(10, 'list'),
-            'order' => array('cdate' => 'ddate'),
-            'col' => '*,total_cash-use_cash as cash',
+            'order' => array('ddate' => 'desc'),
+            'col' => '*',
         ),
     ),
 );

+ 4 - 15
app/card/database/info.php

@@ -2,7 +2,7 @@
 $status = Dever::config('base')->status;
 $type = function()
 {
-    return Dever::db('card/type')->select();
+    return Dever::db('card/type')->all();
 };
 
 $card_type = array
@@ -58,7 +58,7 @@ return array
             'match'     => 'is_numeric',
             'update'    => 'radio',
             'option'    => $type,
-            'control'   => 'type',
+            'list'      => true,
         ),
 
         'value'        => array
@@ -81,17 +81,6 @@ return array
             'update'    => 'text',
         ),
 
-        'day'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '有效天数',
-            'default'   => '7',
-            'desc'      => '有效天数',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-            'show'      => 'type=2',
-        ),
-
         'card_type'        => array
         (
             'type'      => 'int-11',
@@ -176,9 +165,9 @@ return array
     (
     	'list_button' => array
         (
-            'fast' => array('生成卡号', '"add&where_id=1&search_option_info_id={id}"', '{status} == 1'),
+            'fast' => array('生成卡号', '"add&where_id=1&search_option_card_id={id}"', '{status} == 1'),
 
-            'list1' => array('卡号列表', '"code&search_option_info_id={id}&oper_table=info"'),
+            'list1' => array('卡号列表', '"code&search_option_card_id={id}&oper_table=info"'),
         ),
     ),
 

+ 4 - 21
app/card/database/order.php

@@ -188,23 +188,16 @@ return array
 
         'list_button' => array
         (
+            'fast1' => array('发货', '"order_ps&where_id={id}&search_option_order_id={id}&oper_save_jump=order&oper_table=order&oper_parent=order"', '{status} == 2'),
+
+            'oper1'  => array('已收货', '"card/lib/manage.send?order_id={id}"', '{status} == 3'),
+
             //'oper' => array('作废', 'goods/lib/manage.drop?id={id}', '{type} == 1'),
 
             //'oper2' => array('恢复使用', 'goods/lib/manage.recovery?id={id}', '{type} == 4'),
         ),
     ),
 
-    # 索引
-    'index' => array
-    (
-        # 索引名 => 索引id
-        1 => array
-        (
-            'card' => 'card'
-        ),
-        'version' => 1,
-    ),
-
     'request' => array
     (
         'getAll' => array
@@ -214,18 +207,9 @@ return array
             (
                 'name' => array('yes', 'like'),
                 'order_num' => array('yes', 'like'),
-                'type' => 'yes',
-                'type_id' => 'yes',
-                'source_type' => 'yes',
-                'source_id' => 'yes',
                 'start' => array('yes-cdate', '>='),
                 'end' => array('yes-cdate', '<='),
-                'start_o' => array('yes-operdate', '>='),
-                'end_o' => array('yes-operdate', '<='),
-                'start_f' => array('yes-fdate', '>='),
-                'end_f' => array('yes-fdate', '<='),
                 'status' => array('yes', 'in'),
-                'refund_status' => 'yes',
                 'state' => 1,
             ),
             'type' => 'all',
@@ -244,7 +228,6 @@ return array
                 'start' => array('yes-cdate', '>='),
                 'end' => array('yes-cdate', '<='),
                 'status' => array('yes', 'in'),
-                'refund_status' => 'yes',
                 'state' => 1,
             ),
             'type' => 'all',

+ 28 - 0
app/card/database/order_card.php

@@ -40,6 +40,24 @@ return array
             'match'     => 'is_numeric',
         ),
 
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买人名称',
+            'default'   => '0',
+            'desc'      => '请选择用户',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-one',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
+        ),
+
         'card_id'      => array
         (
             'type'      => 'int-11',
@@ -50,6 +68,16 @@ return array
             'list'      => 'Dever::load("card/info-find#name", {card_id})',
         ),
 
+        'city'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '城市',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
         'price'      => array
         (
             'type'      => 'varchar-50',

+ 164 - 0
app/card/database/order_ps.php

@@ -0,0 +1,164 @@
+<?php
+
+$status = array
+(
+    1 => '待处理',
+    2 => '配送中',
+    3 => '已配送',
+    4 => '未配送',
+);
+
+$service = function()
+{
+    $info = Dever::db('shop/service')->select(array('type' => 1));
+    return $info;
+};
+
+return array
+(
+    # 表名
+    'name' => 'order_ps',
+    # 显示给用户看的名称
+    'lang' => '订单配送表',
+    'menu' => false,
+    'status' => $status,
+
+    'end' => array
+    (
+        'insert' => 'card/lib/manage.orderPs',
+        'update' => 'card/lib/manage.orderPs',
+    ),
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            //'list'        => true,
+        ),
+
+        'order_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '订单表id',
+            'default'   => '',
+            'desc'      => '订单表id',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_order_id'),
+        ),
+
+        'service_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '配送服务商',
+            'default'   => '-1',
+            'desc'      => '配送服务商',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $service,
+        ),
+
+        'order_num'        => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '快递单号-多个用换行隔开',
+            'default'   => '',
+            'desc'      => '快递单号',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '包裹数量',
+            'default'   => '',
+            'desc'      => '包裹数量',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            'list'        => true,
+        ),
+
+        'price'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '快递费用',
+            'default'   => '',
+            'desc'      => '快递费用',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'        => true,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'qu_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '取件时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '取件时间',
+        ),
+
+        'qs_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '签收时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '签收时间',
+        ),
+
+        '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})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        
+    ),
+
+    'request' => array
+    (
+        
+    ),
+);

+ 0 - 172
app/card/database/use_log.php

@@ -1,172 +0,0 @@
-<?php
-
-$status = array
-(
-    1 => '正常',
-    2 => '申请退款中',
-    3 => '已取消',
-);
-
-return array
-(
-    # 表名
-    'name' => 'use_log',
-    # 显示给用户看的名称
-    'lang' => '使用记录',
-    'menu' => false,
-    'status' => $status,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            'update'    => 'hidden',
-            //'list'        => true,
-        ),
-
-        'uid'       => array
-        (
-            'type'      => 'int-11',
-            'name'      => '购买人名称',
-            'default'   => '0',
-            'desc'      => '请选择用户',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-            //'search'  => 'select',
-            'search'    => array
-            (
-                'api' => 'passport/user-one',
-                'col' => 'username',
-                'result' => 'id',
-            ),
-            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
-        ),
-
-        'card_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '礼品卡名称',
-            'default'   => '',
-            'desc'      => '礼品卡名称',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("card/info-find#name", {card_id})',
-        ),
-        
-        'order_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '零售订单表id',
-            'default'   => '',
-            'desc'      => '订单表id',
-            'match'     => 'is_numeric',
-        ),
-
-        'use_cash'        => array
-        (
-            'type'      => 'varchar-11',
-            'name'      => '使用金额',
-            'default'   => '0',
-            'desc'      => '使用金额',
-            'match'     => 'is_string',
-        ),
-
-        'status'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '状态',
-            'default'   => '1',
-            'desc'      => '状态',
-            'match'     => 'is_numeric',
-            //'update'  => 'select',
-            'option'    => $status,
-            'search'    => 'select',
-            'list'      => true,
-            'edit'      => 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})',
-        ),
-    ),
-
-    'manage' => array
-    (
-        'insert' => false,
-        'delete' => false,
-        //'page_list' => 'sell_order_goods',
-    ),
-
-    'request' => array
-    (
-        # 获取单条数据
-        'getIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'uid' => 'yes',
-                'card_id' => 'yes',
-                'order_id' => 'yes',
-                'status' => 1,
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*|id',
-        ),
-
-        # 获取多条数据
-        'getDataByIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'ids' => array('yes-id', 'in'),
-                'uid' => 'yes',
-                'card_id' => 'yes',
-                'order_id' => 'yes',
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*',
-        ),
-
-        # 获取多条数据
-        'getTotal' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'uid' => 'yes',
-                'order_id' => 'yes',
-                'status' => array('yes', 'in'),
-                'state' => 1,
-            ),
-            'type' => 'count',
-            'col' => '*',
-        ),
-    ),
-);

+ 0 - 172
app/card/database/user_card.php

@@ -1,172 +0,0 @@
-<?php
-
-$status = array
-(
-    1 => '正常',
-    2 => '申请退款中',
-    3 => '已取消',
-);
-
-return array
-(
-    # 表名
-    'name' => 'user_card',
-    # 显示给用户看的名称
-    'lang' => '用户礼品卡',
-    'menu' => false,
-    'status' => $status,
-    # 数据结构
-    'struct' => array
-    (
-    
-        'id'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => 'ID',
-            'default'   => '',
-            'desc'      => '',
-            'match'     => 'is_numeric',
-            'search'    => 'order',
-            'update'    => 'hidden',
-            //'list'        => true,
-        ),
-
-        'uid'       => array
-        (
-            'type'      => 'int-11',
-            'name'      => '购买人名称',
-            'default'   => '0',
-            'desc'      => '请选择用户',
-            'match'     => 'is_numeric',
-            'update'    => 'text',
-            //'search'  => 'select',
-            'search'    => array
-            (
-                'api' => 'passport/user-one',
-                'col' => 'username',
-                'result' => 'id',
-            ),
-            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
-        ),
-
-        'card_id'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '礼品卡名称',
-            'default'   => '',
-            'desc'      => '礼品卡名称',
-            'match'     => 'is_numeric',
-            'list'      => 'Dever::load("card/info-find#name", {card_id})',
-        ),
-
-        'total_cash'        => array
-        (
-            'type'      => 'varchar-11',
-            'name'      => '总金额',
-            'default'   => '0',
-            'desc'      => '总金额',
-            'match'     => 'is_string',
-        ),
-
-        'use_cash'        => array
-        (
-            'type'      => 'varchar-11',
-            'name'      => '已用金额',
-            'default'   => '0',
-            'desc'      => '已用金额',
-            'match'     => 'is_string',
-        ),
-
-        'status'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '状态',
-            'default'   => '1',
-            'desc'      => '状态',
-            'match'     => 'is_numeric',
-            //'update'  => 'select',
-            'option'    => $status,
-            'search'    => 'select',
-            'list'      => true,
-            'edit'      => 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})',
-        ),
-    ),
-
-    'manage' => array
-    (
-        'insert' => false,
-        'delete' => false,
-        //'page_list' => 'sell_order_goods',
-    ),
-
-    'request' => array
-    (
-        # 获取单条数据
-        'getIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'uid' => 'yes',
-                'card_id' => 'yes',
-                'order_id' => 'yes',
-                'status' => 1,
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*|id',
-        ),
-
-        # 获取多条数据
-        'getDataByIds' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'ids' => array('yes-id', 'in'),
-                'uid' => 'yes',
-                'card_id' => 'yes',
-                'order_id' => 'yes',
-                'state' => 1,
-            ),
-            'type' => 'all',
-            'col' => '*',
-        ),
-
-        # 获取多条数据
-        'getTotal' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'uid' => 'yes',
-                'order_id' => 'yes',
-                'status' => array('yes', 'in'),
-                'state' => 1,
-            ),
-            'type' => 'count',
-            'col' => '*',
-        ),
-    ),
-);

+ 85 - 8
app/card/lib/Buy.php

@@ -87,7 +87,7 @@ class Buy
         $result['search']['status'] = $this->config['status'];
 
         $config = Dever::db('main/sell_config')->find();
-        $result['card_name'] = $config['card'];
+        $result['card_name'] = $config['card_name'];
 
         return $result;
     }
@@ -108,7 +108,7 @@ class Buy
             $result = $this->getInfo($result, true);
 
             $config = Dever::db('main/sell_config')->find();
-            $result['card_name'] = $config['card'];
+            $result['card_name'] = $config['card_name'];
         }
 
         return $result;
@@ -171,8 +171,63 @@ class Buy
         return $info;
     }
 
+    public function getCard(&$data)
+    {
+        $card_id = Dever::input('card_id');
+        if (!$card_id) {
+            Dever::alert('请传入礼品卡');
+        }
+        $card_id = explode(',', $card_id);
+        
+        $num = Dever::input('num');
+        if (!$num) {
+            Dever::alert('请传入数量');
+        }
+        $num = explode(',', $num);
+
+        $city = Dever::input('city');
+        if (!$city) {
+            Dever::alert('请传入城市');
+        }
+        $city = explode(',', $city);
+
+        $data['price'] = 0;
+        $data['num'] = 0;
+        $data['name'] = array();
+        $data['type'] = $data['list'] = array();
+
+        # 计算总价格
+        foreach ($card_id as $k => $v) {
+            $c = isset($city[$k]) ? $city[$k] : -1;
+            $n = isset($num[$k]) ? $num[$k] : 1;
+            $info = Dever::db('card/info')->find($v);
+            if (!$info) {
+                continue;
+            }
+            $type = Dever::db('card/type')->find($info['type_id']);
+            if (!isset($data['type'][$info['type_id']])) {
+                $data['type'][$info['type_id']] = $type;
+            }
+            $data['type'][$info['type_id']]['list'][$k] = $info;
+            $data['type'][$info['type_id']]['list'][$k]['buy_num'] = $n;
+            $data['type'][$info['type_id']]['list'][$k]['city'] = $c;
+
+            $data['list'][$k] = $info;
+            $data['list'][$k]['buy_num'] = $n;
+            $data['list'][$k]['city'] = $c;
+            $data['num'] += $n;
+            $data['price'] += $data['list'][$k]['price'] * $n;
+            $data['name'][] = $data['list'][$k]['name'];
+        }
+
+        $data['name'] = implode(',', $data['name']);
+
+        $config = Dever::db('main/sell_config')->find();
+        $data['card_name'] = $config['card_name'];
+    }
+
     # 发起支付
-    public function pay($user, $shop, $name, $num, $card, $oprice, $price, $cash, $address_id, $system_source = 5, $refer = '')
+    public function pay($user, $shop, $name, $num, $card, $price, $address_id, $system_source = 5, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -194,7 +249,6 @@ class Buy
         $order_data['address_id'] = $address_id;
         $order_data['name'] = $name;
         $order_data['num'] = $num;
-        $order_data['oprice'] = $oprice;
         $order_data['price'] = $price;
 
         $order_data['order_num'] = $this->getOrderId();
@@ -208,6 +262,7 @@ class Buy
             $data['uid'] = $uid;
             $data['order_id'] = $id;
             $data['card_id'] = $v['id'];
+            $data['city'] = $v['city'];
             $data['price'] = $v['price'];
             $data['num'] = $v['buy_num'];
 
@@ -238,14 +293,16 @@ class Buy
             $param['receipt'] = $receipt;
         }
 
-        $result = Dever::load('pay/api.pay', $param);
+        //$result = Dever::load('pay/api.pay', $param);
+        $result['type'] = 'test';
+        $result['order'] = '';
         $result['order_num'] = $order_data['order_num'];
         $result['order_id'] = $id;
         return $result;
     }
 
     # 再次发起支付
-    public function raction($id, $system_source = 5, $refer = '')
+    public function rpay($id, $system_source = 5, $refer = '')
     {
         $order = Dever::db('card/order')->find($id);
 
@@ -263,7 +320,7 @@ class Buy
             'channel_id' => 1,
             'system_source' => $system_source,
             'uid' => $order['uid'],
-            'name' => $order['name'],
+            'name' => $order['price'],
             'cash' => $order['price'],
             'product_id' => $id,
             'order_id' => $order['order_num'],
@@ -359,6 +416,7 @@ class Buy
     # 添加配送信息
     public function updatePs($order, $status = 1)
     {
+        Dever::config('base')->hook = true;
         $where['order_id'] = $order['id'];
         $data = Dever::db('card/order_ps')->find($where);
 
@@ -372,7 +430,7 @@ class Buy
                 $update['qs_date'] = time();
             }
             
-            Dever::db('card/order_ps')->update($update);
+            $state = Dever::db('card/order_ps')->update($update);
         }
     }
 
@@ -416,4 +474,23 @@ class Buy
 
         return $status;
     }
+
+    # 收货
+    public function send()
+    {
+        $order_id = Dever::input('order_id');
+        $order = Dever::db('card/order')->find($order_id);
+
+        if (!$order || ($order && $order['status'] != 3)) {
+            Dever::alert('当前订单状态无法完成收货');
+        }
+
+        $state = Dever::db('card/order')->update(array('where_id' => $order['id'], 'status' => 4, 'fdate' => time()));
+
+        if ($state) {
+            $this->updatePs($order, 3);
+        }
+
+        return 'reload';
+    }
 }

+ 122 - 0
app/card/lib/Code.php

@@ -0,0 +1,122 @@
+<?php
+
+namespace Card\Lib;
+
+use Dever;
+
+class Code
+{
+    /**
+     * 分配礼品卡资源
+     *
+     * @return mixed
+     */
+    public function assign($order_id)
+    {
+        $card = Dever::db('card/order_card')->select(array('order_id' => $order_id));
+        if ($card) {
+            foreach ($card as $k => $v) {
+            	$info = Dever::db('card/info')->find($v['card_id']);
+            	if (!$info) {
+            		continue;
+            	}
+            	$update = array();
+            	$update['where_id'] = $v['id'];
+            	$update['cards'] = array();
+
+            	$w['option_card_id'] = $v['card_id'];
+            	$w['option_status'] = 1;
+            	$w['limit'] = $v['num'];
+                $code = Dever::db('card/code')->getData($w);
+                $total = $v['num'] - count($code);
+                $u = array();
+                $u['status'] = 2;
+        		$u['uid'] = $v['uid'];
+        		$u['order_id'] = $v['order_id'];
+        		$u['order_card_id'] = $v['id'];
+        		$u['city'] = $v['city'];
+        		$u['total_cash'] = $info['value'];
+        		$u['bdate'] = time();
+                if ($code) {
+                	foreach ($code as $k1 => $v1) {
+                		$u['where_id'] = $v1['id'];
+                		Dever::db('card/code')->update($u);
+                		$update['cards'][$v1['card']] = $v1['card'];
+                	}
+                }
+                if ($total > 0) {
+                	for ($i = 0; $i< $total;$i++) {
+		                $card = $this->createCode($info, $u);
+		                $update['cards'][$card] = $card;
+		            }
+                }
+
+                if ($update['cards']) {
+                	$update['cards'] = implode(',', $update['cards']);
+                	Dever::db('card/order_card')->update($update);
+                }
+            }
+        }
+    }
+
+    /**
+     * 创建兑换码
+     *
+     * @return mixed
+     */
+    public function createCard($id, $name, $param)
+    {
+        $num = Dever::param('num', $param);
+        $info_id = Dever::param('info_id', $param);
+
+        $info = Dever::db('card/info')->find($info_id);
+
+        if ($info && $num > 0) {
+            for ($i = 0; $i< $num;$i++) {
+                $this->createCode($info);
+            }
+        }
+    }
+
+    private function createCode($info, $update = false)
+    {
+        # 生成卡号
+        $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
+        $where['clear'] = true;
+        $where['card'] = $card;
+        $state = Dever::db('card/code')->find($where);
+
+        if (!$state) {
+            $where['card_id'] = $info['id'];
+            if ($update) {
+            	$where = array_merge($where, $update);
+            }
+            Dever::db('card/code')->insert($where);
+
+            return $card;
+        } else {
+            return $this->createCode($info);
+        }
+    }
+
+    /**
+     * 作废
+     *
+     * @return mixed
+     */
+    public function drop_api($id)
+    {
+        $update['where_id'] = $id;
+        $update['type'] = 4;
+        Dever::db('card/code')->update($update);
+        return 'ok';
+    }
+
+    public function recovery_api($id)
+    {
+        $update['where_id'] = $id;
+        $update['type'] = 1;
+        Dever::db('card/code')->update($update);
+        return 'ok';
+    }
+}

+ 34 - 33
app/card/lib/Manage.php

@@ -13,67 +13,68 @@ class Manage
      */
     public function showUserInfo($id)
     {
-        $info = Dever::db('card/order')->find($id);
+        $info = Dever::db('card/code')->find($id);
         $table = array();
         if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) {
             $user = Dever::load('passport/user-one', $info['uid']);
             if ($user) {
                 $table['购买人'] = $user['username'] . '('.$user['mobile'].')';
                 $table['下单时间'] = date('Y-m-d H:i:s', $info['cdate']);
-                $table['支付时间'] = date('Y-m-d H:i:s', $info['pdate']);
+                $table['支付时间'] = date('Y-m-d H:i:s', $info['bdate']);
             }
 
-            if ($info['duid'] && $info['duid'] > 0) {
-                $user = Dever::load('passport/user-one', $info['duid']);
+            if (isset($info['dh_uid']) && $info['dh_uid'] && $info['dh_uid'] > 0) {
+                $user = Dever::load('passport/user-one', $info['dh_uid']);
                 if ($user) {
-                    $table['领取人'] = $user['username'] . '('.$user['mobile'].')';
+                    $table['兑换人'] = $user['username'] . '('.$user['mobile'].')';
                     $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
                 }
             }
+
+            if ($table) {
+                return Dever::table($table);
+            }
         }
 
-        return Dever::table($table);
+        return '暂无';
     }
 
     /**
-     * 创建兑换码
+     * 更新信息
      *
      * @return mixed
      */
-    public function createCard($id, $name, $param)
+    public function orderPs($id, $name, $data)
     {
-        $num = Dever::param('num', $param);
-        $info_id = Dever::param('info_id', $param);
-
-        $info = Dever::db('card/info')->find($info_id);
-
-        if ($info && $num > 0) {
-            for ($i = 0; $i< $num;$i++) {
-                $this->createCode($info);
-            }
+        $order_id = Dever::param('order_id', $data);
+        if ($order_id) {
+            $update['where_id'] = $order_id;
+            $update['set_status'] = 3;
+            Dever::db('card/order')->update($update);
         }
     }
 
-    private function createCode($info)
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function orderSh($id, $name, $data)
     {
-        # 生成卡号
-        $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
-        $where['card'] = $card;
-        $state = Dever::db('card/code')->find($where);
-
-        if (!$state) {
-            $where['card_id'] = $info['id'];
-            if ($info['type'] == 1) {
-                $info['day'] = 3650;
-            }
-
-            $where['edate'] = time() + ($info['day']*86400);
-            Dever::db('card/code')->insert($where);
-        } else {
-            $this->createCode($info);
+        $order_id = Dever::param('order_id', $data);
+        if ($order_id) {
+            $update['where_id'] = $order_id;
+            $update['set_status'] = 4;
+            Dever::db('card/order')->update($update);
         }
     }
 
+    # 收货
+    public function send_api()
+    {
+        return Dever::load('card/lib/buy')->send();
+    }
+
     /**
      * 作废
      *

+ 229 - 0
app/card/src/Api.php

@@ -0,0 +1,229 @@
+<?php
+
+namespace Card\Src;
+
+use Dever;
+use Main\Lib\Core;
+
+class Api extends Core
+{
+    public function __construct()
+    {
+        parent::__construct();
+        $this->checkLogin();
+        $this->shop_id = Dever::input('shop_id');
+
+        if (!$this->shop_id) {
+            Dever::alert('请选择门店');
+        }
+
+        $lng = Dever::input('lng');
+        $lat = Dever::input('lat');
+        if ($lng && $lat) {
+            $this->shop = Dever::load('shop/lib/info')->fetch($this->shop_id, false, $lng, $lat, false);
+        } else {
+            $this->shop = Dever::db('shop/info')->getOne($this->shop_id);
+        }
+
+        if (!$this->shop) {
+            Dever::alert('门店不存在');
+        }
+    }
+
+    # 获取礼品卡
+    public function getCard()
+    {
+        $where['type'] = 1;
+        $this->data['card'] = Dever::db('card/type')->getAll($where);
+
+        if ($this->data['card']) {
+            foreach ($this->data['card'] as $k => $v) {
+                $w['type_id'] = $v['id'];
+                $w['status'] = 1;
+                $this->data['card'][$k]['value'] = Dever::db('card/info')->select($w);
+            }
+        }
+
+        # 获取选择的城市
+        $this->data['city'] = Dever::load('shop/lib/info')->getCity();
+
+        $config = Dever::db('main/sell_config')->find();
+        $this->data['card_name'] = $config['card_name'];
+
+        return $this->data;
+    }
+
+    # 确认订单页面
+    public function confirm()
+    {
+        $this->data['uid'] = $this->uid;
+        $this->data['user'] = $this->user;
+        $this->data['shop'] = $this->shop;
+        Dever::load('card/lib/buy')->getCard($this->data);
+        return $this->data;
+    }
+
+    # 开始下单
+    public function pay_commit()
+    {
+        $refer = Dever::input('refer');
+        $address_id = Dever::input('address_id');
+
+        $this->data['uid'] = $this->uid;
+        $this->data['user'] = $this->user;
+        $this->data['shop'] = $this->shop;
+
+        Dever::load('card/lib/buy')->getCard($this->data);
+
+        if (!$address_id) {
+            Dever::alert('收货地址不能为空');
+        }
+
+        $pay = Dever::load('card/lib/buy')->pay($this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $address_id, 5, $refer);
+        return $pay;
+    }
+
+    # 再次付款
+    public function r_pay()
+    {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('card/lib/buy')->rpay($order_id, 5, $refer);
+
+        return $pay;
+    }
+
+    # 查询是否支付
+    public function c_pay()
+    {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('card/lib/buy')->cpay($order_id, 5, $refer);
+
+        return $pay;
+    }
+
+    # 我的订单列表
+    public function order()
+    {
+        return Dever::load('card/lib/buy')->set(1)->getList($this->uid);
+    }
+
+    # 查看订单详情
+    public function order_view()
+    {
+        $id = Dever::input('order_id');
+
+        return Dever::load('card/lib/buy')->set(2)->getView($this->uid, $id);
+    }
+
+    # 取消订单
+    public function order_cancel_commit()
+    {
+        $order_id = Dever::input('order_id');
+
+        return Dever::load('card/lib/buy')->set(2)->cancel($this->uid, $order_id);
+    }
+
+    # 兑换
+    public function dh_card()
+    {
+        $card = Dever::input('card');
+        if (!$card) {
+            Dever::alert('请输入正确的卡号');
+        }
+        $data = Dever::db('card/code')->find(array('card' => $card, 'status' => 2));
+        if (!$data) {
+            Dever::alert('礼品卡卡号错误或礼品卡已兑换');
+        }
+        $update['where_id'] = $data['id'];
+        $update['dh_uid'] = $this->uid;
+        $update['status'] = 3;
+        $update['ddate'] = time();
+        $state = Dever::db('card/code')->update($update);
+
+        if (!$state) {
+            Dever::alert('兑换失败,请重新兑换');
+        }
+
+        return 'ok';
+    }
+
+    # 查看兑换列表
+    public function card()
+    {
+        $config = Dever::db('main/sell_config')->find();
+        $this->data['card_name'] = $config['card_name'];
+
+        $this->data['card'] = Dever::db('card/code')->getPageData(array('dh_uid' => $this->uid));
+
+        if ($this->data['card']) {
+            foreach ($this->data['card'] as $k => $v) {
+                if (!$v['total_cash']) {
+                    $v['total_cash'] = $v['info']['value'];
+                }
+                if (!$v['use_cash']) {
+                    $v['use_cash'] = 0;
+                }
+                $this->data['card'][$k]['cash'] = $v['total_cash'] - $v['use_cash'];
+                $this->data['card'][$k]['info'] = Dever::db('card/info')->find($v['card_id']);
+                $this->data['card'][$k]['type'] = Dever::db('card/type')->find($this->data['card'][$k]['info']['type_id']);
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 查看可用的礼品卡
+    public function use_card()
+    {
+        $config = Dever::db('main/sell_config')->find();
+        $this->data['card_name'] = $config['card_name'];
+
+        $shop_type = $this->shop['type'];
+        $city = Dever::input('city');
+        if ($city) {
+            $county = Dever::db('area/county')->find($city);
+            if ($county) {
+                $city = $county['city_id'];
+            }
+        }
+
+        $card = Dever::db('card/code')->getData(array('dh_uid' => $this->uid));
+
+        $this->data['card'] = array();
+        if ($card) {
+            foreach ($card as $k => $v) {
+                $v['info'] = Dever::db('card/info')->find($v['card_id']);
+                if (!$v['total_cash']) {
+                    $v['total_cash'] = $v['info']['value'];
+                }
+                if (!$v['use_cash']) {
+                    $v['use_cash'] = 0;
+                }
+                $v['cash'] = $v['total_cash'] - $v['use_cash'];
+                if ($v['cash'] <= 0) {
+                    continue;
+                }
+                
+                $v['type'] = $type = Dever::db('card/type')->find($v['info']['type_id']);
+
+                $type['shop_type'] = explode(',', $type['shop_type']);
+                if (in_array($shop_type, $type['shop_type'])) {
+                    if ($type['city_type'] == 1) {
+                        $this->data['card'][] = $v;
+                    } else {
+                        $type['city'] = explode(',', $type['city']);
+                        if (in_array($city, $type['city'])) {
+                            $this->data['card'][] = $v;
+                        }
+                    }
+                }
+            }
+        }
+
+        return $this->data;
+    }
+}

+ 1 - 1
app/shop/lib/Info.php

@@ -9,7 +9,7 @@ class Info
     # 获取城市
     public function getCity()
     {
-        $city = Dever::db('shop/city')->getCity();
+        $city = Dever::db('shop/info')->getCity();
 
         $result = array();
         if ($city) {

+ 4 - 1
app/shop/lib/Sell.php

@@ -456,10 +456,13 @@ class Sell
             }
         }
 
+        # 计算礼品卡
+        
+
         return $data;
     }
 
-    # 获取礼品卡
+    # 获取礼品卡 - 更改商品卡 - 废弃
     public function card($uid, $shop)
     {
         $card = Dever::input('card');

+ 2 - 2
app/shop/src/My.php

@@ -53,7 +53,7 @@ class My extends Core
 		return $this->data;
 	}
 
-	# 我的礼品卡列表
+	# 我的礼品卡列表 废弃
 	public function card()
 	{
 		$this->data['card'] = Dever::db('goods/card_code')->select_page(array('uid' => $this->uid));
@@ -90,7 +90,7 @@ class My extends Core
 		return $this->data;
 	}
 
-	# 检测礼品卡
+	# 检测礼品卡 废弃
 	public function dh_card()
 	{
 		$city = Dever::input('city');

+ 10 - 0
main/database/sell_config.php

@@ -69,6 +69,16 @@ return array
             'place'     => '150*150',
         ),
 
+        'card_name'       => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '礼品卡名称',
+            'default'   => '厨人E卡',
+            'desc'      => '礼品卡名称',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'card'       => array
         (
             'type'      => 'varchar-150',