dever 3 年之前
父节点
当前提交
5685456e61

+ 38 - 2
app/card/database/code.php

@@ -74,7 +74,7 @@ return array
 
         'total_cash'      => array
         (
-            'type'      => 'varchar-50',
+            'type'      => 'float-11',
             'name'      => '总额',
             'default'   => '0',
             'desc'      => '总额',
@@ -84,7 +84,7 @@ return array
 
         'use_cash'      => array
         (
-            'type'      => 'varchar-50',
+            'type'      => 'float-11',
             'name'      => '已使用',
             'default'   => '0',
             'desc'      => '已使用',
@@ -180,6 +180,16 @@ return array
         ),
     ),
 
+    'alter' => array
+    (
+        2 => array
+        (
+            array('update', 'total_cash', 'total_cash', 'float-11 0 总面值'),
+            array('update', 'use_cash', 'use_cash', 'float-11 0 已用面值'),
+        ),
+        'version' => 2,
+    ),
+
     'manage' => array
     (
         'excel' => true,
@@ -243,5 +253,31 @@ return array
             'order' => array('ddate' => 'desc'),
             'col' => '*',
         ),
+
+        'incUseCash' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'use_cash' => array('yes', '+='),
+            ),
+        ),
+
+        'decUseCash' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'use_cash' => array('yes', '-='),
+            ),
+        ),
     ),
 );

+ 11 - 0
app/card/lib/Manage.php

@@ -43,6 +43,17 @@ class Manage
                 }
             }
 
+            if (!$info['total_cash']) {
+                $card_info = Dever::db('card/info')->find($info['card_id']);
+                $info['total_cash'] = $card_info['value'];
+            }
+            if (!$info['use_cash']) {
+                $info['use_cash'] = 0;
+            }
+            $table['总面值'] = $info['total_cash'];
+            $table['已用面值'] = $info['use_cash'];
+            $table['剩余面值'] = $info['total_cash'] - $info['use_cash'];
+
             if ($table) {
                 return Dever::table($table);
             }

+ 1 - 1
app/mshop/src/Data.php

@@ -470,7 +470,7 @@ class Data extends Core
         );
 
         $this->data['price'] -= $cash;
-        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
+        $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], 0, $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
         return $pay;
     }
 

+ 30 - 0
app/shop/database/sell_order.php

@@ -276,6 +276,36 @@ return array
             'match'     => 'option',
         ),
 
+        'card_code_card'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '礼品卡卡号',
+            'default'   => '',
+            'desc'      => '礼品卡卡号',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'card_code_cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '礼品卡抵扣金额',
+            'default'   => '0',
+            'desc'      => '礼品卡抵扣金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'wallet_cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '钱包抵扣金额',
+            'default'   => '0',
+            'desc'      => '钱包抵扣金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'coupon_id'      => array
         (
             'type'      => 'int-11',

+ 8 - 0
app/shop/lib/Refund.php

@@ -314,6 +314,14 @@ class Refund
                         # 还原优惠券
                         Dever::db('shop/user_coupon')->update(array('where_id' => $order['user_coupon_id'], 'status' => 1));
                     }
+
+                    if (isset($order['card_code_id']) && $order['card_code_id'] && $order['card_code_cash'] > 0) {
+                        # 还原礼品卡
+                        Dever::db('card/code')->decUseCash(array('where_id' => $order['card_code_id'], 'set_use_cash' => $order['card_code_cash']));
+                    } elseif (isset($order['wallet_cash']) && $order['wallet_cash'] && $order['wallet_cash'] > 0) {
+                        # 还原钱包
+                        
+                    }
                 }
             }
 

+ 94 - 11
app/shop/lib/Sell.php

@@ -172,6 +172,14 @@ class Sell
             $info['ps_cash'] = 0;
         }
 
+        if (!$info['wallet_cash']) {
+            $info['wallet_cash'] = 0;
+        }
+
+        if (!$info['card_code_cash']) {
+            $info['card_code_cash'] = 0;
+        }
+
         if ($this->type == 1) {
             if ($info['status'] == 2) {
                 $info['status_name'] = '支付成功';
@@ -279,8 +287,16 @@ class Sell
             $state = Dever::db('shop/sell_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
             if ($state) {
                 if ($data['user_coupon_id']) {
+                    # 还原优惠券
                     Dever::db('shop/user_coupon')->update(array('where_id' => $data['user_coupon_id'], 'status' => 1));
                 }
+                if (isset($data['card_code_id']) && $data['card_code_id'] && $data['card_code_cash'] > 0) {
+                    # 还原礼品卡
+                    Dever::db('card/code')->decUseCash(array('where_id' => $data['card_code_id'], 'set_use_cash' => $data['card_code_cash']));
+                } elseif (isset($data['wallet_cash']) && $data['wallet_cash'] && $data['wallet_cash'] > 0) {
+                    # 还原钱包
+                    
+                }
 
                 $this->updateSell($data, 2);
             }
@@ -451,13 +467,47 @@ class Sell
                 }
             }
             $data['price'] -= $data['coupon_cash'];
-            if ($data['price'] < 0) {
-                $data['price'] = 0;
-            }
         }
 
         # 计算礼品卡
-        
+        $card = Dever::input('card');
+        $wallet = Dever::input('wallet');
+        if ($data['price'] > 0 && isset($data['uid']) && $data['uid'] > 0) {
+
+            if ($card) {
+                # 验证这个礼品卡属于自己
+                $check = Dever::db('card/code')->find($card);
+                if ($check['dh_uid'] == $data['uid']) {
+                    if (!$check['total_cash']) {
+                        $card_info = Dever::db('card/info')->find($check['card_id']);
+                        $check['total_cash'] = $card_info['value'];
+                    }
+                    if (!$check['use_cash']) {
+                        $check['use_cash'] = 0;
+                    }
+                    $card_cash = $check['total_cash'] - $check['use_cash'];
+
+                    if ($card_cash > 0) {
+                        $data['card'] = array();
+                        $data['card']['id'] = $check['id'];
+                        $data['card']['card'] = $check['card'];
+                        if ($card_cash >= $data['price']) {
+                            $data['card']['cash'] = $data['price'];
+                            $data['price'] = 0;
+                        } else {
+                            $data['card']['cash'] = $card_cash;
+                            $data['price'] -= $data['card']['cash'];
+                        }
+                    }
+                }
+            } elseif ($wallet && $wallet > 0) {
+                $data['score'] = Dever::load('score/lib/core')->getUserScore($data['uid']);
+            }
+        }
+
+        if ($data['price'] < 0) {
+            $data['price'] = 0;
+        }
 
         return $data;
     }
@@ -579,6 +629,11 @@ class Sell
             $num = explode(',', $num);
         }
 
+        # 钱包金额
+        $data['wallet_cash'] = 0;
+        # 配送金额
+        $data['ps_cash'] = 0;
+
         # 原价
         $data['oprice'] = 0;
         # 现价
@@ -631,7 +686,7 @@ class Sell
     }
 
     # 发起支付
-	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
+	public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $wallet_cash, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -671,6 +726,10 @@ class Sell
 
         if ($card) {
         	$order_data['card_code_id'] = $card['id'];
+            $order_data['card_code_card'] = $card['card'];
+            $order_data['card_code_cash'] = $card['cash'];
+        } elseif ($wallet_cash) {
+            $order_data['wallet_cash'] = $wallet_cash;
         }
         if ($user_coupon_id) {
             $order_data['user_coupon_id'] = $user_coupon_id;
@@ -718,7 +777,7 @@ class Sell
         $order_data['id'] = $id;
         $this->updateSell($order_data);
 
-        if ($card || $price <= 0 || $pay_type == 2) {
+        if ($price <= 0 || $pay_type == 2) {
 
         	$param['pay_product_id'] = $id;
         	$param['pay_order_id'] = $order_data['order_num'];
@@ -732,8 +791,9 @@ class Sell
                 $this->dropCart($cart, $uid, $goods, $shop['id']);
             }
             # 使用优惠券
-            $this->useCoupon($coupon_id, $user_coupon_id);
+            $this->useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash);
 
+            /*
             if ($card) {
                 # 更新礼品卡状态
                 $card_update['where_id'] = $card['id'];
@@ -741,7 +801,7 @@ class Sell
                 $card_update['order_id'] = $id;
                 $card_update['shop_id'] = $shop['id'];
                 Dever::db('goods/card_code')->update($card_update);
-            }
+            }*/
         	return array
             (
                 'order' => '',
@@ -796,7 +856,7 @@ class Sell
             $this->dropCart($cart, $uid, $goods, $shop['id']);
         }
         # 使用优惠券
-        $this->useCoupon($coupon_id, $user_coupon_id);
+        $this->useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash);
         $result['order_num'] = $order_data['order_num'];
         $result['order_id'] = $id;
         return $result;
@@ -817,12 +877,18 @@ class Sell
         }
     }
 
-    public function useCoupon($coupon_id, $user_coupon_id)
+    public function useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash)
     {
         if ($user_coupon_id) {
             Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
         }
 
+        if ($card) {
+            $state = Dever::db('card/code')->incUseCash(array('where_id' => $card['id'], 'set_use_cash' => $card['cash']));
+        } elseif ($wallet_cash) {
+
+        }
+
         # 这里可以记录一下使用日志
     }
 
@@ -1087,6 +1153,16 @@ class Sell
             $info['ps_cash'] = 0;
         }
 
+        if (!$info['wallet_cash']) {
+            $info['wallet_cash'] = 0;
+        }
+
+        if (!$info['card_code_cash']) {
+            $info['card_code_cash'] = 0;
+        }
+
+        $info['card_code_cash'] .= '('.$info['card_code_card'].')';
+
         if ($tk && $tk['process'] == 1) {
             $status = '申请' . $tk_status[$tk['status']];
             $process = $tk_process[$tk['process']];
@@ -1139,11 +1215,18 @@ class Sell
 
                 array
                 (
+                    array('支付金额', '¥ ' . $info['price']),
                     array('优惠券满减', '¥ ' . $info['coupon_cash']),
-                    array('抹零', '¥ ' . $info['kou_cash']),
                     array('配送费', '¥ ' . $info['ps_cash']),
                 ),
 
+                array
+                (
+                    array('礼品卡抵扣', '¥ ' . $info['card_code_cash']),
+                    array('钱包抵扣', '¥ ' . $info['wallet_cash']),
+                    array('抹零', '¥ ' . $info['kou_cash']),
+                ),
+
                 $time,
             )
         );

+ 11 - 5
app/shop/src/Buy.php

@@ -232,7 +232,15 @@ class Buy extends Core
 			$cart = false;
 		}
 
-		if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
+		if (!isset($this->data['card'])) {
+			$this->data['card'] = false;
+		}
+
+		if (!isset($this->data['wallet_cash'])) {
+			$this->data['wallet_cash'] = 0;
+		}
+
+		if (!$this->data['coupon_id'] && !$this->data['card'] && !$this->data['wallet_cash'] && $this->data['price'] <= 0) {
 			Dever::alert('已售空');
 		}
 
@@ -240,11 +248,9 @@ class Buy extends Core
 			Dever::alert('收货地址不能为空');
 		}
 
-		if (!isset($this->data['card'])) {
-			$this->data['card'] = false;
-		}
+		
 
-		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
+		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['wallet_cash'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
 		return $pay;
 	}
 

+ 0 - 116
app/shop/src/Card.php

@@ -1,116 +0,0 @@
-<?php
-
-namespace Shop\Src;
-
-use Dever;
-use Main\Lib\Core;
-
-class Card extends Core
-{
-	public function __construct()
-	{
-		parent::__construct();
-		$this->checkLogin();
-		$this->shop_id = Dever::input('shop_id');
-	}
-
-	# 购买礼品卡基本信息
-	public function getList()
-	{
-		$this->data['config'] = Dever::db('main/sell_config')->find();
-
-		# 列表
-		$this->data['list'] = Dever::db('card/info')->select();
-
-		return $this->data;
-	}
-
-	# 确认订单页面
-	public function confirm()
-	{
-		$this->data['uid'] = $this->uid;
-		$this->getCard();
-
-		return $this->data;
-	}
-
-	# 获取下单的礼品卡信息
-	public function getCard()
-	{
-		$card_id = Dever::input('card_id');
-		$num = Dever::input('num');
-
-		if (!$card_id) {
-			Dever::alert('请选择礼品卡');
-		}
-
-		$card = explode(',', $card_id);
-
-		$this->data['price'] = 0;
-        $this->data['num'] = 0;
-		$this->data['list'] = array();
-		$i = 0;
-		foreach ($card as $k => $v) {
-			$n = isset($num[$k]) ? $num[$k] : 1;
-
-			$info = Dever::db('card/info')->find($v);
-			if ($info) {
-				$this->data['list'][$i] = $info;
-				$this->data['list']['buy_num'] = $n;
-
-				$this->data['price'] += $data['list'][$k]['value'] * $n;
-				$this->data['num'] += $n;
-				$i++;
-			}
-		}
-	}
-
-	# 开始下单
-	public function pay_commit()
-	{
-		$refer = Dever::input('refer');
-		$cart = Dever::input('cart', 1);
-		$address_id = Dever::input('address_id');
-		$invoice_id = Dever::input('invoice_id');
-		
-		$info = Dever::input('info');
-
-		$this->data['uid'] = $this->uid;
-		$this->data['user'] = $this->user;
-		$this->data['shop'] = $this->shop;
-
-		Dever::load('shop/lib/sell')->goods($this->data);
-		Dever::load('shop/lib/sell')->coupon($this->data, 2);
-
-
-		if ($this->data['pay_method'] > 1) {
-			$cart = false;
-		}
-
-		if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
-			Dever::alert('已售空');
-		}
-
-		if ($this->data['method'] == 2 && !$address_id) {
-			Dever::alert('收货地址不能为空');
-		}
-
-		if (!isset($this->data['card'])) {
-			$this->data['card'] = false;
-		}
-
-		$pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], 1, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], 0, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 5, $refer);
-		return $pay;
-	}
-
-	# 再次付款
-	public function r_pay()
-	{
-		$refer = Dever::input('refer');
-		$order_id = Dever::input('order_id');
-
-		$pay = Dever::load('shop/lib/sell')->rpay($order_id, 5, $refer);
-
-		return $pay;
-	}
-}