|
@@ -17,15 +17,47 @@ class Buy extends Core
|
|
|
Dever::alert('请选择门店');
|
|
|
}
|
|
|
|
|
|
- $this->shop = Dever::db('shop/info')->find($this->shop_id);
|
|
|
+ $this->shop = Dever::db('shop/info')->getOne($this->shop_id);
|
|
|
|
|
|
if (!$this->shop) {
|
|
|
Dever::alert('门店不存在');
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if ($this->shop['status'] != 1) {
|
|
|
- Dever::alert('门店不存在');
|
|
|
+ # 分享
|
|
|
+ public function share()
|
|
|
+ {
|
|
|
+ $act_id = Dever::input('act_id', 1);
|
|
|
+ $path = Dever::input('path');
|
|
|
+ $this->data = Dever::load('shop/lib/share')->up($this->uid, $this->shop_id, $act_id, $path);
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取店铺的优惠券
|
|
|
+ public function getCoupon()
|
|
|
+ {
|
|
|
+ $this->data['coupon'] = Dever::load('shop/lib/coupon')->getAll($this->shop_id);
|
|
|
+
|
|
|
+ $this->data['shop'] = $this->shop;
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 领取优惠券 也得判断一下用户是否有权限领取
|
|
|
+ public function takeCoupon()
|
|
|
+ {
|
|
|
+ # 验证这个券是否可以领取
|
|
|
+ $shop_coupon_id = Dever::input('shop_coupon_id');
|
|
|
+ $coupon = explode(',', $shop_coupon_id);
|
|
|
+
|
|
|
+ $this->data['take'] = array();
|
|
|
+ foreach ($coupon as $k => $v) {
|
|
|
+ $this->data['take']['shop_coupon_id'] = $v;
|
|
|
+ $this->data['take']['status'] = Dever::load('shop/lib/coupon')->getOne($this->uid, $this->shop, $v);
|
|
|
}
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
}
|
|
|
|
|
|
# 获取商品详细信息
|
|
@@ -147,7 +179,7 @@ class Buy extends Core
|
|
|
Dever::alert('付款价格错误');
|
|
|
}
|
|
|
|
|
|
- $coupon_id = Dever::input('coupon_id');
|
|
|
+ $user_coupon_id = Dever::input('user_coupon_id');
|
|
|
|
|
|
$this->data['user_coupon_id'] = 0;
|
|
|
$this->data['coupon_id'] = 0;
|
|
@@ -170,7 +202,7 @@ class Buy extends Core
|
|
|
$kou = false;
|
|
|
if ($coupon_info['type'] == 1) {
|
|
|
# 满减券
|
|
|
- if ($price >= $coupon_info['total']) {
|
|
|
+ if ($price >= $coupon_info['total_cash']) {
|
|
|
$kou = true;
|
|
|
}
|
|
|
} else {
|
|
@@ -178,14 +210,15 @@ class Buy extends Core
|
|
|
}
|
|
|
|
|
|
if ($kou) {
|
|
|
+ $coupon_info['user_coupon_id'] = $v['id'];
|
|
|
$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['user_coupon_id'] = $coupon['id'];
|
|
|
- $this->data['coupon_id'] = $v['id'];
|
|
|
+ if (!$user_coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
|
|
|
+ $this->data['user_coupon_id'] = $v['id'];
|
|
|
+ $this->data['coupon_id'] = $coupon_info['id'];
|
|
|
$this->data['coupon_cash'] = $coupon_info['cash'];
|
|
|
}
|
|
|
}
|
|
@@ -194,13 +227,13 @@ class Buy extends Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($coupon_id) {
|
|
|
- $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $coupon_id, 'status' => 1));
|
|
|
+ if ($user_coupon_id) {
|
|
|
+ $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $user_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::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
|
|
|
Dever::alert('优惠券已过期');
|
|
|
}
|
|
|
|
|
@@ -216,15 +249,15 @@ class Buy extends Core
|
|
|
}
|
|
|
|
|
|
$goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
|
|
|
- if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total']) {
|
|
|
+ if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total_cash']) {
|
|
|
Dever::alert('优惠券不可用');
|
|
|
}
|
|
|
- if ($goods_coupon['method'] != $method || $goods_coupon['method'] != 3) {
|
|
|
+ if ($goods_coupon['method'] != $method && $goods_coupon['method'] != 3) {
|
|
|
Dever::alert('优惠券不可用');
|
|
|
}
|
|
|
|
|
|
- $this->data['user_coupon_id'] = $coupon['id'];
|
|
|
- $this->data['coupon_id'] = $coupon_id;
|
|
|
+ $this->data['user_coupon_id'] = $user_coupon_id;
|
|
|
+ $this->data['coupon_id'] = $goods_coupon['id'];
|
|
|
$this->data['coupon_cash'] = $goods_coupon['cash'];
|
|
|
}
|
|
|
|
|
@@ -240,7 +273,7 @@ class Buy extends Core
|
|
|
private function goods()
|
|
|
{
|
|
|
# 1自提,2配送
|
|
|
- $this->data['method'] = Dever::input('method');
|
|
|
+ $this->data['method'] = Dever::input('method', 1);
|
|
|
$this->data['pay_method'] = Dever::input('pay_method');
|
|
|
$card = Dever::input('card');
|
|
|
$pwd = Dever::input('pwd');
|