dever 3 years ago
parent
commit
1aa7886cb7

+ 0 - 2
app/goods/database/card.php

@@ -113,8 +113,6 @@ return array
                     'match'     => 'is_string',
                     'update'    => 'text',
                 ),
-
-                
             ),
         ),
 

+ 22 - 3
app/goods/database/card_code.php

@@ -1,10 +1,10 @@
 <?php
 $status = array
 (
-    1 => '未领取',
+    1 => '未兑换',
     2 => '已使用',
     3 => '已完成',
-    4 => '已作废',
+    4 => '已过期',
 );
 
 return array
@@ -13,6 +13,7 @@ return array
     'name' => 'card_code',
     # 显示给用户看的名称
     'lang' => '礼品卡卡密',
+    'status' => $status,
     # 后台菜单排序
     'order' => 99,
     'menu'  => false,
@@ -78,7 +79,7 @@ return array
             'search'    => 'select',
             'update'    => 'select',
             'list'      => true,
-            'mul'       => array(1 => '恢复使用', 4 => '已作废'),
+            //'mul'       => array(1 => '恢复使用', 4 => '已作废'),
         ),
 
         'uid'       => array
@@ -101,6 +102,15 @@ return array
             'match'     => 'is_numeric',
         ),
 
+        'order_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '订单表id',
+            'default'   => '',
+            'desc'      => '订单表id',
+            'match'     => 'is_numeric',
+        ),
+
         'ddate'     => array
         (
             'type'      => 'int-11',
@@ -111,6 +121,15 @@ return array
             //'search'  => 'date',
         ),
 
+        'edate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '失效时间',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'list'      => 'date("Y-m-d H:i:s", {edate})',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 2 - 0
app/goods/lib/Info.php

@@ -245,11 +245,13 @@ class Info
         $info = Dever::db($this->table_info)->getOne($id);
 
         if ($info) {
+            $info['sku_id'] = 0;
             if ($sku > 0) {
                 $where['info_id'] = $info['id'];
                 $where['id'] = $sku;
                 $sku = Dever::db('goods/info_sku')->getOne($where);
                 if ($sku) {
+                    $info['sku_id'] = $sku['id'];
                     $info['price'] = $sku['price'];
                     $info['num'] = $sku['num'];
                 }

+ 1 - 1
app/goods/lib/Manage.php

@@ -338,7 +338,7 @@ class Manage
     private function createCode($card_id)
     {
         # 生成卡号和密码
-        $card = Dever::rand(16);
+        $card = 'CR' . Dever::rand(14);
         $pwd = Dever::rand(8);
 
         $where['card'] = $card;

+ 21 - 1
app/shop/database/coupon.php

@@ -59,6 +59,16 @@ return array
             'list'      => 'Dever::load("goods/coupon-find#name", {coupon_id})';
         ),
 
+        'city'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '城市',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
         'day'        => array
         (
             'type'      => 'int-11',
@@ -72,13 +82,23 @@ return array
         'num'      => array
         (
             'type'      => 'int-11',
-            'name'      => '发放数量',
+            'name'      => '发放数量-数量为0则不限量',
             'default'   => '10',
             'desc'      => '发放数量',
             'match'     => 'is_string',
             'update'    => 'text',
         ),
 
+        'act_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '已用数量',
+            'default'   => '0',
+            'desc'      => '已用数量',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 146 - 0
app/shop/database/feedback.php

@@ -0,0 +1,146 @@
+<?php
+$info = function()
+{
+    return Dever::db('collection/info')->state();
+};
+
+$type = array
+(
+	1 => '未回复',
+	2 => '已回复',
+);
+return array
+(
+	# 表名
+	'name' => 'feedback',
+	# 显示给用户看的名称
+	'lang' => '反馈管理',
+	# 是否显示在后台菜单
+	'order' => 80,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+		
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户名',
+			'default' 	=> '0',
+			'desc' 		=> '请选择用户',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'select',
+			'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+			//'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+		),
+
+		'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})';
+        ),
+
+		'mobile'        => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '下单手机号',
+            'default'   => '',
+            'desc'      => '手机号',
+            'match'     => 'option',
+            'search'	=> 'text',
+            'list'		=> true,
+        ),
+
+        'truename'        => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '联系人姓名',
+            'default'   => '',
+            'desc'      => '联系人姓名',
+            'match'     => 'option',
+            'search'	=> 'text',
+            'list'		=> true,
+        ),
+
+		'content'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '反馈内容',
+			'update' 	=> 'textarea',
+			'key'		=> 1,
+			'default' 	=> '',
+			'desc' 		=> '请输入内容',
+			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+			//'modal'		=> '查看详情',
+			//'list'		=> 'Dever::load("user/lib/manage.feedback", {id})',
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '是否回复',
+			'default' 	=> '1',
+			'desc' 		=> '是否回复',
+			'match' 	=> 'is_numeric',
+			'update'    => 'radio',
+            'option'    => $type,
+            '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,
+		'edit' => false,
+		'delete' => false,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	)
+);

+ 40 - 1
app/shop/database/goods.php

@@ -55,6 +55,17 @@ return array
             'list'        => true,
         ),
 
+        'sell_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '销量',
+            'default'   => '0',
+            'desc'      => '请填写销量',
+            'match'     => 'option',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -84,6 +95,34 @@ return array
 
     'request' => array
     (
+        # 更新售出量
+        'updateSell' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'sell_num' => array('yes', '+='),
+            ),
+        ),
+
+        # 获取单条数据
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'goods_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*,num-sell_num as num',
+        ),
+
         'getData' => array
         (
             # 匹配的正则或函数 选填项
@@ -111,7 +150,7 @@ return array
             ),
             'type' => 'all',
             'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc'),
-            'col' => '*',
+            'col' => 't_2.*,t_1.num-t_1.sell_num as num,t_1.sell_num',
         ),
     ),
 );

+ 201 - 0
app/shop/database/goods_sku.php

@@ -0,0 +1,201 @@
+<?php
+
+$config = array
+(
+    # 表名
+    'name' => 'goods_sku',
+    # 显示给用户看的名称
+    'lang' => '商品价格设置',
+    'order' => 200,
+    'menu' => false,
+
+    # 数据结构 不同的字段放这里
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})';
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})';
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品sku',
+            'default'   => '',
+            'desc'      => '商品sku',
+            'match'     => 'is_numeric',
+        ),
+
+        'num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '库存',
+            'default'   => '',
+            'desc'      => '库存',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'sell_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '销量',
+            'default'   => '0',
+            'desc'      => '请填写销量',
+            'match'     => 'option',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序-数值越大越靠前,相当于置顶',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            //'update'  => 'text',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+            '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,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'page_list_table' => 'sku',
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '自定义属性' => array('fast', 1, 'config&where_id=1'),
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        # 列表
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*,num-sell_num as num',
+        ),
+
+        # 获取单条数据
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'sku_id' => 'yes',
+                'goods_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*,num-sell_num as num',
+        ),
+
+        'getMinOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'order' => array('price' => 'asc', 'id' => 'desc'),
+            'col' => '*',
+        ),
+
+        'getMaxOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'order' => array('price' => 'desc', 'id' => 'desc'),
+            'col' => '*',
+        ),
+
+        # 更新售出量
+        'updateSell' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'sell_num' => array('yes', '+='),
+            ),
+        ),
+    ),
+);
+
+return $config;

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

@@ -238,7 +238,7 @@ return array
         'gotime'      => array
         (
             'type'      => 'varchar-100',
-            'name'      => '外送时间',
+            'name'      => '外送时间-如10:00~22:00,24小时制',
             'default'   => '',
             'desc'      => '外送时间',
             'match'     => 'is_string',

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

@@ -4,7 +4,7 @@ $pay_status = Dever::config('base', 'pay')->pay['status'];
 
 $method = array
 (
-    1 => '送',
+    1 => '送',
     2 => '自提',
 );
 
@@ -15,6 +15,21 @@ $pay_method = array
     3 => '礼品卡',
 );
 
+$code_status = array
+(
+    1 => '已下单',
+    2 => '待自提',
+    3 => '已自提',
+);
+
+$ps_status = array
+(
+    1 => '已下单',
+    2 => '待配送',
+    3 => '配送中',
+    4 => '已收货',
+);
+
 $status = array
 (
     1 => '待支付',
@@ -32,6 +47,11 @@ return array
     # 显示给用户看的名称
     'lang' => '销售订单',
     'order' => 100,
+    'status' => $status,
+    'ps_status' => $ps_status,
+    'code_status' => $code_status,
+    'pay_method' = $pay_method,
+    'method' => $method,
     'menu' => false,
     # 数据结构
     'struct' => array
@@ -76,6 +96,26 @@ return array
             'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
         ),
 
+        'parent_uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '邀请人',
+            'default'   => '0',
+            'desc'      => '请选择用户',
+            'match'     => 'is_numeric',
+            //'update'    => 'text',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            //'list_name' => '订单详情',
+            //'list'      => 'Dever::load("goods/lib/manage.order", {id})',
+            //'list'      => '{parent_uid} > 0 ? Dever::load("passport/user-one#username", {parent_uid}) : "无邀请人"',
+        ),
+
         'mobile'        => array
         (
             'type'      => 'varchar-300',
@@ -102,6 +142,16 @@ return array
             //'list'      => 'Dever::load("passport/address-find#address", {address_id})';
         ),
 
+        'invoice_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '发票信息',
+            'default'   => '',
+            'desc'      => '发票信息',
+            'match'     => 'is_numeric',
+            //'list'      => 'Dever::load("passport/address-find#address", {address_id})';
+        ),
+
         'name'      => array
         (
             'type'      => 'varchar-80',
@@ -155,6 +205,66 @@ return array
             'match'     => 'option',
         ),
 
+        'coupon_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户的优惠券id',
+            'default'   => '',
+            'desc'      => '用户的优惠券id',
+            'match'     => 'option',
+        ),
+
+        'method'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '配送类型',
+            'default'   => '1',
+            'desc'      => '配送类型',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $method,
+        ),
+
+        'code'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '自提码',
+            'default'   => '',
+            'desc'      => '自提码',
+            'match'     => 'is_numeric',
+        ),
+
+        'code_status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '自提状态',
+            'default'   => '1',
+            'desc'      => '自提状态',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $code_status,
+        ),
+
+        'ps_code'        => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '物流号',
+            'default'   => '',
+            'desc'      => '物流号',
+            'match'     => 'is_numeric',
+        ),
+
+        'ps_status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '配送状态',
+            'default'   => '1',
+            'desc'      => '配送状态',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $ps_status,
+        ),
+
         'pay_id'      => array
         (
             'type'      => 'varchar-100',
@@ -187,6 +297,17 @@ return array
             'update'    => 'text',
         ),
 
+        'pay_method'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '支付类型',
+            'default'   => '1',
+            'desc'      => '支付类型',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $pay_method,
+        ),
+
         'info'      => array
         (
             'type'      => 'varchar-300',

+ 9 - 0
app/shop/database/sell_order_goods.php

@@ -77,6 +77,15 @@ return array
             'list'      => 'Dever::load("goods/info-find#name", {goods_id})';
         ),
 
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'sku_id',
+            'default'   => '',
+            'desc'      => 'sku_id',
+            'match'     => 'is_numeric',
+        ),
+
         'price'      => array
         (
             'type'      => 'varchar-50',

+ 72 - 2
app/shop/database/user_coupon.php

@@ -1,5 +1,9 @@
 <?php
-
+$status = array
+(
+    1 => '可用',
+    2 => '已过期',
+);
 return array
 (
     # 表名
@@ -70,6 +74,39 @@ return array
             'match'     => 'is_numeric',
         ),
 
+        'city'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '城市',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '可用状态',
+            'default'   => '1',
+            'desc'      => '可用状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'edate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '失效时间',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'list'      => 'date("Y-m-d H:i:s", {edate})',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -99,6 +136,39 @@ return array
 
     'request' => array
     (
-        
+        # 列表
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'city' => 'yes',
+                'edate' => array('yes', '<'),
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('status' => 'asc','edate' => 'asc', 'id' => 'desc'),
+            'col' => '*',
+        ),
+
+        # 列表
+        'getAllPage' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'city' => 'yes',
+                'edate' => array('yes', '<'),
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'page' => array(10, 'list'),
+            'order' => array('status' => 'asc','edate' => 'asc', 'id' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );

+ 18 - 0
app/shop/lib/Cron.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Cron
+{
+    /**
+     * 处理优惠券到期时间
+     *
+     * @return mixed
+     */
+    public function coupon()
+    {
+        
+    }
+}

+ 231 - 0
app/shop/lib/Sell.php

@@ -0,0 +1,231 @@
+<?php
+
+# 销售支付
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Sell
+{
+    # 发起支付
+	public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $coupon_id, $parent_uid = false, $refer = '')
+    {
+        if (!$user) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $uid = $user['id'];
+
+        if (!$parent_uid && Dever::project('invite')) {
+            $parent = Dever::load('invite/api')->getParent($uid, 1);
+            if ($parent) {
+                $parent_uid = $parent['uid'];
+            }
+        }
+        
+        if ($parent_uid) {
+            $order_data['parent_uid'] = $parent_uid;
+        }
+        
+        $order_data['shop_id'] = $shop['id'];
+        $order_data['uid'] = $uid;
+        $order_data['mobile'] = $user['mobile'];
+        $order_data['address_id'] = $address_id;
+        $order_data['invoice_id'] = $invoice_id;
+        $order_data['name'] = $name;
+        $order_data['num'] = $num;
+        $order_data['info'] = $info;
+        $order_data['price'] = $price;
+
+        $order_data['method'] = $method;
+        $order_data['pay_method'] = $pay_method;
+
+        if ($card) {
+        	$order_data['card_code_id'] = $card['id'];
+        }
+        if ($coupon_id) {
+        	$order_data['coupon_id'] = $coupon_id;
+        }
+
+        $order_data['order_num'] = $this->getOrderId();
+        $order_data['pay_id'] = $order_data['order_num'] . '_p1';
+        $order_data['pay_status'] = 1;
+        $order_data['pay_price'] = 0;
+        $id = Dever::db('goods/order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('支付失败');
+        }
+
+        foreach($goods as $k => $v) {
+        	$data['uid'] = $uid;
+        	$data['shop_id'] = $shop['id'];
+        	$data['order_id'] = $id;
+        	$data['goods_id'] = $v['id'];
+        	$data['sku_id'] = $v['sku_id'];
+        	$data['price'] = $v['price'];
+        	$data['num'] = $v['buy_num'];
+
+        	Dever::db('shop/sell_order_goods')->insert($data);
+        }
+
+        if ($card || $price <= 0) {
+
+        	$param['pay_product_id'] = $id;
+        	$param['pay_order_id'] = $order_data['pay_id'];
+        	$param['pay_status'] = 2;
+        	$param['pay_cash'] = $price;
+        	$param['pay_msg'] = '';
+        	$this->success($param);
+        	return 'ok';
+        }
+
+        $param = array
+        (
+            'project_id' => 1,
+            'channel_id' => 1,
+            'system_source' => 1,
+            'uid' => $uid,
+            'name' => $order_data['name'],
+            'cash' => $price,
+            'product_id' => $id,
+            'order_id' => $order_data['pay_id'],
+            'refer' => $refer,
+        );
+
+        $receipt = Dever::input('receipt');
+        if ($receipt) {
+            $param['receipt'] = $receipt;
+        }
+
+        $result = Dever::load('pay/api.pay', $param);
+
+        return $result;
+    }
+
+    # 再次发起支付
+    public function raction($id, $refer = '')
+    {
+    	$order = Dever::db('goods/order')->find($id);
+
+    	if (!$order) {
+    		Dever::alert('订单信息错误');
+    	}
+
+    	if ($order['status'] > 1) {
+    		Dever::alert('订单已支付或已取消');
+    	}
+
+    	$param = array
+        (
+            'project_id' => 1,
+            'channel_id' => 1,
+            'system_source' => 1,
+            'uid' => $order['uid'],
+            'name' => $order['name'],
+            'cash' => $order['price'],
+            'product_id' => $id,
+            'order_id' => $order['pay_id'],
+            'refer' => $refer,
+        );
+
+        $receipt = Dever::input('receipt');
+        if ($receipt) {
+            $param['receipt'] = $receipt;
+        }
+
+        $result = Dever::load('pay/api.pay', $param);
+    }
+
+    # 支付成功回调 安全加密 设置token
+    public function success_secure_api_token()
+    {
+        $project_id = Dever::input('pay_project_id');
+        $info = Dever::db('pay/project')->one($project_id);
+        if ($info) {
+            return $info['key'];
+        }
+        return 'shop_dever_2020';
+    }
+
+    # 支付成功回调 安全加密
+    public function success_secure_api($param = array())
+    {
+        $this->success($param);
+    }
+
+    # 支付成功回调
+    public function success($param = array())
+    {
+        $send = $param ? $param : Dever::preInput('pay_');
+        $product_id = $send['pay_product_id'];
+        $order_id = $send['pay_order_id'];
+        $status = $send['pay_status'];
+        $cash = $send['pay_cash'];
+        $msg = $send['pay_msg'];
+
+        $order = Dever::db('shop/sell_order')->one(array('id' => $product_id, 'time' => time()));
+        if ($order && $order['pay_status'] == 1) {
+
+            if ($status == 2) {
+                # 减少库存 增加销量
+                $update['where_id'] = $order['info_id'];
+                $update['sell_num'] = $order['num'];
+                Dever::db('shop/goods')->updateSell($update);
+
+                if ($order['sku_id'] > 0) {
+                    $update['where_id'] = $order['sku_id'];
+                    $update['sell_num'] = $order['num'];
+                    Dever::db('shop/goods_sku')->updateSell($update);
+                }
+
+                # 发消息
+                if (Dever::project('message')) {
+                    Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', '购买成功', 11);
+                }
+
+                # 如果是自提订单,生成自提码
+                if ($order['method'] == 2) {
+                	$update['code_status'] = 2;
+                	$update['code'] = $this->getCode();
+                } else {
+                	$update['ps_status'] = 2;
+                }
+            }
+
+            $update['pay_status'] = $status;
+            $update['status'] = 2;
+            $update['where_id'] = $order['id'];
+            $update['pay_time'] = time();
+            $update['pay_price'] = $cash;
+            Dever::db('shop/sell_order')->update($update);
+        }
+
+        return 'ok';
+    }
+
+    # 生成自提码
+    public function getCode()
+    {
+        $where['code'] = Dever::rand(6);
+        $state = Dever::db('shop/sell_order')->one($where);
+        if (!$state) {
+            return $where['code'];
+        } else {
+            return $this->getCode();
+        }
+    }
+
+    # 生成订单号
+    public function getOrderId()
+    {
+        $where['order_num'] = Dever::order('G');
+        $state = Dever::db('shop/sell_order')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderId();
+        }
+    }
+}

+ 221 - 15
app/shop/src/Buy.php

@@ -16,6 +16,16 @@ class Buy extends Core
         if (!$this->shop_id) {
             Dever::alert('请选择门店');
         }
+
+        $this->shop = Dever::db('shop/info')->find($this->shop_id);
+
+        if (!$this->shop) {
+            Dever::alert('门店不存在');
+        }
+
+        if ($this->shop['status'] != 1) {
+            Dever::alert('门店不存在');
+        }
     }
 
     # 获取购物车的数据
@@ -74,37 +84,233 @@ class Buy extends Core
     # 确认订单页面
     public function confirm()
     {
-        $goods_id = Dever::input('goods_id');
-        $goods_id = explode(',', $goods_id);
+        $this->data['user'] = $this->user;
+        $this->goods();
+        $this->coupon($this->data['price'], $this->data['method']);
+
+        return $this->data;
+    }
+
+    # 优惠券
+    public function coupon($price, $method, $type = 1)
+    {
+        if ($price <= 0) {
+            Dever::alert('付款价格错误');
+        }
+
+        $coupon_id = Dever::input('coupon_id');
 
-        $sku_id = Dever::input('sku_id');
-        $sku_id = explode(',', $sku_id);
+        $this->data['coupon_id'] = 0;
+        $this->data['coupon_cash'] = 0;
 
-        $num = Dever::input('num');
-        $num = explode(',', $num);
+        if ($type == 1) {
+            # 查找符合要求的优惠券
+            $coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $this->uid, 'city' => $this->shop['city'], 'status' => 1, 'edate' => time()));
+
+            if ($coupon) {
+                foreach ($coupon as $k => $v) {
+                    if ($v['shop_id'] != $this->shop_id) {
+                        # 查找该券是否符合当前店铺
+                        if ($this->shop['coupon_city'] == 2) {
+                            continue;
+                        }
+                    }
+                    $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
+                    if ($coupon_info && ($coupon_info['method'] == $method || $coupon_info['method'] == 3)) {
+                        $kou = false
+                        if ($coupon_info['type'] == 1) {
+                            # 满减券
+                            if ($price >= $coupon_info['total']) {
+                                $kou = true;
+                            }
+                        } else {
+                            $kou = true;
+                        }
+
+                        if ($kou) {
+                            $coupon_info['uid'] = $v['uid'];
+                            $coupon_info['shop_id'] = $v['shop_id'];
+                            $coupon_info['edate'] = date('Y-m-d', $v['edate']);
+                            $this->data['coupon'][] = $coupon_info;
+
+                            if (!$coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
+                                $this->data['coupon_id'] = $v['id'];
+                                $this->data['coupon_cash'] = $coupon_info['cash'];
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        if ($coupon_id) {
+            $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $coupon_id, 'status' => 1));
+            if (!$coupon) {
+                Dever::alert('优惠券不可用');
+            }
+            if (time() > $coupon['edate']) {
+                Dever::db('shop/user_coupon')->update(array('where_id' => $coupon_id, 'status' => 2));
+                Dever::alert('优惠券已过期');
+            }
+
+            if ($coupon['shop_id'] != $this->shop_id) {
+                if ($this->shop['coupon_city'] == 2) {
+                    Dever::alert('优惠券不可用');
+                } else {
+                    $coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $coupon['shop_id'], 'coupon_id' => $coupon['coupon_id'], 'city' => $coupon['city']));
+                    if (!$coupon_info) {
+                        Dever::alert('优惠券不可用');
+                    }
+                }
+            }
+
+            $goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
+            if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total']) {
+                Dever::alert('优惠券不可用');
+            }
+            if ($goods_coupon['method'] != $method || $goods_coupon['method'] != 3)) {
+                Dever::alert('优惠券不可用');
+            }
+
+            $this->data['coupon_id'] = $coupon_id;
+            $this->data['coupon_cash'] = $goods_coupon['cash'];
+        }
+
+        if (isset($this->data['coupon_cash']) && $this->data['coupon_cash'] > 0) {
+            $this->data['price'] -= $this->data['coupon_cash'];
+            if ($this->data['price'] < 0) {
+                $this->data['price'] = 0;
+            }
+        }
+    }
 
-        $this->data['list']['price'] = 0;
+    # 得到商品和总价
+    private function goods()
+    {
+        # 1自提,2配送
+        $this->data['method'] = Dever::input('method');
+        $this->data['pay_method'] = Dever::input('pay_method');
+        $card = Dever::input('card');
+        $pwd = Dever::input('pwd');
+
+        if ($this->data['pay_method'] == 3 && $card && $pwd) {
+            $this->data['card'] = Dever::load('goods/card_code')->find(array('card' => $card, 'pwd' => $pwd, 'status' => 1));
+            if (!$this->data['card']) {
+                Dever::alert('卡号/密码错误');
+            }
+            $goods = Dever::array_decode($this->data['card']['goods']);
+
+            $goods_id = array();
+            $num = array();
+            $sku_id = array();
+            foreach ($goods as $k => $v) {
+                $goods_id[] = $v['goods_id'];
+                $num[] = $v['num'];
+            }
+        } else {
+            $goods_id = Dever::input('goods_id');
+            if (!$goods_id) {
+                Dever::alert('请传入商品');
+            }
+            $goods_id = explode(',', $goods_id);
+
+            $sku_id = Dever::input('sku_id');
+            if ($sku_id) {
+                $sku_id = explode(',', $sku_id);
+            }
+            
+            $num = Dever::input('num');
+            $num = explode(',', $num);
+        }
+
+        $this->data['price'] = 0;
+        $this->data['num'] = 0;
+        $this->data['name'] = '';
+        $count = count($goods_id);
         # 计算总价格
         foreach ($goods_id as $k => $v) {
-
             $s = isset($sku_id[$k]) ? $sku_id[$k] : 0;
             $n = isset($num[$k]) ? $num[$k] : 1;
+            $total = 0;
             $this->data['list'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
 
-            $this->data['list']['price'] += $this->data['list'][$k]['goods']['price'] * $this->data['list'][$k]['goods']['num'];
-        }
+            # 2是库存不足
+            $this->data['list'][$k]['goods']['ku_state'] = 1;
+            # 验证是否有货
+            if ($s > 0) {
+                $w['goods_id'] = $v;
+                $w['shop_id'] = $this->shop_id;
+                $w['sku_id'] = $s;
+                $sku = Dever::db('shop/goods_sku')->getOne($w);
+
+                if ($sku) {
+                    $total = $sku['num'];
+                }
+            } else {
+                $w['goods_id'] = $v;
+                $w['shop_id'] = $this->shop_id;
+                $goods = Dever::db('shop/goods')->getOne($w);
+                if ($goods) {
+                    $total = $goods['num'];
+                }
+            }
 
-        # 查找符合要求的优惠券
-        $coupon = Dever::db('shop/user_coupon')->select(array('uid' => $this->uid));
+            if ($n > $total) {
+                $n = $total;
+            }
+            if ($total <= 0) {
+                $this->data['list'][$k]['goods']['ku_state'] = 2;
+            }
+
+            if ($this->data['list'][$k]['goods']['ku_state'] == 1) {
+                $this->data['list'][$k]['goods']['buy_num'] = $n;
+                $this->data['num'] += $n;
+                $this->data['price'] += $this->data['list'][$k]['goods']['price'] * $n;
+                if (!$this->data['name']) {
+                    if ($count > 1) {
+                        $this->data['name'] = $this->data['list'][$k]['goods']['name'] . '等' . $count . '种商品';
+                    } else {
+                        $this->data['name'] = $this->data['list'][$k]['goods']['name'];
+                    }
+                }
+            }
+        }
+    }
 
+    # 开始下单
+    public function pay()
+    {
+        $refer = Dever::input('refer');
+        $parent_uid = Dever::input('parent_uid');
+        $address_id = Dever::input('address_id');
+        $invoice_id = Dever::input('invoice_id');
         
+        $info = Dever::input('info');
 
-        return $this->data;
+        $this->goods();
+        $this->coupon($this->data['price'], $this->data['method'], 2);
+
+        if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
+            Dever::alert('已售空');
+        }
+
+        if ($this->data['method'] == 2 && !$address_id) {
+            Dever::alert('收货地址不能为空');
+        }
+
+        $pay = Dever::load('shop/lib/sell')->action($this->data['method'], $this->data['pay_method'], $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $parent_uid, $refer);
+
+        return $pay;
     }
 
-    # 获取当前可用优惠券
-    public function coupon()
+    # 再次付款
+    public function r_pay()
     {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('shop/lib/sell')->raction($order_id, $refer);
 
+        return $pay;
     }
 }

+ 161 - 1
app/shop/src/My.php

@@ -32,19 +32,167 @@ class My extends Core
     # 我的优惠券列表
     public function coupon()
     {
+        $this->data = Dever::db('shop/user_coupon')->getAllPage(array('uid' => $this->uid));
+
+        if ($this->data) {
+            foreach ($this->data as $k => $v) {
+                $this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
+                $this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
+                $this->data[$k]['shop'] = array();
+                $coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
+
+                foreach ($coupon as $k1 => $v1) {
+                    $shop = Dever::db('shop/info')->find(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
+                    if ($shop) {
+                        $this->data[$k]['shop'][] = $shop;
+
+                        if ($k1 > 0) {
+                            $city = Dever::db('area/city')->find($v['city']);
+                            $this->data[$k]['shop_name'] = $city['name'] . '多店通用';
+                        } else {
+                            $this->data[$k]['shop_name'] = $shop['name'];
+                        }
+                    }
+                }
+
+                if (!$this->data[$k]['shop']) {
+                    $shop = Dever::db('shop/info')->find($v['shop_id']);
+                    $this->data[$k]['shop'][] = $shop;
+                    $this->data[$k]['shop_name'] = $shop['name'];
+                }
+            }
+        }
 
+        return $this->data;
     }
 
     # 我的礼品卡列表
     public function card()
     {
-        
+        $this->data = Dever::db('goods/card_code')->page(array('uid' => $this->uid));
+
+        if ($this->data) {
+            $status = Dever::db('goods/card_code')->config['status'];
+            $time = time();
+            foreach ($this->data as $k => $v) {
+
+                if ($v['status'] == 1 && $time > $v['edate']) {
+                    $v['status'] = 4;
+                    Dever::db('goods/card_code')->update(array('where_id' => $v['id'], 'status' => 4));
+                }
+                $this->data[$k]['status_name'] = $status[$v['status']];
+                $this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
+                $this->data[$k]['goods'] = array();
+                $info = Dever::db('goods/card')->find($v['card_id']);
+                $goods = Dever::array_decode($info['goods']);
+                foreach ($goods as $k1 => $v1) {
+                    $this->data[$k]['goods'][$k1] = Dever::db('goods/info')->find($v1['goods_id']);
+                    $this->data[$k]['goods'][$k1]['num'] = $v1['num'];
+                }
+
+                if (($v['status'] == 2 || $v['status'] == 3) && $v['order_id'] > 0) {
+                    # 查找订单
+                    $order = Dever::db('shop/sell_order')->find($v['order_id']);
+                    $this->data[$k]['order_num'] = $order['order_num'];
+                } else {
+                    $this->data[$k]['order_num'] = '';
+                }
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 我的订单列表
+    public function order()
+    {
+        $this->data = Dever::db('shop/sell_order')->page(array('uid' => $this->uid));
+
+        if ($this->data) {
+            $this->config = Dever::db('shop/sell_order')->config;
+            foreach ($this->data as $k => $v) {
+                $this->data[$k] = $this->order_info($v);
+            }
+        }
+    }
+
+    # 查看订单详情
+    public function order_view()
+    {
+        $id = Dever::input('order_id');
+
+        $this->data = Dever::db('shop/sell_order')->find(array('uid' => $this->uid, 'id' => $id));
+        if (!$this->data) {
+            Dever::alert('订单不存在');
+        }
+
+        $this->config = Dever::db('shop/sell_order')->config;
+        $this->data = $this->order_info($this->data, 2);
+
+    }
+
+    # 获取订单详细信息
+    public function order_info($info, $type = 1)
+    {
+        $info['status_name'] = $this->config['status'][$info['status']];
+        $info['method_name'] = $this->config['method'][$info['method']];
+
+        if ($info['method'] == 1 && $info['status'] > 1) {
+
+        }
+        $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
+        $info['shop'] = Dever::db('shop/info')->find($info['shop_id']);
+        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+
+        if ($type == 2) {
+            foreach ($info['goods'] as $k => $v) {
+                $info['goods']['info'] = Dever::load('goods/lib/info')->getInfo($v['goods_id']);
+            }
+            if ($info['address_id']) {
+                $info['address'] = Dever::db('passport/address')->find($info['address_id']);
+            }
+
+            if ($info['invoice_id']) {
+                $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
+            }
+
+            if ($info['coupon_id']) {
+                $coupon = Dever::db('shop/user_coupon')->find($info['coupon_id']);
+                if ($coupon) {
+                    $info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
+                }
+            }
+        }
+
+        return $info;
+    }
+
+    # 取消订单
+    public function order_cancel()
+    {
+        $id = Dever::input('order_id');
+
+        $this->data = Dever::db('shop/sell_order')->find(array('uid' => $this->uid, 'id' => $id));
+        if (!$this->data) {
+            Dever::alert('订单不存在');
+        }
+
+        Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => 5));
+
+        return 'ok';
     }
 
     # 我的消息列表
     public function msg()
     {
+        return Dever::load('msg/lib/data')->read($this->uid);
+    }
 
+    # 查看我的消息
+    public function view_msg()
+    {
+        $id = Dever::input('id');
+        return Dever::load('msg/lib/data')->view($this->uid, $id);
     }
 
     # 我的地址列表
@@ -58,4 +206,16 @@ class My extends Core
     {
         return Dever::load('passport/invoice')->get($this->uid);
     }
+
+    # 提交反馈
+    public function feedback()
+    {
+        $data['uid'] = $this->uid;
+        $data['shop_id'] = Dever::input('shop_id');
+        $data['mobile'] = Dever::input('mobile');
+        $data['truename'] = Dever::input('truename');
+        $data['content'] = Dever::input('content');
+
+        return Dever::load('shop/feedback')->insert($data);
+    }
 }