find($id); $data['order'] = array(); $data['order']['订单号'] = $info['order_num']; $seller = Dever::db('role/seller')->find($info['seller_id']); $data['order']['销售商'] = $seller['name']; if ($info['uid'] && $info['uid'] > 0) { $user = Dever::db('passport/api')->info($info['uid']); $data['order']['购买人'] = $user; } $data['order'] = Dever::table($data['order']); if ($info['address']) { $data['address'] = array(); $info['address'] = Dever::json_encode($info['address']); if ($info['address']) { $data['address']['收件人'] = $info['address']['name']; $data['address']['手机号'] = $info['address']['mobile']; $data['address']['地址'] = $info['address']['address']; } $data['address'] = Dever::table($data['address']); } $data['cash'] = array(); $data['cash']['总数量'] = $info['num']; $data['cash']['总金额'] = $info['cash']; $data['cash']['支付金额'] = $info['pay_cash']; $data['cash'] = Dever::table($data['cash']); return $data; } public function ps($id, $name, $data) { Dever::config('base')->hook = true; $order_id = Dever::param('order_id', $data); if ($order_id) { /* $info = Dever::db('order/sell')->find(array('id' => $order_id)); if ($info && $info['status'] < 3) { Dever::load('shop/lib/sell')->notice($info); }*/ } } # 得到商品和总价 public function goods(&$data) { # 1自提,2配送 $data['method'] = Dever::input('method', 1); $goods = Dever::input('goods'); if (!$goods) { Dever::alert('请传入商品'); } $goods = Dever::json_decode($goods); if (!$goods) { Dever::alert('商品信息不存在'); } # 总价 $data['cash'] = 0; # 支付价格 $data['pay_cash'] = 0; # 钱包金额 $data['wallet_cash'] = 0; # 配送金额 $data['ps_cash'] = 0; $data['num'] = 0; # 获取角色 $role = $this->getRole($data); $data['discount_goods'] = array(); $data['discount_cash'] = 0; $data['discount_id'] = 0; # 计算总价格 foreach ($goods as $k => $v) { if (!isset($v['goods_id']) || !isset($v['sku_id'])) { continue; } $v['num'] = isset($v['num']) ? $v['num'] : 1; $data['list'][$k] = Dever::load('product/lib/info')->getInfo($v['goods_id'], $v['sku_id']); $w = array(); $w['goods_id'] = $v; $w['sku_id'] = $s; $w['shop_id'] = $data['shop']['id']; $goods_sku = Dever::db('shop/goods_sku')->find($w); if ($goods_sku) { if (isset($goods_sku['min'])) { $data['list'][$k]['min'] = $goods_sku['min']; } if (isset($goods_sku['price_id']) && $goods_sku['price_id'] > 0) { $price_template = Dever::load('price/lib/data')->get($v, $s, $goods_sku['price_id']); if ($price_template) { /* if ($goods_sku['min'] <= 0 && $price_template['price_num'] > 0) { $data['list'][$k]['min'] = $price_template['price_num']; } */ if ($price_template['price_sell'] && $price_template['price_sell'] > 0) { $data['list'][$k]['price'] = $price_template['price_sell']; } } } } $data['list'][$k]['cash'] = $data['list'][$k]['price']; $data['list'][$k]['num'] = $n; # 2是库存不足 $data['list'][$k]['ku_state'] = 1; if ($data['list'][$k]['status'] == 2) { $total = 0; } else { # 验证是否有货 $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $data['shop']['id'], $s); if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) { if ($total < $data['list'][$k]['min']) { $total = 0; } } } 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; # 根据角色设置折扣 if ($role) { $role_set = false; foreach ($role as $rk => $rv) { $discount_goods = Dever::db('act/discount_goods')->getData(array('discount_id' => $rv['id'])); if ($discount_goods) { $discount_goods = array_keys($discount_goods); if (in_array($data['list'][$k]['id'], $discount_goods)) { $role_set = $rv; break; } } elseif ($rv['category'] && in_array($data['list'][$k]['top_category_id'], $rv['category'])) { $role_set = $rv; break; } } if ($role_set) { $discount_cash = round($data['list'][$k]['price'] * ($role_set['num']/10), 2); $data['list'][$k]['discount_id'] = $role_set['id']; $data['discount_goods'][] = $data['list'][$k]; $data['discount_id'] = $role_set['id']; $data['list'][$k]['discount_cash'] = round(($data['list'][$k]['price'] - $discount_cash) * $n, 2); $data['discount_cash'] += $data['list'][$k]['discount_cash']; $data['price'] += $discount_cash * $n; } else { $data['price'] += $data['list'][$k]['price'] * $n; } } else { $data['price'] += $data['list'][$k]['price'] * $n; } $data['oprice'] += $data['list'][$k]['cash'] * $n; $data['name'][] = $data['list'][$k]['name']; } } $data['name'] = implode(',', $data['name']); if ($data['method'] == 2) { $data['ps_cash'] = $data['shop']['ps_cash']; if ($data['shop']['free_ps_cash'] && $data['shop']['free_ps_cash'] > 0 && $data['price'] >= $data['shop']['free_ps_cash']) { $data['ps_cash'] = 0; } if (!$data['ps_cash']) { $data['ps_cash'] = 0; } } return $data; } public function getRole($data) { if(isset($data['uid']) && $data['uid'] > 0) { return Dever::load('shop/lib/info')->getRole($data['uid']); } return false; } # 发起支付 public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $wallet_cash, $coupon_id, $user_coupon_id, $coupon_cash, $discount_id, $discount_cash, $cart = false, $system_source = 5, $refer = '') { if (!$user) { Dever::alert('错误的用户信息'); } $uid = $user['id']; if ($uid > 0) { $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1)); if (!$wechat) { //Dever::alert('错误的用户信息'); } } if ($method == 2) { $ps_cash = $shop['ps_cash']; if ($shop['free_ps_cash'] && $shop['free_ps_cash'] > 0 && $price >= $shop['free_ps_cash']) { $ps_cash = 0; } if (!$ps_cash) { $ps_cash = 0; } $order_data['ps_cash'] = $ps_cash; $price += $order_data['ps_cash']; } $order_data['shop_id'] = $shop['id']; if ($shop['type'] == 10) { $order_data['shop_type'] = 2; } else { $order_data['shop_type'] = 1; } $order_data['area'] = $shop['area'] . ',' . $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['oprice'] = $oprice; $order_data['price'] = $price; $order_data['kou_cash'] = $cash; $order_data['method'] = $method; $order_data['pay_method'] = $pay_method; $order_data['pay_type'] = $pay_type; $order_data['refund_cash'] = 0; if ($card) { // $order_data['card_id'] = $card['info']['id']; $order_data['card_code_id'] = $card['id']; $order_data['card_code_card'] = $card['card']; $order_data['card_code_cash'] = $card['cash']; } elseif ($wallet_cash && $wallet_cash > 0) { $order_data['wallet_cash'] = $wallet_cash; } 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; } if ($discount_id) { $order_data['discount_id'] = $discount_id; } if ($discount_cash) { $order_data['discount_cash'] = $discount_cash; } $time = time(); $order_data_where = $order_data; $order_data_where['start'] = $time - 60; $order_data_where['end'] = $time; $order_data_where['option']['start'] = array('yes-cdate', '>='); $order_data_where['option']['end'] = array('yes-cdate', '<='); $info = Dever::db('shop/sell_order')->find($order_data_where); $order_data['order_num'] = $this->getOrderId(); if (!$info) { $id = Dever::db('shop/sell_order')->insert($order_data); } else { return array ( 'order' => '', 'order_num' => $info['order_num'], 'order_id' => $info['id'], 'type' => 'test', ); } if (!$id) { Dever::alert('支付失败'); } foreach($goods as $k => $v) { if ($v['ku_state'] == 1) { $data['uid'] = $uid; $data['order_id'] = $id; $data['shop_id'] = $shop['id']; $data['goods_id'] = $v['id']; $data['sku_id'] = $v['sku_id']; $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; } if (isset($v['discount_id']) && $v['discount_id']) { $data['discount_id'] = $v['discount_id']; } if (isset($v['discount_cash']) && $v['discount_cash']) { $data['discount_cash'] = $v['discount_cash']; } Dever::db('shop/sell_order_goods')->insert($data); } } # 减少库存 增加销量 $order_data['id'] = $id; $this->updateSell($order_data); if ($price <= 0 || $pay_type == 2) { $param['pay_product_id'] = $id; $param['pay_order_id'] = $order_data['order_num']; $param['pay_status'] = 2; $param['pay_cash'] = $price; $param['pay_msg'] = ''; $this->success($param); if ($cart) { # 来自购物车,要清空一下 $this->dropCart($cart, $uid, $goods, $shop['id']); } # 使用优惠券 $this->useCoupon($order_data, $coupon_id, $user_coupon_id, $card, $wallet_cash); /* if ($card) { # 更新礼品卡状态 $card_update['where_id'] = $card['id']; $card_update['status'] = 3; $card_update['order_id'] = $id; $card_update['shop_id'] = $shop['id']; Dever::db('goods/card_code')->update($card_update); }*/ return array ( 'order' => '', 'order_num' => $order_data['order_num'], 'order_id' => $id, 'type' => 'test', ); } $sell_config = Dever::db('main/sell_config')->one(); # 分账 $other = false; if (isset($shop['mid']) && $shop['mid']) { $other = array ( 'mid' => $shop['mid'], 'order_id' => $order_data['order_num'] . '_' . $shop['id'], 'per' => $sell_config['per'], 'oprice' => $oprice, ); } $param = array ( 'project_id' => 1, 'channel_id' => 1, 'system_source' => $system_source, 'uid' => $uid, 'name' => $order_data['name'], 'cash' => $price, 'product_id' => $id, 'order_id' => $order_data['order_num'], 'other' => $other, 'refer' => $refer, ); if ($uid > 0 && isset($wechat) && $wechat) { $param['openid'] = $wechat['openid']; } $receipt = Dever::input('receipt'); if ($receipt) { $param['receipt'] = $receipt; } $result = Dever::load('pay/api.pay', $param); //$result['type'] = 'test'; //$result['order'] = ''; if ($cart) { # 来自购物车,要清空一下 $this->dropCart($cart, $uid, $goods, $shop['id']); } # 使用优惠券 $this->useCoupon($order_data, $coupon_id, $user_coupon_id, $card, $wallet_cash); $result['order_num'] = $order_data['order_num']; $result['order_id'] = $id; return $result; } }