public function doPay() { // 获得payment_id 获得相关参数 $payment_id = Filter::int(Req::args('payment_id')); $order_id = Filter::int(Req::args('order_id')); $recharge = Req::args('recharge'); $extendDatas = Req::args(); if ($payment_id) { $payment = new Payment($payment_id); $paymentPlugin = $payment->getPaymentPlugin(); //充值处理 if ($recharge != null) { $recharge = Filter::float($recharge); $paymentInfo = $payment->getPayment(); $data = array('account' => $recharge, 'paymentName' => $paymentInfo['name']); $packData = $payment->getPaymentInfo('recharge', $data); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { if ($order_id != null) { $order = Order::getOrder($order_id); $model = new Model("order_goods"); if ($order) { //获取订单可能延时时长,0不限制 $config = Config::getInstance(); $config_other = $config->get('other'); // todo 修改方法 order type 去掉 详情表中记录 order type switch ($order['type']) { case '1': $order_delay = isset($config_other['other_order_delay_group']) ? intval($config_other['other_order_delay_group']) : 120; break; case '2': $order_delay = isset($config_other['other_order_delay_flash']) ? intval($config_other['other_order_delay_flash']) : 120; break; case '3': $order_delay = isset($config_other['other_order_delay_bund']) ? intval($config_other['other_order_delay_bund']) : 0; break; default: $order_delay = isset($config_other['other_order_delay']) ? intval($config_other['other_order_delay']) : 0; break; } $time = strtotime("-" . $order_delay . " Minute"); $create_time = strtotime($order['create_time']); if ($create_time >= $time || $order_delay == 0) { //取得所有订单商品 //$order_goods = $model->table('order_goods')->fields("product_id,goods_nums, prom_type")->where('order_id='.$order_id)->findAll(); $order_goods_inst = new OrderGoods(); $order_goods = $order_goods_inst->getOrderGoods($order_id); $product_ids = array(); $order_products = array(); // todo 这里判断 prom_type 类型 foreach ($order_goods as $value) { // 套餐不在这里检查商品库存 考虑在别的地方检查 // 如果订单详细表中行是由于捆绑促销 if ($value['prom_type'] == 'bundling') { continue; } else { $product_ids[] = $value['product_id']; $order_products[$value['product_id']] = $value['goods_nums']; } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); /* 这里不需要验证库存量 提交订单时已经验证 if (!empty($product_ids)) { $product_ids = implode(',', $product_ids); $products = $model->table('products')->fields("id,store_nums")->where("id in ($product_ids)")->findAll(); $products_list = array(); foreach ($products as $value) { $products_list[$value['id']] = $value['store_nums']; } $flag = true; foreach ($order_goods as $value) { if ($order_products[$value['product_id']] > $products_list[$value['product_id']]) { $flag = false; break; } } //检测库存是否还能满足订单 if ($flag) { //团购订单 if ($order['type'] == 1 || $order['type'] == 2) { if ($order['type'] == 1) { $prom_name = '团购'; $prom_table = "groupbuy"; } else { $prom_name = '抢购'; $prom_table = "flash_sale"; } $prom = $model->table($prom_table)->where("id=" . $order['prom_id'])->find(); if ($prom) { if (time() > strtotime($prom['end_time']) || $prom['max_num'] <= $prom["goods_num"]) { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,' . $prom_name . "活动已结束。")); exit; } } } $packData = $payment->getPaymentInfo('order', $order_id); $packData = array_merge($extendDatas, $packData); $sendData = $paymentPlugin->packData($packData); } else { $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,库存已不足。')); exit; } } */ } else { $model->data(array('status' => 6))->where('id=' . $order_id)->update(); $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '订单超出了规定时间内付款,已作废.')); exit; } } } } if (!empty($sendData)) { $this->assign("paymentPlugin", $paymentPlugin); $this->assign("sendData", $sendData); $this->redirect('pay_form', false); } else { $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '需要支付的订单已经不存在。')); } } else { echo "fail"; } }
public static function getOrderWithDetailByNo($orderNo) { $order = Order::getOrderByNo($orderNo); if ($order) { $order_id = $order['id']; $order_goods_inst = new OrderGoods(); $order['OrderGoods'] = $order_goods_inst->getOrderGoods($order_id); $ret = array('status' => 1, 'data' => $order, 'msg' => '获取订单及详情成功!'); return $ret; } else { $ret = array('status' => 0, 'msg' => '获取订单及详情失败!'); return $ret; } }