find($id); $data['order'] = array(); $data['order']['订单号'] = $info['order_num']; $seller = Dever::db('scm_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('scm_order/sell')->find(array('id' => $order_id)); if ($info && $info['status'] < 3) { Dever::load('shop/lib/sell')->notice($info); }*/ } } # 得到商品和总价 public function goods($uid, $seller_id = 1) { $goods = Dever::input('goods'); if (!$goods) { Dever::alert('请传入商品'); } $goods = Dever::json_decode($goods); if (!$goods) { Dever::alert('商品信息不存在'); } $data = array(); # 总价 $data['cash'] = 0; # 支付价格 $data['pay_cash'] = 0; # 钱包金额 $data['wallet_cash'] = 0; # 配送金额 $data['ps_cash'] = 0; # 总数量 $data['num'] = 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('scm_product/lib/info')->getPayInfo($v['goods_id'], $v['sku_id'], $seller_id); if (!$data['list'][$k]) { continue; } if ($data['list'][$k]['sell_type'] == 2) { continue; } $data['list'][$k]['pay_cash'] = $data['list'][$k]['cash'] = $data['list'][$k]['price']; unset($data['list'][$k]['price']); $data['list'][$k]['num'] = $v['num']; # 1可以购买 2不可以购买 $data['list'][$k]['buy_state'] = 1; if ($data['list'][$k]['stock'] == 1) { if ($data['list'][$k]['status'] == 2) { $stock = 0; } else { # 获取库存 $stock = $this->stock($data['list'][$k]['num'], $v['goods_id'], $v['sku_id'], $seller_id); if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) { if ($stock < $data['list'][$k]['min']) { $stock = 0; } } } if ($stock <= 0) { # 如果没有库存了 $data['list'][$k]['buy_state'] = 2; $data['list'][$k]['buy_num'] = 0; } } if ($data['list'][$k]['buy_state'] == 1) { $data['list'][$k]['buy_num'] = $v['num']; $data['num'] += $v['num']; $data['cash'] += $data['list'][$k]['cash'] * $v['num']; $data['pay_cash'] += $data['list'][$k]['pay_cash'] * $v['num']; } } /* if ($data['method'] == 2) { # 获取配送商的价格 $data['ps_cash'] = $data['shop']['ps_cash']; if ($data['shop']['free_ps_cash'] && $data['shop']['free_ps_cash'] > 0 && $data['cash'] >= $data['shop']['free_ps_cash']) { $data['ps_cash'] = 0; } if (!$data['ps_cash']) { $data['ps_cash'] = 0; } }*/ return $data; } # 实时获取库存 之后改成从redis中获取 public function stock($num, $goods_id, $sku_id, $seller_id) { $seller = Dever::db('scm_role/seller')->find($seller_id); if ($seller['stock'] == 2 && $seller['stock_seller'] > 0) { $seller_id = $seller['stock_seller']; } $where['seller_id'] = $seller_id; $where['goods_id'] = $goods_id; $where['sku_id'] = $sku_id; $info = Dever::db('scm_role/seller_goods_sku')->getOne($where); if (!$info) { return 0; } $total = $info['total']; return $total; } # 发起支付 public function pay($data, $uid, $seller_id, $info = '', $cart = false, $refer = '') { if (!$uid) { Dever::alert('错误的用户信息'); } if ($uid > 0) { $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1)); if (!$wechat) { //Dever::alert('错误的用户信息'); } } $order_data['seller_id'] = $seller_id; $order_data['uid'] = $uid; //$order_data['address'] = $address; $order_data['num'] = $data['num']; $order_data['info'] = $info; $order_data['cash'] = $data['cash']; $order_data['pay_cash'] = $data['pay_cash']; $order_data['wallet_cash'] = $data['wallet_cash']; $order_data['ps_cash'] = $data['ps_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('scm_order/sell')->find($order_data_where); $order_data['order_num'] = $this->getOrderId(); if (!$info) { $id = Dever::db('scm_order/sell')->insert($order_data); } else { return array ( 'order' => '', 'order_num' => $info['order_num'], 'order_id' => $info['id'], 'type' => 'test', ); } if (!$id) { Dever::alert('支付失败'); } foreach($data['list'] as $k => $v) { if ($v['buy_state'] == 1) { $data['uid'] = $uid; $data['order_id'] = $id; $data['seller_id'] = $seller_id; $data['goods_id'] = $v['id']; $data['sku_id'] = $v['sku_id']; $data['cash'] = $v['cash']; $data['pay_cash'] = $v['pay_cash']; $data['num'] = $v['buy_num']; Dever::db('scm_order/sell_goods')->insert($data); } } # 减少库存 增加销量 $order_data['id'] = $id; $this->updateStock($order_data); if ($price <= 0) { $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, $seller_id, $data['list']); } # 使用优惠券 //$this->useCoupon($order_data, $coupon_id, $user_coupon_id, $card, $wallet_cash); 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; } }