|
@@ -8,8 +8,546 @@ use Dever;
|
|
|
|
|
|
class Sell
|
|
|
{
|
|
|
+ # 1是用户自己看,2是门店看
|
|
|
+ public $type = 1;
|
|
|
+ # 1是列表,2是详情
|
|
|
+ public $view = 1;
|
|
|
+ # 获取配置
|
|
|
+ public $config = array();
|
|
|
+ # table
|
|
|
+ public $table = 'shop/sell_order';
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->config = Dever::db($this->table)->config;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 设置订单的类型
|
|
|
+ public function set($type, $view)
|
|
|
+ {
|
|
|
+ $this->type = $type;
|
|
|
+ $this->view = $view;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取公共的where
|
|
|
+ public function where($id)
|
|
|
+ {
|
|
|
+ $where = array();
|
|
|
+ if ($this->type == 1) {
|
|
|
+ $where['uid'] = $id;
|
|
|
+ } elseif ($this->type == 2) {
|
|
|
+ $where['shop_id'] = $id;
|
|
|
+ }
|
|
|
+ if (!$where) {
|
|
|
+ Dever::alert('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $where;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取订单列表
|
|
|
+ public function getList($id)
|
|
|
+ {
|
|
|
+ $result = array();
|
|
|
+ $where = $this->where($id);
|
|
|
+ $mobile = Dever::input('mobile');
|
|
|
+ if ($mobile) {
|
|
|
+ $where['mobile'] = $mobile;
|
|
|
+ }
|
|
|
+ $status = Dever::input('status');
|
|
|
+ if ($status) {
|
|
|
+ $where['status'] = $status;
|
|
|
+ }
|
|
|
+
|
|
|
+ $method = Dever::input('method');
|
|
|
+ if ($method) {
|
|
|
+ $where['method'] = $method;
|
|
|
+ }
|
|
|
+
|
|
|
+ $pay_method = Dever::input('pay_method');
|
|
|
+ if ($pay_method) {
|
|
|
+ $where['pay_method'] = $pay_method;
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['search_value'] = $where;
|
|
|
+ $result['search_value']['day'] = $day = Dever::input('day');
|
|
|
+ if ($day) {
|
|
|
+ $where['start'] = Dever::maketime($day . ' 00:00:00');
|
|
|
+ $where['end'] = Dever::maketime($day . ' 23:59:59');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['order'] = Dever::db($this->table)->getAll($where);
|
|
|
+
|
|
|
+ if ($result['order']) {
|
|
|
+ foreach ($result['order'] as $k => $v) {
|
|
|
+ $result['order'][$k] = $this->getInfo($v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['search'] = array();
|
|
|
+ $result['search']['status'] = array
|
|
|
+ (
|
|
|
+ array('value' => 1, 'name' => '待支付'),
|
|
|
+ array('value' => 2, 'name' => '待处理'),
|
|
|
+ array('value' => 3, 'name' => '待自提'),
|
|
|
+ array('value' => 3, 'name' => '配送中'),
|
|
|
+ array('value' => '6,7,8', 'name' => '退款'),
|
|
|
+ array('value' => 4, 'name' => '已完成'),
|
|
|
+ array('value' => 5, 'name' => '已取消'),
|
|
|
+ );
|
|
|
+ $result['search']['method'] = array
|
|
|
+ (
|
|
|
+ array('value' => 1, 'name' => '自提'),
|
|
|
+ array('value' => 2, 'name' => '配送')
|
|
|
+ );
|
|
|
+ $result['search']['pay_method'] = array
|
|
|
+ (
|
|
|
+ array('value' => 1, 'name' => '平台结算'),
|
|
|
+ array('value' => 2, 'name' => '门店代下单')
|
|
|
+ );
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 查看详情
|
|
|
+ public function getView($id, $order_id, $show = true)
|
|
|
+ {
|
|
|
+ $where = $this->where($id);
|
|
|
+ $where['id'] = $order_id;
|
|
|
+
|
|
|
+ $result = Dever::db($this->table)->find($where);
|
|
|
+
|
|
|
+ if (!$result) {
|
|
|
+ Dever::alert('订单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($show) {
|
|
|
+ $result = $this->getInfo($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取订单详细信息
|
|
|
+ public function getInfo($info)
|
|
|
+ {
|
|
|
+ if ($info['status'] == 1) {
|
|
|
+ # 15分钟内支付,900秒
|
|
|
+ $m = 9000;
|
|
|
+ # 支付倒计时
|
|
|
+ $info['time'] = time() - $info['cdate'];
|
|
|
+ if ($info['time'] >= $m) {
|
|
|
+ # 已过期,自动取消
|
|
|
+ $info['time'] = -1;
|
|
|
+ Dever::db($this->table)->update(array('where_id' => $info['id'], 'status' => 11));
|
|
|
+ $info['status'] = 11;
|
|
|
+ } else {
|
|
|
+ $info['time'] = $m - $info['time'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['status_name'] = $this->config['status'][$info['status']];
|
|
|
+ $info['method_name'] = $this->config['method'][$info['method']];
|
|
|
+ $info['pay_method_name'] = $this->config['pay_method'][$info['pay_method']];
|
|
|
+
|
|
|
+ if ($this->type == 1) {
|
|
|
+ if ($info['status'] == 2) {
|
|
|
+ $info['status_name'] = '支付成功';
|
|
|
+ }
|
|
|
+ if ($info['status'] == 3) {
|
|
|
+ if ($info['method'] == 1) {
|
|
|
+ $info['status_name'] = '已配货';
|
|
|
+ } else {
|
|
|
+ $info['status_name'] = '配送中';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } elseif ($this->type == 2) {
|
|
|
+ if ($info['status'] == 2) {
|
|
|
+ $info['status_name'] = '待处理';
|
|
|
+ }
|
|
|
+ if ($info['status'] == 3) {
|
|
|
+ if ($info['method'] == 1) {
|
|
|
+ $info['status_name'] = '待自提';
|
|
|
+ } else {
|
|
|
+ $info['status_name'] = '配送中';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['method'] == 2) {
|
|
|
+ $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
|
|
|
+ if ($info['ps_info']) {
|
|
|
+ $info['ps_info']['service_name'] = '商家自送';
|
|
|
+ if ($info['ps_info']['service_id'] > 0) {
|
|
|
+ //暂时还没有
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
|
|
|
+ $info['user'] = Dever::load('passport/api')->info($info['uid']);
|
|
|
+ $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
|
|
|
+ $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
+
|
|
|
+ if ($this->view == 2) {
|
|
|
+ foreach ($info['goods'] as $k => $v) {
|
|
|
+ $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
|
|
|
+ }
|
|
|
+ if ($info['address_id']) {
|
|
|
+ $info['address'] = Dever::db('passport/address')->find($info['address_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['invoice_id']) {
|
|
|
+ $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['user_coupon_id']) {
|
|
|
+ $coupon = Dever::db('shop/user_coupon')->find($info['user_coupon_id']);
|
|
|
+ if ($coupon) {
|
|
|
+ $info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ foreach ($info['goods'] as $k => $v) {
|
|
|
+ $goods = Dever::db('goods/info')->one($v['goods_id']);
|
|
|
+ $info['goods'][$k]['name'] = $goods['name'];
|
|
|
+ $info['goods'][$k]['cover'] = $goods['cover'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 取消订单
|
|
|
+ public function cancel($id, $order_id)
|
|
|
+ {
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+ if ($data['status'] == 1) {
|
|
|
+ $state = Dever::db('shop/sell_order')->update(array('where_id' => $data['id'], 'status' => 5));
|
|
|
+ if ($state) {
|
|
|
+ if ($data['user_coupon_id']) {
|
|
|
+ $this->noCoupon($data['user_coupon_id']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::alert('当前订单状态不允许取消');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 全部退款
|
|
|
+ public function tui($id, $order_id, $status = 6, $desc = '')
|
|
|
+ {
|
|
|
+ if ($status != 6 && $status != 7 && $status != 8) {
|
|
|
+ Dever::alert('当前订单状态不允许退货退款');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+ if ($data['status'] == 2) {
|
|
|
+ $state = Dever::db('shop/sell_order')->update(array('where_id' => $data['id'], 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $data['price']));
|
|
|
+
|
|
|
+ $this->pay_tui($state, $data, $data['price']);
|
|
|
+
|
|
|
+ if ($state && $data['user_coupon_id']) {
|
|
|
+ $this->noCoupon($data['user_coupon_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::alert('当前订单状态不允许退货退款');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取部分退款的详情
|
|
|
+ public function tui_one_info($id, $order_id, $order_goods_id)
|
|
|
+ {
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+ if ($data['status'] == 2 || $data['status'] == 3 || $data['status'] == 4) {
|
|
|
+ $info = Dever::db('shop/sell_order_goods')->find(array('id' => $order_goods_id, 'order_id' => $data['id'], 'shop_id' => $id));
|
|
|
+ if ($info && $info['status'] <= 2) {
|
|
|
+ $info['tui_price'] = $info['price'] - $info['coupon_cash'];
|
|
|
+ $info['tui_one_price'] = round($info['tui_price'] / $info['num'], 2);
|
|
|
+ $info['goods'] = Dever::db('goods/info')->find($info['goods_id']);
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ } else {
|
|
|
+ Dever::alert('当前订单状态不允许退货退款');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 部分退款
|
|
|
+ public function tui_one($id, $order_id, $order_goods_id, $num = false, $status = 6, $desc = '')
|
|
|
+ {
|
|
|
+ if ($status != 3 && $status != 4) {
|
|
|
+ Dever::alert('当前订单状态不允许退货退款');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->getView($id, $order_id, false);
|
|
|
+ if ($data['status'] == 2 || $data['status'] == 3 || $data['status'] == 4) {
|
|
|
+ $info = Dever::db('shop/sell_order_goods')->find(array('id' => $order_goods_id, 'order_id' => $data['id'], 'shop_id' => $id));
|
|
|
+ if ($info && $info['status'] <= 2) {
|
|
|
+ $info['price'] = $info['price'] - $info['coupon_cash'];
|
|
|
+ if ($num > 0 && $info['num'] >= $num) {
|
|
|
+ $price = round($info['price'] / $info['num'], 2);
|
|
|
+ $info['price'] = round($price * $num, 2);
|
|
|
+ }
|
|
|
+ $state = Dever::db('shop/sell_order_goods')->update(array('where_id' => $info['id'], 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $info['price']));
|
|
|
+
|
|
|
+ if ($state) {
|
|
|
+ $this->pay_tui($state, $data, $info['price']);
|
|
|
+
|
|
|
+ # 检查这个订单下的商品是不是都退了
|
|
|
+ $total = Dever::db('shop/sell_order_goods')->total(array('order_id' => $data['id'], 'shop_id' => $id, 'status' => 1));
|
|
|
+ if ($total <= 0) {
|
|
|
+ $status += 4;
|
|
|
+ $state = Dever::db('shop/sell_order')->update(array('where_id' => $data['id'], 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $info['price']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 'ok';
|
|
|
+ } else {
|
|
|
+ Dever::alert('当前订单状态不允许退货退款');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 退款通知
|
|
|
+ public function pay_tui($state, $data, $price)
|
|
|
+ {
|
|
|
+ if ($state) {
|
|
|
+ $shop = Dever::db('shop/info')->one($data['shop_id']);
|
|
|
+ $msg_param['type'] = 1;//消息类型1是订单消息
|
|
|
+ $msg_param['id'] = $data['id'];
|
|
|
+ $msg_param['name'] = $shop['name'];
|
|
|
+ $msg_param = Dever::json_encode($msg_param);
|
|
|
+ $msg = '您有一笔订单已退款,退款将在3个工作日内返回原支付账户';
|
|
|
+ Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 1, 1, false, $msg_param);
|
|
|
+
|
|
|
+ # 退款到原支付账户 待处理
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取优惠券
|
|
|
+ public function coupon(&$data, $type = 1)
|
|
|
+ {
|
|
|
+ $user_coupon_id = Dever::input('user_coupon_id');
|
|
|
+ $coupon_id = Dever::input('coupon_id');
|
|
|
+
|
|
|
+ $data['user_coupon_id'] = 0;
|
|
|
+ $data['coupon_id'] = 0;
|
|
|
+ $data['coupon_cash'] = 0;
|
|
|
+
|
|
|
+ if ($type == 1 && isset($data['uid']) && $data['uid'] > 0) {
|
|
|
+ if ($data['price'] <= 0) {
|
|
|
+ Dever::alert('付款价格错误');
|
|
|
+ }
|
|
|
+ # 查找符合要求的优惠券
|
|
|
+ $coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $data['uid'], 'city' => $data['shop']['city'], 'status' => 1, 'edate' => time()));
|
|
|
+
|
|
|
+ if ($coupon) {
|
|
|
+ foreach ($coupon as $k => $v) {
|
|
|
+ if ($v['shop_id'] != $data['shop']['id']) {
|
|
|
+ # 查找该券是否符合当前店铺
|
|
|
+ if ($data['shop']['coupon_city'] == 2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
|
|
|
+ if ($coupon_info && ($coupon_info['method'] == $data['method'] || $coupon_info['method'] == 3)) {
|
|
|
+ $kou = false;
|
|
|
+ if ($coupon_info['type'] == 1) {
|
|
|
+ # 满减券
|
|
|
+ if ($data['price'] >= $coupon_info['total_cash']) {
|
|
|
+ $kou = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $kou = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($kou) {
|
|
|
+ $coupon_info['user_coupon_id'] = $v['id'];
|
|
|
+ $coupon_info['uid'] = $v['uid'];
|
|
|
+ $coupon_info['shop_id'] = $v['shop_id'];
|
|
|
+ $coupon_info['edate'] = date('Y-m-d', $v['edate']);
|
|
|
+ $data['coupon'][] = $coupon_info;
|
|
|
+
|
|
|
+ if (!$user_coupon_id && $data['coupon_cash'] <= $coupon_info['cash']) {
|
|
|
+ $data['user_coupon_id'] = $v['id'];
|
|
|
+ $data['coupon_id'] = $coupon_info['id'];
|
|
|
+ $data['coupon_cash'] = $coupon_info['cash'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($user_coupon_id && isset($data['uid']) && $data['uid'] > 0) {
|
|
|
+ if ($data['price'] <= 0) {
|
|
|
+ Dever::alert('付款价格错误');
|
|
|
+ }
|
|
|
+ $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $data['uid'], 'id' => $user_coupon_id, 'status' => 1));
|
|
|
+ if (!$coupon) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+ if (time() > $coupon['edate']) {
|
|
|
+ Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
|
|
|
+ Dever::alert('优惠券已过期');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($coupon['shop_id'] != $data['shop']['id']) {
|
|
|
+ if ($data['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 && $data['price'] < $goods_coupon['total_cash']) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+ if ($goods_coupon['method'] != $data['method'] && $goods_coupon['method'] != 3) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['user_coupon_id'] = $user_coupon_id;
|
|
|
+ $data['coupon_id'] = $goods_coupon['id'];
|
|
|
+ $data['coupon_cash'] = $goods_coupon['cash'];
|
|
|
+ } elseif ($coupon_id && $type == 3) {
|
|
|
+ if ($data['price'] <= 0) {
|
|
|
+ Dever::alert('付款价格错误');
|
|
|
+ }
|
|
|
+ $coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $data['shop']['id'], 'id' => $coupon_id));
|
|
|
+ if (!$coupon_info) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+
|
|
|
+ $goods_coupon = Dever::db('goods/coupon')->find($coupon_info['coupon_id']);
|
|
|
+ if ($goods_coupon['type'] == 2 && $data['price'] < $goods_coupon['total_cash']) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+ if ($goods_coupon['method'] != $data['method'] && $goods_coupon['method'] != 3) {
|
|
|
+ Dever::alert('优惠券不可用');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['user_coupon_id'] = -1;
|
|
|
+ $data['coupon_id'] = $goods_coupon['id'];
|
|
|
+ $data['coupon_cash'] = $goods_coupon['cash'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['coupon_cash']) && $data['coupon_cash'] > 0) {
|
|
|
+ # 这里还要计算每个商品的优惠金额
|
|
|
+ if (isset($data['list']) && $data['list']) {
|
|
|
+ foreach ($data['list'] as $k => $v) {
|
|
|
+ $data['list'][$k]['coupon_id'] = $data['coupon_id'];
|
|
|
+ $data['list'][$k]['user_coupon_id'] = $data['user_coupon_id'];
|
|
|
+ $data['list'][$k]['coupon_cash'] = round($v['price']/$data['price'], 2) * $data['coupon_cash'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['price'] -= $data['coupon_cash'];
|
|
|
+ if ($data['price'] < 0) {
|
|
|
+ $data['price'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ # 得到商品和总价
|
|
|
+ public function goods(&$data)
|
|
|
+ {
|
|
|
+ # 1自提,2配送
|
|
|
+ $data['method'] = Dever::input('method', 1);
|
|
|
+ $data['pay_method'] = Dever::input('pay_method');
|
|
|
+ $card = Dever::input('card');
|
|
|
+ $pwd = Dever::input('pwd');
|
|
|
+
|
|
|
+ if ($data['pay_method'] == 3 && $card && $pwd) {
|
|
|
+ $data['card'] = Dever::db('goods/card_code')->find(array('card' => $card, 'pwd' => $pwd, 'status' => 1));
|
|
|
+ if (!$data['card']) {
|
|
|
+ Dever::alert('卡号/密码错误');
|
|
|
+ }
|
|
|
+ if (time() > $data['card']['edate']) {
|
|
|
+ Dever::alert('礼品卡已失效');
|
|
|
+ }
|
|
|
+ $card_info = Dever::db('goods/card')->find($data['card']['card_id']);
|
|
|
+ if (!$card_info) {
|
|
|
+ Dever::alert('卡号/密码错误');
|
|
|
+ }
|
|
|
+ $goods = Dever::array_decode($card_info['goods']);
|
|
|
+
|
|
|
+ $goods_id = array();
|
|
|
+ $num = array();
|
|
|
+ $sku_id = array();
|
|
|
+ foreach ($goods as $k => $v) {
|
|
|
+ $goods_id[] = $v['goods_id'];
|
|
|
+ $num[] = $v['num'];
|
|
|
+ $sku_id[] = -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $goods_id = Dever::input('goods_id');
|
|
|
+ if (!$goods_id) {
|
|
|
+ Dever::alert('请传入商品');
|
|
|
+ }
|
|
|
+ $goods_id = explode(',', $goods_id);
|
|
|
+
|
|
|
+ $sku_id = Dever::input('price_id');
|
|
|
+ if ($sku_id) {
|
|
|
+ $sku_id = explode(',', $sku_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ $num = Dever::input('num');
|
|
|
+ if (!$num) {
|
|
|
+ Dever::alert('请传入商品数量');
|
|
|
+ }
|
|
|
+ $num = explode(',', $num);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['price'] = 0;
|
|
|
+ $data['num'] = 0;
|
|
|
+ $data['name'] = array();
|
|
|
+ $count = count($goods_id);
|
|
|
+ # 计算总价格
|
|
|
+ foreach ($goods_id as $k => $v) {
|
|
|
+ $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
|
|
|
+ $n = isset($num[$k]) ? $num[$k] : 1;
|
|
|
+ $data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
|
|
|
+ $data['list'][$k]['num'] = $n;
|
|
|
+
|
|
|
+ # 2是库存不足
|
|
|
+ $data['list'][$k]['ku_state'] = 1;
|
|
|
+
|
|
|
+ # 验证是否有货
|
|
|
+ $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $data['shop']['id'], $s);
|
|
|
+
|
|
|
+ if ($total <= 0) {
|
|
|
+ $data['list'][$k]['ku_state'] = 2;
|
|
|
+ $data['list'][$k]['buy_num'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($data['list'][$k]['ku_state'] == 1) {
|
|
|
+ $data['list'][$k]['buy_num'] = $n;
|
|
|
+ $data['num'] += $n;
|
|
|
+ $data['price'] += $data['list'][$k]['price'] * $n;
|
|
|
+ if ($count > 1) {
|
|
|
+ $data['name'][] = $data['list'][$k]['name'];
|
|
|
+ } else {
|
|
|
+ $data['name'][] = $data['list'][$k]['name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
# 发起支付
|
|
|
- public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $user_coupon_id, $cart = false, $refer = '')
|
|
|
+ public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $price, $cash, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
|
|
|
{
|
|
|
if (!$user) {
|
|
|
Dever::alert('错误的用户信息');
|
|
@@ -26,6 +564,7 @@ class Sell
|
|
|
$order_data['num'] = $num;
|
|
|
$order_data['info'] = $info;
|
|
|
$order_data['price'] = $price;
|
|
|
+ $order_data['kou_cash'] = $cash;
|
|
|
|
|
|
$order_data['area'] = $shop['area'];
|
|
|
$order_data['province'] = $shop['province'];
|
|
@@ -35,6 +574,7 @@ class Sell
|
|
|
|
|
|
$order_data['method'] = $method;
|
|
|
$order_data['pay_method'] = $pay_method;
|
|
|
+ $order_data['pay_type'] = $pay_type;
|
|
|
|
|
|
if ($card) {
|
|
|
$order_data['card_code_id'] = $card['id'];
|
|
@@ -42,6 +582,12 @@ class Sell
|
|
|
if ($user_coupon_id) {
|
|
|
$order_data['user_coupon_id'] = $user_coupon_id;
|
|
|
}
|
|
|
+ if ($coupon_id) {
|
|
|
+ $order_data['coupon_id'] = $coupon_id;
|
|
|
+ }
|
|
|
+ if ($coupon_cash) {
|
|
|
+ $order_data['coupon_cash'] = $coupon_cash;
|
|
|
+ }
|
|
|
|
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
|
$id = Dever::db('shop/sell_order')->insert($order_data);
|
|
@@ -60,11 +606,23 @@ class Sell
|
|
|
$data['price'] = $v['price'];
|
|
|
$data['num'] = $v['buy_num'];
|
|
|
|
|
|
+ if (isset($v['user_coupon_id']) && $v['user_coupon_id']) {
|
|
|
+ $data['user_coupon_id'] = $v['user_coupon_id'];
|
|
|
+ }
|
|
|
+ if (isset($v['coupon_id']) && $v['coupon_id']) {
|
|
|
+ $data['coupon_id'] = $v['coupon_id'];
|
|
|
+ }
|
|
|
+ if (isset($v['coupon_cash']) && $v['coupon_cash']) {
|
|
|
+ $data['coupon_cash'] = $v['coupon_cash'];
|
|
|
+ } else {
|
|
|
+ $data['coupon_cash'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
Dever::db('shop/sell_order_goods')->insert($data);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($card || $price <= 0) {
|
|
|
+ if ($card || $price <= 0 || $pay_type == 2) {
|
|
|
|
|
|
$param['pay_product_id'] = $id;
|
|
|
$param['pay_order_id'] = $order_data['order_num'];
|
|
@@ -73,12 +631,12 @@ class Sell
|
|
|
$param['pay_msg'] = '';
|
|
|
$this->success($param);
|
|
|
|
|
|
- if ($cart == 1) {
|
|
|
+ if ($cart) {
|
|
|
# 来自购物车,要清空一下
|
|
|
- $this->dropCart($uid, $goods, $shop['id']);
|
|
|
+ $this->dropCart($cart, $uid, $goods, $shop['id']);
|
|
|
}
|
|
|
# 使用优惠券
|
|
|
- $this->useCoupon($user_coupon_id);
|
|
|
+ $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
|
|
|
if ($card) {
|
|
|
# 更新礼品卡状态
|
|
@@ -97,7 +655,7 @@ class Sell
|
|
|
(
|
|
|
'project_id' => 1,
|
|
|
'channel_id' => 1,
|
|
|
- 'system_source' => 5,
|
|
|
+ 'system_source' => $system_source,
|
|
|
'uid' => $uid,
|
|
|
'name' => $order_data['name'],
|
|
|
'cash' => $price,
|
|
@@ -112,34 +670,48 @@ class Sell
|
|
|
}
|
|
|
|
|
|
$result = Dever::load('pay/api.pay', $param);
|
|
|
- if ($cart == 1) {
|
|
|
+ if ($cart) {
|
|
|
# 来自购物车,要清空一下
|
|
|
- $this->dropCart($uid, $goods, $shop['id']);
|
|
|
+ $this->dropCart($cart, $uid, $goods, $shop['id']);
|
|
|
}
|
|
|
# 使用优惠券
|
|
|
- $this->useCoupon($user_coupon_id);
|
|
|
+ $this->useCoupon($coupon_id, $user_coupon_id);
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- public function dropCart($uid, $goods, $shop_id)
|
|
|
+ public function dropCart($cart, $uid, $goods, $shop_id)
|
|
|
{
|
|
|
$where['uid'] = $uid;
|
|
|
$where['shop_id'] = $shop_id;
|
|
|
foreach ($goods as $k => $v) {
|
|
|
$where['goods_id'] = $v['id'];
|
|
|
- Dever::db('shop/cart')->delete($where);
|
|
|
+ if ($cart == 1) {
|
|
|
+ Dever::db('shop/cart')->delete($where);
|
|
|
+ } else {
|
|
|
+ unset($where['uid']);
|
|
|
+ Dever::db('shop/shop_cart')->delete($where);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function useCoupon($user_coupon_id)
|
|
|
+ public function useCoupon($coupon_id, $user_coupon_id)
|
|
|
{
|
|
|
if ($user_coupon_id) {
|
|
|
Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
|
|
|
}
|
|
|
+
|
|
|
+ # 这里可以记录一下使用日志
|
|
|
+ }
|
|
|
+
|
|
|
+ public function noCoupon($user_coupon_id)
|
|
|
+ {
|
|
|
+ if ($user_coupon_id) {
|
|
|
+ Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 1));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
# 再次发起支付
|
|
|
- public function raction($id, $refer = '')
|
|
|
+ public function rpay($id, $system_source = 5, $refer = '')
|
|
|
{
|
|
|
$order = Dever::db('shop/sell_order')->find($id);
|
|
|
|
|
@@ -155,7 +727,7 @@ class Sell
|
|
|
(
|
|
|
'project_id' => 1,
|
|
|
'channel_id' => 1,
|
|
|
- 'system_source' => 5,
|
|
|
+ 'system_source' => $system_source,
|
|
|
'uid' => $order['uid'],
|
|
|
'name' => $order['name'],
|
|
|
'cash' => $order['price'],
|