|
@@ -81,58 +81,86 @@ class Api extends Base
|
|
|
|
|
|
public function buy()
|
|
|
{
|
|
|
- $products = $product_id = Dever::input('products');
|
|
|
+ $address_name = Dever::input('name');
|
|
|
+ $mobile = Dever::input('mobile');
|
|
|
+ $address = Dever::input('address');
|
|
|
+ $invite_uid = Dever::input('invite_uid', 0);
|
|
|
+
|
|
|
+ $products = $product_id = Dever::input('product_id');
|
|
|
if (!$products) {
|
|
|
Dever::alert('请传入正确的产品id');
|
|
|
}
|
|
|
- $num = Dever::input('num');
|
|
|
- $products = explode(',', $products);
|
|
|
- $num = explode(',', $num);
|
|
|
-
|
|
|
- $name = array();
|
|
|
- $price = 0;
|
|
|
- foreach ($products as $k => $v) {
|
|
|
- $product = Dever::db('product/info')->one($v);
|
|
|
- if (count($name) >= 3) {
|
|
|
-
|
|
|
- } else {
|
|
|
- $name[] = $product['name'];
|
|
|
- }
|
|
|
|
|
|
- $cart = Dever::db('product/cart')->state(array('product_id' => $v, 'uid' => $this->data['uid']));
|
|
|
- if ($cart) {
|
|
|
- foreach ($cart as $k1 => $v1) {
|
|
|
- Dever::db('product/cart')->delete($v1['id']);
|
|
|
+ if ($name && $mobile && $address) {
|
|
|
+ $num = Dever::input('num');
|
|
|
+ $products = explode(',', $products);
|
|
|
+ $num = explode(',', $num);
|
|
|
+
|
|
|
+ $name = array();
|
|
|
+ $price = 0;
|
|
|
+ foreach ($products as $k => $v) {
|
|
|
+ $product = Dever::db('product/info')->one($v);
|
|
|
+ if (count($name) >= 3) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $name[] = $product['name'];
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- $price = $price + ($product['pay_price'] * $num[$k]);
|
|
|
- }
|
|
|
|
|
|
- $user = Dever::db('passport/user')->one($this->data['uid']);
|
|
|
- $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
|
|
|
-
|
|
|
-
|
|
|
- $param = array
|
|
|
- (
|
|
|
- 'account_id' => 1,
|
|
|
- 'uid' => $this->data['uid'],
|
|
|
- 'username' => $user['username'],
|
|
|
- 'name' => implode(',', $name),
|
|
|
- 'cash' => $price,
|
|
|
-
|
|
|
- 'openid' => $wechat['openid'],
|
|
|
- 'product_id' => $product_id,
|
|
|
- );
|
|
|
+ $cart = Dever::db('product/cart')->state(array('product_id' => $v, 'uid' => $this->data['uid']));
|
|
|
+ if ($cart) {
|
|
|
+ foreach ($cart as $k1 => $v1) {
|
|
|
+ Dever::db('product/cart')->delete($v1['id']);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ $price = $price + ($product['pay_price'] * $num[$k]);
|
|
|
+ }
|
|
|
|
|
|
+ $user = Dever::db('passport/user')->one($this->data['uid']);
|
|
|
+ $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
|
|
|
|
|
|
- $this->data['pay'] = Dever::load('pay/api')->applet($param);
|
|
|
+ $name = implode(',', $name);
|
|
|
|
|
|
- if (isset($this->data['pay']['prepay_id'])) {
|
|
|
- Dever::setInput('form_id', $this->data['pay']['prepay_id']);
|
|
|
- $this->writeFormId();
|
|
|
+ $order_id = $this->createOrder('P');
|
|
|
+ $order_data['order_id'] = $order_id;
|
|
|
+ $order_data['product_id'] = $product_id;
|
|
|
+ $order_data['uid'] = $this->data['uid'];
|
|
|
+ if ($invite_uid > 0) {
|
|
|
+ $order_data['invite_uid'] = $invite_uid;
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_data['type'] = 1;
|
|
|
+ $order_data['status'] = 1;
|
|
|
+ $order_data['name'] = $name;
|
|
|
+ $order_data['address_name'] = $address_name;
|
|
|
+ $order_data['address_mobile'] = $mobile;
|
|
|
+ $order_data['address_address'] = $address;
|
|
|
+
|
|
|
+ $id = Dever::db('product/order')->insert($order_data);
|
|
|
+
|
|
|
+
|
|
|
+ $param = array
|
|
|
+ (
|
|
|
+ 'account_id' => 1,
|
|
|
+ 'uid' => $this->data['uid'],
|
|
|
+ 'username' => $user['username'],
|
|
|
+ 'name' => $name,
|
|
|
+ 'cash' => $price,
|
|
|
+
|
|
|
+ 'openid' => $wechat['openid'],
|
|
|
+ 'product_id' => $product_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->data['pay'] = Dever::load('pay/api')->applet($param);
|
|
|
+
|
|
|
+ if (isset($this->data['pay']['prepay_id'])) {
|
|
|
+ Dever::setInput('form_id', $this->data['pay']['prepay_id']);
|
|
|
+ $this->writeFormId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Dever::alert('请输入收货信息');
|
|
|
}
|
|
|
|
|
|
return $this->data;
|
|
@@ -190,6 +218,7 @@ class Api extends Base
|
|
|
$name = Dever::input('name');
|
|
|
$mobile = Dever::input('mobile');
|
|
|
$address = Dever::input('address');
|
|
|
+ $invite_uid = Dever::input('invite_uid', 0);
|
|
|
|
|
|
if ($code && $name && $mobile && $address) {
|
|
|
|
|
@@ -217,9 +246,24 @@ class Api extends Base
|
|
|
|
|
|
Dever::db('code/info')->update(array('where_id' => $info['id'], 'type' => 3, 'uid' => $this->data['uid'], 'ldate' => time()));
|
|
|
|
|
|
- $order_id = $this->createOrder();
|
|
|
- Dever::db('product/order')->insert(array('order_id' => $order_id, 'product_id' => $product_id, 'code' => $code, 'uid' => $this->data['uid'], 'type' => 2, 'name' => $product['name'], 'address_name' => $name, 'address_mobile' => $mobile, 'address_address' => $address, 'status' => 2));
|
|
|
+ $order_id = $this->createOrder('C');
|
|
|
|
|
|
+ $order_data['order_id'] = $order_id;
|
|
|
+ $order_data['product_id'] = $product_id;
|
|
|
+ $order_data['uid'] = $this->data['uid'];
|
|
|
+ $order_data['code'] = $code;
|
|
|
+ if ($invite_uid > 0) {
|
|
|
+ $order_data['invite_uid'] = $invite_uid;
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_data['type'] = 2;
|
|
|
+ $order_data['status'] = 2;
|
|
|
+ $order_data['name'] = $product['name'];
|
|
|
+ $order_data['address_name'] = $name;
|
|
|
+ $order_data['address_mobile'] = $mobile;
|
|
|
+ $order_data['address_address'] = $address;
|
|
|
+
|
|
|
+ $id = Dever::db('product/order')->insert($order_data);
|
|
|
} else {
|
|
|
Dever::alert('请输入完整的兑换码或者收货信息');
|
|
|
}
|
|
@@ -227,9 +271,9 @@ class Api extends Base
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private function createOrder()
|
|
|
+ private function createOrder($prefix = 'C')
|
|
|
{
|
|
|
- $order = Dever::order('C');
|
|
|
+ $order = Dever::order($prefix);
|
|
|
|
|
|
$info = Dever::db('product/order')->one(array('order_id' => $order));
|
|
|
|