|
@@ -78,8 +78,34 @@ class Api extends Base
|
|
# 购买
|
|
# 购买
|
|
public function buy()
|
|
public function buy()
|
|
{
|
|
{
|
|
- $product_id = Dever::input('product_id', false, '> 0', '请传入正确的产品id');
|
|
|
|
- $product = Dever::db('product/info')->one($product_id);
|
|
|
|
|
|
+ $products = $product_id = Dever::input('products');
|
|
|
|
+ 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']);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $price = $price + ($product['pay_price'] * $num[$k]);
|
|
|
|
+ }
|
|
|
|
|
|
$user = Dever::db('passport/user')->one($this->data['uid']);
|
|
$user = Dever::db('passport/user')->one($this->data['uid']);
|
|
$wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
|
|
$wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
|
|
@@ -90,10 +116,11 @@ class Api extends Base
|
|
'account_id' => 1,
|
|
'account_id' => 1,
|
|
'uid' => $this->data['uid'],
|
|
'uid' => $this->data['uid'],
|
|
'username' => $user['username'],
|
|
'username' => $user['username'],
|
|
- 'name' => $product['name'],
|
|
|
|
- 'cash' => $product['pay_price'],
|
|
|
|
|
|
+ 'name' => implode(',', $name),
|
|
|
|
+ 'cash' => $price,
|
|
//'refer' => '1',
|
|
//'refer' => '1',
|
|
'openid' => $wechat['openid'],
|
|
'openid' => $wechat['openid'],
|
|
|
|
+ 'product_id' => $product_id,
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|