|
@@ -9,24 +9,13 @@ use Dever;
|
|
|
class Sell
|
|
|
{
|
|
|
|
|
|
- public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $parent_uid = false, $cart = false, $refer = '')
|
|
|
+ public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $user_coupon_id, $cart = false, $refer = '')
|
|
|
{
|
|
|
if (!$user) {
|
|
|
Dever::alert('错误的用户信息');
|
|
|
}
|
|
|
|
|
|
$uid = $user['id'];
|
|
|
-
|
|
|
- if (!$parent_uid && Dever::project('invite')) {
|
|
|
- $parent = Dever::load('invite/api')->getParent($uid, 1);
|
|
|
- if ($parent) {
|
|
|
- $parent_uid = $parent['uid'];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($parent_uid) {
|
|
|
- $order_data['parent_uid'] = $parent_uid;
|
|
|
- }
|
|
|
|
|
|
$order_data['shop_id'] = $shop['id'];
|
|
|
$order_data['uid'] = $uid;
|
|
@@ -50,17 +39,11 @@ class Sell
|
|
|
if ($card) {
|
|
|
$order_data['card_code_id'] = $card['id'];
|
|
|
}
|
|
|
- if ($coupon_id) {
|
|
|
- $order_data['coupon_id'] = $coupon_id;
|
|
|
- }
|
|
|
if ($user_coupon_id) {
|
|
|
$order_data['user_coupon_id'] = $user_coupon_id;
|
|
|
}
|
|
|
|
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
|
- $order_data['pay_id'] = $order_data['order_num'];
|
|
|
- $order_data['pay_status'] = 1;
|
|
|
- $order_data['pay_price'] = 0;
|
|
|
$id = Dever::db('shop/sell_order')->insert($order_data);
|
|
|
|
|
|
if (!$id) {
|
|
@@ -84,7 +67,7 @@ class Sell
|
|
|
if ($card || $price <= 0) {
|
|
|
|
|
|
$param['pay_product_id'] = $id;
|
|
|
- $param['pay_order_id'] = $order_data['pay_id'];
|
|
|
+ $param['pay_order_id'] = $order_data['order_num'];
|
|
|
$param['pay_status'] = 2;
|
|
|
$param['pay_cash'] = $price;
|
|
|
$param['pay_msg'] = '';
|
|
@@ -95,7 +78,7 @@ class Sell
|
|
|
$this->dropCart($uid, $goods, $shop['id']);
|
|
|
}
|
|
|
|
|
|
- $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
+ $this->useCoupon($user_coupon_id);
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
@@ -108,7 +91,7 @@ class Sell
|
|
|
'name' => $order_data['name'],
|
|
|
'cash' => $price,
|
|
|
'product_id' => $id,
|
|
|
- 'order_id' => $order_data['pay_id'],
|
|
|
+ 'order_id' => $order_data['order_num'],
|
|
|
'refer' => $refer,
|
|
|
);
|
|
|
|
|
@@ -123,7 +106,7 @@ class Sell
|
|
|
$this->dropCart($uid, $goods, $shop['id']);
|
|
|
}
|
|
|
|
|
|
- $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
+ $this->useCoupon($user_coupon_id);
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
@@ -137,7 +120,7 @@ class Sell
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function useCoupon($coupon_id, $user_coupon_id)
|
|
|
+ public function useCoupon($user_coupon_id)
|
|
|
{
|
|
|
if ($user_coupon_id) {
|
|
|
Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
|
|
@@ -160,12 +143,13 @@ class Sell
|
|
|
$param = array
|
|
|
(
|
|
|
'project_id' => 1,
|
|
|
- 'account_id' => 5,
|
|
|
+ 'channel_id' => 1,
|
|
|
+ 'system_source' => 5,
|
|
|
'uid' => $order['uid'],
|
|
|
'name' => $order['name'],
|
|
|
'cash' => $order['price'],
|
|
|
'product_id' => $id,
|
|
|
- 'order_id' => $order['pay_id'],
|
|
|
+ 'order_id' => $order['order_num'],
|
|
|
'refer' => $refer,
|
|
|
);
|
|
|
|
|
@@ -207,41 +191,59 @@ class Sell
|
|
|
$msg = $send['pay_msg'];
|
|
|
|
|
|
$order = Dever::db('shop/sell_order')->one(array('id' => $product_id, 'time' => time()));
|
|
|
- if ($order && $order['pay_status'] == 1) {
|
|
|
+ if ($order && $order['status'] == 1) {
|
|
|
|
|
|
if ($status == 2) {
|
|
|
|
|
|
$this->updateSell($order);
|
|
|
|
|
|
-
|
|
|
- if (Dever::project('message')) {
|
|
|
- Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', '购买成功', 1);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
$update['code'] = $this->getCode();
|
|
|
if ($order['method'] == 1) {
|
|
|
- $update['code_status'] = 2;
|
|
|
+ $msg = '您有一件自提商品已订购成功,取件码:' . $update['code'];
|
|
|
} else {
|
|
|
- $update['ps_status'] = 2;
|
|
|
+ $msg = '您有一件外送商品已订购成功,核销码:' . $update['code'];
|
|
|
+
|
|
|
+ $this->updatePs($order);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- $update['ps_cash'] = 0;
|
|
|
- $update['ps_id'] = 1;
|
|
|
+
|
|
|
+ if (Dever::project('message')) {
|
|
|
+ $shop = Dever::db('shop/info')->one($order['shop_id']);
|
|
|
+ $msg_param['type'] = 1;
|
|
|
+ $msg_param['id'] = $order['id'];
|
|
|
+ $msg_param['name'] = $shop['name'];
|
|
|
+ $msg_param = Dever::json_encode($msg_param);
|
|
|
+ Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', $msg, 1, 1, false, $msg_param);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $update['pay_status'] = $status;
|
|
|
$update['status'] = 2;
|
|
|
$update['where_id'] = $order['id'];
|
|
|
- $update['pay_time'] = time();
|
|
|
- $update['pay_price'] = $cash;
|
|
|
Dever::db('shop/sell_order')->update($update);
|
|
|
}
|
|
|
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function updatePs($order)
|
|
|
+ {
|
|
|
+ $where['order_id'] = $order['id'];
|
|
|
+ $data = Dever::db('shop/sell_order_ps')->find($where);
|
|
|
+
|
|
|
+ if (!$data) {
|
|
|
+ $insert = $where;
|
|
|
+ $insert['uid'] = $order['uid'];
|
|
|
+ $insert['shop_id'] = $order['shop_id'];
|
|
|
+ $insert['service_id'] = -1;
|
|
|
+ $insert['price'] = 0;
|
|
|
+ $insert['num'] = $order['num'];
|
|
|
+
|
|
|
+ Dever::db('shop/sell_order_ps')->insert($insert);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function updateSell($order)
|
|
|
{
|