|
@@ -135,6 +135,48 @@ class Api extends Base
|
|
|
return $this->data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function checkCode()
|
|
|
+ {
|
|
|
+ $code = Dever::input('code');
|
|
|
+
|
|
|
+ if ($code) {
|
|
|
+
|
|
|
+ $info = Dever::db('code/info')->one(array('code' => $code));
|
|
|
+
|
|
|
+ if (!$info) {
|
|
|
+ Dever::alert('兑换码不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['type'] == 3) {
|
|
|
+ Dever::alert('兑换码已被使用');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $order = Dever::db('product/order')->one('code' => $code);
|
|
|
+
|
|
|
+ if ($order) {
|
|
|
+ Dever::alert('兑换码已被使用');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['product_id']) {
|
|
|
+ $product = Dever::db('product/info')->one($product_id);
|
|
|
+ $this->data['product'] = array($product);
|
|
|
+ $this->data['address'] = Dever::db('product/address')->one(array('uid' => $this->data['uid']));
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Dever::alert('请输入完整的兑换码');
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function code()
|
|
|
{
|
|
@@ -142,7 +184,11 @@ class Api extends Base
|
|
|
|
|
|
$code = Dever::input('code');
|
|
|
|
|
|
- if ($code) {
|
|
|
+ $name = Dever::input('name');
|
|
|
+ $mobile = Dever::input('mobile');
|
|
|
+ $address = Dever::input('address');
|
|
|
+
|
|
|
+ if ($code && $name && $mobile && $address) {
|
|
|
|
|
|
$product = Dever::db('product/info')->one($product_id);
|
|
|
|
|
@@ -169,10 +215,10 @@ 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'], 'status' => 2));
|
|
|
+ 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));
|
|
|
|
|
|
} else {
|
|
|
- Dever::alert('请输入完整的兑换码');
|
|
|
+ Dever::alert('请输入完整的兑换码或者收货信息');
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -239,7 +285,7 @@ class Api extends Base
|
|
|
$where = array();
|
|
|
$where['uid'] = $this->data['uid'];
|
|
|
|
|
|
- $this->data['carts'] = Dever::db('product/cart')->state($where);
|
|
|
+ $this->data['carts'] = Dever::db('product/cart')->getAll($where);
|
|
|
|
|
|
if ($this->data['carts']) {
|
|
|
foreach ($this->data['carts'] as $k => $v) {
|
|
@@ -252,6 +298,26 @@ class Api extends Base
|
|
|
return $this->data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function delCarts()
|
|
|
+ {
|
|
|
+ $product_id = Dever::input('product_id', false, '> 0', '请传入正确的产品id');
|
|
|
+ $uid = $this->data['uid'];
|
|
|
+ if ($product_id > 0) {
|
|
|
+ $update = array();
|
|
|
+ $update['product_id'] = $product_id;
|
|
|
+ $update['uid'] = $this->data['uid'];
|
|
|
+
|
|
|
+ $info = Dever::db('product/cart')->one($update);
|
|
|
+ if ($info) {
|
|
|
+ $update['where_id'] = $info['id'];
|
|
|
+ Dever::db('product/cart')->delete($update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function addAddress()
|
|
|
{
|