|
@@ -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,
|
|
|
)
|
|
|
);
|