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; $order_data['mobile'] = $user['mobile']; $order_data['address_id'] = $address_id; $order_data['invoice_id'] = $invoice_id; $order_data['name'] = $name; $order_data['num'] = $num; $order_data['info'] = $info; $order_data['price'] = $price; $order_data['area'] = $shop['area']; $order_data['province'] = $shop['province']; $order_data['city'] = $shop['city']; $order_data['county'] = $shop['county']; $order_data['town'] = $shop['town']; $order_data['method'] = $method; $order_data['pay_method'] = $pay_method; 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) { Dever::alert('支付失败'); } foreach($goods as $k => $v) { if ($v['ku_state'] == 1) { $data['uid'] = $uid; $data['shop_id'] = $shop['id']; $data['order_id'] = $id; $data['goods_id'] = $v['id']; $data['sku_id'] = $v['sku_id']; $data['price'] = $v['price']; $data['num'] = $v['buy_num']; Dever::db('shop/sell_order_goods')->insert($data); } } if ($card || $price <= 0) { $param['pay_product_id'] = $id; $param['pay_order_id'] = $order_data['pay_id']; $param['pay_status'] = 2; $param['pay_cash'] = $price; $param['pay_msg'] = ''; $this->success($param); if ($cart == 1) { # 来自购物车,要清空一下 $this->dropCart($uid, $goods, $shop['id']); } # 使用优惠券 $this->useCoupon($coupon_id, $user_coupon_id); return 'ok'; } $param = array ( 'project_id' => 1, 'channel_id' => 1, 'system_source' => 5, 'uid' => $uid, 'name' => $order_data['name'], 'cash' => $price, 'product_id' => $id, 'order_id' => $order_data['pay_id'], 'refer' => $refer, ); $receipt = Dever::input('receipt'); if ($receipt) { $param['receipt'] = $receipt; } $result = Dever::load('pay/api.pay', $param); if ($cart == 1) { # 来自购物车,要清空一下 $this->dropCart($uid, $goods, $shop['id']); } # 使用优惠券 $this->useCoupon($coupon_id, $user_coupon_id); return $result; } public function dropCart($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); } } 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 raction($id, $refer = '') { $order = Dever::db('shop/sell_order')->find($id); if (!$order) { Dever::alert('订单信息错误'); } if ($order['status'] > 1) { Dever::alert('订单已支付或已取消'); } $param = array ( 'project_id' => 1, 'account_id' => 5, 'uid' => $order['uid'], 'name' => $order['name'], 'cash' => $order['price'], 'product_id' => $id, 'order_id' => $order['pay_id'], 'refer' => $refer, ); $receipt = Dever::input('receipt'); if ($receipt) { $param['receipt'] = $receipt; } $result = Dever::load('pay/api.pay', $param); return $result; } # 支付成功回调 安全加密 设置token public function success_secure_api_token() { $project_id = Dever::input('pay_project_id'); $info = Dever::db('pay/project')->one($project_id); if ($info) { return $info['key']; } return 'shop_dever_2020'; } # 支付成功回调 安全加密 public function success_secure_api($param = array()) { $this->success($param); } # 支付成功回调 public function success($param = array()) { $send = $param ? $param : Dever::preInput('pay_'); $product_id = $send['pay_product_id']; $order_id = $send['pay_order_id']; $status = $send['pay_status']; $cash = $send['pay_cash']; $msg = $send['pay_msg']; $order = Dever::db('shop/sell_order')->one(array('id' => $product_id, 'time' => time())); if ($order && $order['pay_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; } else { $update['ps_status'] = 2; } } $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 updateSell($order) { $where['order_id'] = $order['id']; $data = Dever::db('shop/sell_order_goods')->select($where); if ($data) { foreach ($data as $k => $v) { $up = array(); $up['where_shop_id'] = $v['shop_id']; $up['where_goods_id'] = $v['goods_id']; $up['sell_num'] = $v['num']; Dever::db('shop/goods')->updateSell($up); if ($v['sku_id'] > 0) { } else { $v['sku_id'] = -1; } $upSku = $up; $upSku['where_sku_id'] = $v['sku_id']; Dever::db('shop/goods_sku')->updateSell($upSku); } } } # 生成自提码 public function getCode() { $where['code'] = Dever::rand(6, 0); $state = Dever::db('shop/sell_order')->one($where); if (!$state) { return $where['code']; } else { return $this->getCode(); } } # 生成订单号 public function getOrderId() { $where['order_num'] = Dever::order('G'); $state = Dever::db('shop/sell_order')->one($where); if (!$state) { return $where['order_num']; } else { return $this->getOrderId(); } } # 展示订单详情 public function show() { $id = Dever::input('order_id'); $config = Dever::db('shop/sell_order')->config; $info = Dever::db('shop/sell_order')->one($id); $shop = Dever::db('shop/info')->find($info['shop_id']); $user = Dever::db('passport/user')->find($info['uid']); if (!$user['truename']) { $user['truename'] = $user['username']; } $html = '[基本信息]:'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; if ($info['address_id'] > 0) { $address = Dever::load('passport/address')->getOne($info['uid'], $info['address_id']); $html .= ''; } if ($info['invoice_id'] > 0) { $invoice = Dever::load('passport/invoice')->getOne($info['uid'], $info['invoice_id']); $html .= ''; } $html .= '
项目详情
订单号 '.$this->table(false, array(array($info['order_num']))).'
门店信息 '.$this->table(false, array(array('门店名称:' . $shop['name'], '联系人:' . $shop['truename'], '联系电话:' . $shop['mobile']))).'
用户信息 '.$this->table(false, array(array('昵称:' . $user['username'], '联系电话:' . $user['mobile']))).'
订单信息 '.$this->table(array('订单状态', '金额', '数量','支付方式', '配送方式'), array(array($config['status'][$info['status']], $info['price'], $info['num'],$config['pay_method'][$info['pay_method']], $config['method'][$info['method']]))).'
收货地址 '.$this->table(array('省份', '城市', '地区','地址', '门牌号', '姓名', '手机号'), array(array($address['province_name'], $address['city_name'], $address['county_name'], $address['address'], $address['house_number'], $address['contact'], $address['mobile']))).'
发票信息 '.$this->table(array('发票类型', '抬头', '税号','手机号', '邮箱'), array(array($invoice['title_type_name'], $invoice['title'], $invoice['number'], $invoice['mobile'], $invoice['email']))).'
'; $html .= '[商品清单]:'; $head = array('商品名称', '商品属性', '商品价格', '商品数量'); $body = array(); $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id'])); foreach ($goods as $k => $v) { $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']); $body[$k] = array ( $goods_info['name'], $v['price'], $v['price'], $v['num'], ); } $html .= $this->table($head, $body); return $html; } private function table($head, $data) { $html = ''; if ($head) { $html = ''; $html .= ''; foreach ($head as $k => $v) { $html .= ''; } $html .= ''; $html .= ''; foreach ($data as $k => $v) { $html .= ''; foreach ($v as $k1 => $v1) { $html .= ''; } $html .= ''; } $html .= ''; $html .= '
'.$v.'
'.$v1.'
'; } else { foreach ($data as $k => $v) { $html .= ''; foreach ($v as $k1 => $v1) { $html .= $v1 . '    '; } $html .= ''; } } return $html; } }