public function order_collection_doc() { //获得订单号 $order_no = IFilter::act(IReq::get('order_no')); $text = "<br /><div align='center'>付款已完成</div>"; if (payment::updateOrder($order_no)) { //获得collection_doc表的对象 $tb_collection_doc = new IModel('collection_doc'); $tb_collection_doc->setData(array('order_id' => IFilter::act(IReq::get('id'), 'int'), 'user_id' => IFilter::act(IReq::get('user_id'), 'int'), 'payment_id' => IFilter::act(IReq::get('payment_id'), 'int'), 'collection_account' => IFilter::act(IReq::get('collection_account')), 'time' => date('Y-m-d H:i:s'), 'amount' => IFilter::act(IReq::get('amount'), 'float'), 'note' => IFilter::act(IReq::get('note'), 'text'), 'pay_status' => 1, 'if_del' => 0)); $tb_collection_doc->add(); //生成订单日志 $tb_order_log = new IModel('order_log'); $tb_order_log->setData(array('order_id' => IFilter::act(IReq::get('id'), 'int'), 'user' => $this->admin['admin_id'], 'action' => '付款', 'result' => '成功', 'note' => '订单【' . $order_no . '】付款' . IFilter::act(IReq::get('amount'), 'float'), 'addtime' => date('Y-m-d H:i:s'))); $tb_order_log->add(); $logObj = new log('db'); $logObj->write('operation', array("管理员:" . ISafe::get('admin_name'), "订单更新为已付款", "订单号:" . $order_no . ',已经确定付款')); } else { $text = "<br /><div align='center'>付款失败</div>"; } echo $text; exit; }
function server_callback() { $payment_name = is_array($payment_name = IReq::get('payment_name')) ? IFilter::act($payment_name[0]) : IFilter::act(IReq::get('payment_name')); //初始化参数 $money = null; $message = null; $tradeno = null; //获取支付payment的id值 $pObj = new IModel('payment as a,pay_plugin as b'); $paymentRow = $pObj->getObj('b.file_path = "' . $payment_name . '" and a.plugin_id = b.id', 'a.id'); //载入支付接口文件 $paymentObj = new Payment(); $payObj = $paymentObj->loadMethod($payment_name); if (!is_object($payObj)) { echo 'fail'; exit; } //执行接口回调函数 $return = $payObj->serverCallback(array_merge($_POST, $_GET), $paymentRow['id'], $money, $message, $tradeno); //判断返回状态 if ($return == 1) { if (stripos($tradeno, 'recharge_') !== false) { $tradenoArray = explode('_', $tradeno); $recharge_no = isset($tradenoArray[1]) ? $tradenoArray[1] : 0; if (payment::updateRecharge($recharge_no)) { echo 'success'; exit; } else { echo 'fail'; } } else { if (payment::updateOrder($tradeno)) { echo 'success'; exit; } else { echo 'fail'; } } } else { echo 'fail'; } }
function cart3() { $accept_name = IFilter::act(IReq::get('accept_name')); $province = IFilter::act(IReq::get('province'), 'int'); $city = IFilter::act(IReq::get('city'), 'int'); $area = IFilter::act(IReq::get('area'), 'int'); $address = IFilter::act(IReq::get('address')); $mobile = IFilter::act(IReq::get('mobile')); $telphone = IFilter::act(IReq::get('telphone')); $zip = IFilter::act(IReq::get('zip')); $delivery_id = IFilter::act(IReq::get('delivery_id'), 'int'); $accept_time_radio = IFilter::act(IReq::get('accept_time_radio'), 'int'); $accept_time = IFilter::act(IReq::get('accept_time')); $payment = IFilter::act(IReq::get('payment'), 'int'); $order_message = IFilter::act(IReq::get('message')); $ticket_id = IFilter::act(IReq::get('ticket_id'), 'int'); $is_tax = IFilter::act(IReq::get('is_tax'), 'int'); $tax_title = IFilter::act(IReq::get('tax_title'), 'text'); $gid = intval(IReq::get('direct_gid')); $num = intval(IReq::get('direct_num')); $type = IFilter::act(IReq::get('direct_type')); //商品或者货品 $promo = IFilter::act(IReq::get('direct_promo')); $active_id = intval(IReq::get('direct_active_id')); $tourist = IReq::get('tourist'); //游客方式购物 $order_no = block::createOrderNum(); $order_type = 0; $is_protectPrice = IFilter::act(IReq::get('protect_price')); $dataArray = array(); //防止表单重复提交 if (IReq::get('timeKey') != null) { if (ISafe::get('timeKey') == IReq::get('timeKey')) { IError::show(403, '订单数据不能被重复提交'); exit; } else { ISafe::set('timeKey', IReq::get('timeKey')); } } if ($province == 0 || $city == 0 || $area == 0) { IError::show(403, '请填写收货地址的省市地区'); } if ($delivery_id == 0) { IError::show(403, '请选择配送方式'); } $user_id = $this->user['user_id'] == null ? 0 : $this->user['user_id']; //活动特殊处理 if ($promo != '' && $active_id != '') { //团购 if ($promo == 'groupon') { $hashId = $user_id ? $user_id : ICookie::get("regiment_{$active_id}"); //此团购还存在已经报名但是未付款的情况 if (regiment::hasJoined($active_id, $hashId) == true) { IError::show(403, '您已经参加过此次团购,请先完成支付'); exit; } //团购已经达到限定的人数 if (regiment::isFull($active_id) == true) { IError::show(403, '此团购的参加人数已满'); exit; } $order_type = 1; //团购开始报名 $joinUserId = $user_id ? $user_id : null; $resultData = regiment::join($active_id, $joinUserId); $is_success = ''; if ($resultData['flag'] == true) { $regimentRelationObj = new IModel('regiment_user_relation'); $regimentRelationObj->setData(array('order_no' => $order_no)); $is_success = $regimentRelationObj->update('id = ' . $resultData['relation_id']); } if ($is_success == '' || $resultData['flag'] == false) { $errorMsg = isset($resultData['data']) && $resultData['data'] != '' ? $resultData['data'] : '团购报名失败'; IError::show(403, $errorMsg); exit; } } else { if ($promo == 'time') { $order_type = 2; } } } //付款方式,判断是否为货到付款 $deliveryObj = new IModel('delivery'); $deliveryRow = $deliveryObj->getObj('id = ' . $delivery_id, 'type'); if ($deliveryRow['type'] == 0 && $payment == 0) { IError::show(403, '请选择支付方式'); } else { if ($deliveryRow['type'] == 1) { $payment = 0; } } $countSumObj = new CountSum(); //直接购买商品方式 if ($type != '' && $gid != 0) { //计算$gid商品 $goodsResult = $countSumObj->direct_count($gid, $type, $num, $promo, $active_id); } else { //计算购物车中的商品价格$goodsResult $goodsResult = $countSumObj->cart_count(); //清空购物车 $cartObj = new Cart(); $cartObj->clear(); } //判断商品商品是否存在 if (empty($goodsResult['goodsList']) && empty($goodsResult['productList'])) { IError::show(403, '商品数据不存在'); exit; } $sum_r = $goodsResult['sum']; $proReduce_r = $goodsResult['proReduce']; $reduce_r = $goodsResult['reduce']; $final_sum_r = $goodsResult['final_sum']; $freeFreight_r = $goodsResult['freeFreight']; $point_r = $goodsResult['point']; $exp_r = $goodsResult['exp']; //计算运费$deliveryPrice和保价$protect_price $deliveryList = Delivery::getDelivery($province, $goodsResult['weight'], $final_sum_r); $deliveryPrice = $deliveryList[$delivery_id]['price']; if ($is_protectPrice == null) { $protect_price = 0; $if_insured = 0; } else { $protect_price = $deliveryList[$delivery_id]['protect_price']; $if_insured = 1; } if ($freeFreight_r == true) { $deliveryPrice_r = 0; } else { $deliveryPrice_r = $deliveryPrice; } //获取红包减免金额 if ($ticket_id != '') { $memberObj = new IModel('member'); $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'prop,custom'); if (ISafe::get('ticket_' . $ticket_id) == $ticket_id || stripos(',' . trim($memberRow['prop'], ',') . ',', ',' . $ticket_id . ',') !== false) { $propObj = new IModel('prop'); $ticketRow = $propObj->getObj('id = ' . $ticket_id . ' and NOW() between start_time and end_time and type = 0 and is_close = 0 and is_userd = 0 and is_send = 1'); if (!empty($ticketRow)) { $ticket_value = $ticketRow['value']; $reduce_r += $ticket_value; $final_sum_r -= $ticket_value; $dataArray['prop'] = $ticket_id; } //锁定红包状态 $propObj->setData(array('is_close' => 2)); $propObj->update('id = ' . $ticket_id); } } //获取税率$tax if ($is_tax == 1) { $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); $tax_per = isset($site_config['tax']) ? $site_config['tax'] : 0; $tax = $final_sum_r * ($tax_per / 100); } else { $tax = 0; } //货到付款的方式 if ($payment == 0) { $paymentName = '货到付款'; $payment_fee = 0; $paymentType = 0; $paymentNote = ''; } else { //计算支付手续费 $paymentObj = new IModel('payment'); $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,poundage,poundage_type,name,note'); $paymentName = $paymentRow['name']; $paymentType = $paymentRow['type']; $paymentNote = $paymentRow['note']; if ($paymentRow['poundage_type'] == 1) { $payment_fee = ($final_sum_r + $tax + $deliveryPrice_r + $protect_price) * ($paymentRow['poundage'] / 100); } else { $payment_fee = $paymentRow['poundage']; } } //最终订单金额计算 $order_amount = $final_sum_r + $deliveryPrice_r + $payment_fee + $tax + $protect_price; $order_amount = $order_amount <= 0 ? 0 : round($order_amount, 2); //生成的订单数据 $dataArray = array('order_no' => $order_no, 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'status' => 1, 'pay_status' => 0, 'distribution_status' => 0, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'invoice' => $is_tax, 'postscript' => $order_message, 'invoice_title' => $tax_title, 'accept_time' => $accept_time, 'exp' => $exp_r, 'point' => $point_r, 'type' => $order_type, 'prop' => isset($dataArray['prop']) ? $dataArray['prop'] : null, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $deliveryPrice, 'real_freight' => $deliveryPrice_r, 'pay_fee' => $payment_fee, 'taxes' => $tax, 'promotions' => $proReduce_r + $reduce_r, 'order_amount' => $order_amount, 'if_insured' => $if_insured, 'insured' => $protect_price); $orderObj = new IModel('order'); $orderObj->setData($dataArray); $this->order_id = $orderObj->add(); if ($this->order_id == false) { IError::show(403, '订单生成错误'); } /*将订单中的商品插入到order_goods表*/ $orderGoodsObj = new IModel('order_goods'); $goodsArray = array('order_id' => $this->order_id); $findType = array('goods' => 'goodsList', 'product' => 'productList'); foreach ($findType as $key => $list) { if (isset($goodsResult[$list]) && count($goodsResult[$list]) > 0) { foreach ($goodsResult[$list] as $k => $val) { //拼接商品名称和规格数据 $specArray = array('name' => $val['name'], 'value' => ''); if ($key == 'product') { $goodsArray['product_id'] = $val['id']; $goodsArray['goods_id'] = $val['goods_id']; $spec = block::show_spec($val['spec_array']); foreach ($spec as $skey => $svalue) { $specArray['value'] .= $skey . ':' . $svalue . ' , '; } } else { $goodsArray['goods_id'] = $val['id']; $goodsArray['product_id'] = 0; } $specArray = serialize($specArray); $goodsArray['goods_price'] = $val['sell_price']; $goodsArray['real_price'] = $val['sell_price'] - $val['reduce']; $goodsArray['goods_nums'] = $val['count']; $goodsArray['goods_weight'] = $val['weight']; $goodsArray['goods_array'] = $specArray; $orderGoodsObj->setData($goodsArray); $orderGoodsObj->add(); } } } //更改购买商品的库存数量 Block::updateStore($this->order_id, 'reduce'); //记录用户默认习惯的数据 if (!isset($memberRow['custom'])) { $memberObj = new IModel('member'); $memberRow = $memberObj->getObj('user_id = ' . $user_id, 'custom'); } $memberData = array('custom' => serialize(array('payment' => $payment, 'delivery' => $delivery_id))); $memberObj->setData($memberData); $memberObj->update('user_id = ' . $user_id); //收货地址的处理 if ($user_id) { $addressObj = new IModel('address'); //如果用户之前没有收货地址,那么会自动记录此次的地址信息并且为默认 $addressRow = $addressObj->getObj('user_id = ' . $user_id); if (empty($addressRow)) { $addressData = array('default' => '1', 'user_id' => $user_id, 'accept_name' => $accept_name, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'zip' => $zip, 'telphone' => $telphone, 'mobile' => $mobile); $addressObj->setData($addressData); $addressObj->add(); } else { //如果用户有收货地址,但是没有设置默认项,那么会自动设置此次地址信息为默认 $radio_address = intval(IReq::get('radio_address')); if ($radio_address != 0) { $addressDefRow = $addressObj->getObj('user_id = ' . $user_id . ' and `default` = 1'); if (empty($addressDefRow)) { $addressData = array('default' => 1); $addressObj->setData($addressData); $addressObj->update('user_id = ' . $user_id . ' and id = ' . $radio_address); } } } } //获取备货时间 $siteConfigObj = new Config("site_config"); $site_config = $siteConfigObj->getInfo(); $this->stockup_time = isset($site_config['stockup_time']) ? $site_config['stockup_time'] : 2; //数据渲染 $this->order_num = $dataArray['order_no']; $this->final_sum = $dataArray['order_amount']; $this->payment_fee = $payment_fee; $this->payment = $paymentName; $this->delivery = $deliveryList[$delivery_id]['name']; $this->tax_title = $tax_title; $this->deliveryType = $deliveryRow['type']; $this->paymentType = $paymentType; $this->paymentNote = $paymentNote; //订单金额为0时,订单自动完成 if ($this->final_sum <= 0) { $order_id = payment::updateOrder($dataArray['order_no']); if ($order_id != '') { if ($user_id) { $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货") . '/?callback=ucenter/order_detail/id/' . $order_id); } else { $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货")); } } else { IError::show(403, '订单修改失败'); } } else { $this->redirect('cart3'); } }