|
@@ -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()
|
|
|
+ {
|
|
|
+
|
|
|
+ $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'];
|
|
|
- }
|
|
|
+
|
|
|
+ $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;
|
|
|
}
|
|
|
}
|