|
@@ -9,7 +9,7 @@ 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 = '')
|
|
|
+ public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $parent_uid = false, $cart = false, $refer = '')
|
|
|
{
|
|
|
if (!$user) {
|
|
|
Dever::alert('错误的用户信息');
|
|
@@ -47,6 +47,9 @@ class Sell
|
|
|
if ($coupon_id) {
|
|
|
$order_data['coupon_id'] = $coupon_id;
|
|
|
}
|
|
|
+ if ($user_coupon_id) {
|
|
|
+ $order_data['user_coupon_id'] = $user_coupon_id;
|
|
|
+ }
|
|
|
|
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
|
$order_data['pay_id'] = $order_data['order_num'] . '_p1';
|
|
@@ -78,6 +81,13 @@ class Sell
|
|
|
$param['pay_cash'] = $price;
|
|
|
$param['pay_msg'] = '';
|
|
|
$this->success($param);
|
|
|
+
|
|
|
+ if ($cart) {
|
|
|
+ # 来自购物车,要清空一下
|
|
|
+ $this->dropCart($uid, $goods, $shop['id']);
|
|
|
+ # 使用优惠券
|
|
|
+ $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
+ }
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
@@ -100,10 +110,32 @@ class Sell
|
|
|
}
|
|
|
|
|
|
$result = Dever::load('pay/api.pay', $param);
|
|
|
-
|
|
|
+ if ($cart) {
|
|
|
+ # 来自购物车,要清空一下
|
|
|
+ $this->dropCart($uid, $goods, $shop['id']);
|
|
|
+ # 使用优惠券
|
|
|
+ $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
+ }
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ public function dropCart($uid, $goods, $shop_id)
|
|
|
+ {
|
|
|
+ $where['uid'] = $uid;
|
|
|
+ $where['shop_id'] = $shop_id;
|
|
|
+ foreach ($goods as $k => $v) {
|
|
|
+ $where['goods_id'] = $v['id'];
|
|
|
+ Dever::db('shop/cart')->delete($where);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function useCoupon($coupon_id, $user_coupon_id)
|
|
|
+ {
|
|
|
+ if ($user_coupon_id) {
|
|
|
+ Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
# 再次发起支付
|
|
|
public function raction($id, $refer = '')
|
|
|
{
|