$page = isset($_GET['page']) && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1; $orderGoodsQuery = CountSum::getSellerGoodsFeeQuery($seller_id); $orderGoodsQuery->page = $page; ?> <?php foreach ($orderGoodsQuery->find() as $key => $item) { ?> <?php $goodsSum = $item['goods_price'] * $item['goods_nums']; ?> <?php $orderWeight = $item['goods_weight'] * $item['goods_nums']; ?> <?php $orderCount = CountSum::countOrderFee($goodsSum, $goodsSum, $orderWeight, $item['province'], $item['distribution'], 0, false, $item['if_insured'], $item['invoice']); ?> <tr> <td title="<?php echo isset($item['order_no']) ? $item['order_no'] : ""; ?> "><?php echo isset($item['order_no']) ? $item['order_no'] : ""; ?> </td> <td> <img src='<?php echo IUrl::creatUrl("") . "" . $item['img'] . ""; ?> ' class="ico" /> <?php
public function countGoodsFee() { $seller_id = $this->seller['seller_id']; $start_time = IFilter::act(IReq::get('start_time')); $end_time = IFilter::act(IReq::get('end_time')); $queryObject = CountSum::getSellerGoodsFeeQuery($seller_id, $start_time, $end_time, 0); $countData = CountSum::countSellerOrderFee($queryObject->find()); if ($countData['orderAmountPrice'] > 0) { $replaceData = array('{startTime}' => $start_time, '{endTime}' => $end_time, '{goodsNums}' => count($countData['order_goods_ids']), '{goodsSums}' => $countData['goodsSum'], '{deliveryPrice}' => $countData['deliveryPrice'], '{protectedPrice}' => $countData['insuredPrice'], '{taxPrice}' => $countData['taxPrice'], '{totalSum}' => $countData['orderAmountPrice']); $billString = AccountLog::sellerBillTemplate($replaceData); $result = array('result' => 'success', 'data' => $billString); } else { $result = array('result' => 'fail', 'data' => '当前没有任何款项可以结算'); } die(JSON::encode($result)); }
<a class="normal f12" href="javascript:void(0)" id='paymentToggleButton' onclick="orderFormInstance.paymentModToggle();">[关闭]</a> </h3> <table width="100%" class="border_table" id='payment_form'> <colgroup> <col width="200px" /> <col /> </colgroup> <?php $paymentList = $this->paymentList; ?> <?php foreach ($paymentList as $key => $item) { ?> <?php $paymentPrice = CountSum::getGoodsPaymentPrice($item['id'], $this->sum); ?> <tr> <th><label><input class="radio" name="payment" alt="<?php echo isset($paymentPrice) ? $paymentPrice : ""; ?> " onclick='orderFormInstance.paymentSelected(<?php echo JSON::encode($item); ?> );' title="<?php echo isset($item['name']) ? $item['name'] : ""; ?> " type="radio" value="<?php echo isset($item['id']) ? $item['id'] : ""; ?> " /><?php
/** * @brief 计算商户货款及其他费用 * @param array $orderGoodsList 订单商品关联 * @return array('goodsSum' => 商品总额,'deliveryPrice' => 运费, 'insuredPrice' => 保价, 'taxPrice' => 税金 ,'orderAmountPrice' => 统计总价,'order_goods_ids' => 关联表IDS) */ public static function countSellerOrderFee($orderGoodsList) { $result = array('goodsSum' => 0, 'deliveryPrice' => 0, 'insuredPrice' => 0, 'taxPrice' => 0, 'orderAmountPrice' => 0, 'order_goods_ids' => array()); if ($orderGoodsList && is_array($orderGoodsList)) { foreach ($orderGoodsList as $key => $item) { $goodsSum = $item['goods_price'] * $item['goods_nums']; $orderWeight = $item['goods_weight'] * $item['goods_nums']; $orderCount = CountSum::countOrderFee($goodsSum, $goodsSum, $orderWeight, $item['province'], $item['distribution'], 0, false, $item['if_insured'], $item['invoice']); $result['goodsSum'] += $goodsSum; $result['deliveryPrice'] += $orderCount['deliveryPrice']; $result['insuredPrice'] += $orderCount['insuredPrice']; $result['taxPrice'] += $orderCount['taxPrice']; $result['orderAmountPrice'] += $orderCount['orderAmountPrice']; $result['order_goods_ids'][] = $item['id']; } } return $result; }
/** * @brief 保存修改订单 */ public function order_update() { //获取必要数据 $order_id = IReq::get('id'); //生成order数据 $dataArray['invoice_title'] = IFilter::act(IReq::get('invoice_title')); $dataArray['invoice'] = IFilter::act(IReq::get('invoice'), 'int'); $dataArray['insured'] = IFilter::act(IReq::get('insured'), 'float'); $dataArray['if_insured'] = IFilter::act(IReq::get('if_insured'), 'int'); $dataArray['pay_type'] = IFilter::act(IReq::get('pay_type'), 'int'); $dataArray['accept_name'] = IFilter::act(IReq::get('accept_name')); $dataArray['postcode'] = IFilter::act(IReq::get('postcode')); $dataArray['telphone'] = IFilter::act(IReq::get('telphone')); $dataArray['province'] = IFilter::act(IReq::get('province'), 'int'); $dataArray['city'] = IFilter::act(IReq::get('city'), 'int'); $dataArray['area'] = IFilter::act(IReq::get('area'), 'int'); $dataArray['address'] = IFilter::act(IReq::get('address')); $dataArray['mobile'] = IFilter::act(IReq::get('mobile')); $dataArray['discount'] = IFilter::act(IReq::get('discount'), 'float'); $dataArray['postscript'] = IFilter::act(IReq::get('postscript')); $dataArray['distribution'] = IFilter::act(IReq::get('distribution'), 'int'); $dataArray['accept_time'] = IFilter::act(IReq::get('accept_time')); $goods_id = IFilter::act(IReq::get('goods_id')); $product_id = IFilter::act(IReq::get('product_id')); $goods_nuns = IFilter::act(IReq::get('goods_nums')); //设置订单持有者 $username = IFilter::act(IReq::get('username')); $userDB = new IModel('user'); $userRow = $userDB->getObj('username = "******"'); $dataArray['user_id'] = isset($userRow['id']) ? $userRow['id'] : 0; //拼接要购买的商品或货品数据,组装成固有的数据结构便于计算价格 $length = count($product_id); $buyInfo = array('goods' => array('id' => array(), 'data' => array()), 'product' => array('id' => array(), 'data' => array())); for ($i = 0; $i < $length; $i++) { //货品数据 if (intval($product_id[$i]) > 0) { $buyInfo['product']['id'][] = $product_id[$i]; $buyInfo['product']['data'][$product_id[$i]] = array('count' => $goods_nuns[$i]); } else { $buyInfo['goods']['id'][] = $goods_id[$i]; $buyInfo['goods']['data'][$goods_id[$i]] = array('count' => $goods_nuns[$i]); } } //开始算账 $countSumObj = new CountSum(); $goodsResult = $countSumObj->goodsCount($buyInfo); $orderFee = $countSumObj->countOrderFee($goodsResult['sum'], $goodsResult['final_sum'], $goodsResult['weight'], $dataArray['province'], $dataArray['distribution'], $dataArray['pay_type'], $goodsResult['freeFreight'], $dataArray['if_insured'], $dataArray['invoice'], $dataArray['discount']); //获取原价的运费 $dataArray['payable_freight'] = $orderFee['deliveryOrigPrice']; $dataArray['payable_amount'] = $goodsResult['sum']; $dataArray['real_amount'] = $goodsResult['final_sum']; $dataArray['real_freight'] = $orderFee['deliveryPrice']; $dataArray['insured'] = $orderFee['insuredPrice']; $dataArray['pay_fee'] = $orderFee['paymentPrice']; $dataArray['taxes'] = $orderFee['taxPrice']; $dataArray['promotions'] = $goodsResult['proReduce'] + $goodsResult['reduce']; $dataArray['order_amount'] = $orderFee['orderAmountPrice']; $dataArray['exp'] = $goodsResult['exp']; $dataArray['point'] = $goodsResult['point']; //生成订单 $orderDB = new IModel('order'); //修改操作 if ($order_id) { $orderDB->setData($dataArray); $orderDB->update('id = ' . $order_id); //获取订单信息 $orderRow = $orderDB->getObj('id = ' . $order_id); //记录日志信息 $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "修改了订单信息", '订单号:' . $orderRow['order_no'])); } else { $dataArray['create_time'] = date('Y-m-d H:i:s'); $dataArray['order_no'] = Order_Class::createOrderNum(); $orderDB->setData($dataArray); $order_id = $orderDB->add(); //记录日志信息 $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "添加了订单信息", '订单号:' . $dataArray['order_no'])); } //同步order_goods表 $orderInstance = new Order_Class(); $orderInstance->insertOrderGoods($order_id, $goodsResult); $this->redirect('order_list'); }
/** * 生成订单 */ 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 = 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'); $taxes = IFilter::act(IReq::get('taxes'), 'float'); $insured = IFilter::act(IReq::get('insured'), 'float'); $tax_title = IFilter::act(IReq::get('tax_title'), 'text'); $gid = IFilter::act(IReq::get('direct_gid'), 'int'); $num = IFilter::act(IReq::get('direct_num'), 'int'); $type = IFilter::act(IReq::get('direct_type')); //商品或者货品 $promo = IFilter::act(IReq::get('direct_promo')); $active_id = IFilter::act(IReq::get('direct_active_id'), 'int'); $takeself = IFilter::act(IReq::get('takeself'), 'int'); $order_no = Order_Class::createOrderNum(); $order_type = 0; $dataArray = array(); //pr($_POST); //防止表单重复提交 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']; //配送方式,判断是否为货到付款 $deliveryObj = new IModel('delivery'); $deliveryRow = $deliveryObj->getObj('id = ' . $delivery_id); if ($deliveryRow['type'] == 0) { if ($payment == 0) { IError::show(403, '请选择正确的支付方式'); } } else { if ($deliveryRow['type'] == 1) { $payment = 0; } else { if ($deliveryRow['type'] == 2) { if ($takeself == 0) { IError::show(403, '请选择正确的自提点'); } } } } //如果不是自提方式自动清空自提点 if ($deliveryRow['type'] != 2) { $takeself = 0; } //计算费用 $countSumObj = new CountSum($user_id); //直接购买商品方式 if ($type && $gid) { //计算$gid商品 $goodsResult = $countSumObj->direct_count($gid, $type, $num, $promo, $active_id); } else { //计算购物车中的商品价格$goodsResult $goodsResult = $countSumObj->cart_count(); //清空购物车 IInterceptor::reg("cart@onFinishAction"); } //判断商品商品是否存在 if (is_string($goodsResult) || empty($goodsResult['goodsList'])) { IError::show(403, '商品数据错误'); exit; } //需要选择的地址数 $need_choose_addr_num = 1; if (count($goodsResult['goodsList']) == 1 && $goodsResult['count'] > 1) { $need_choose_addr_num = $goodsResult['count']; } //匹配收获地址 $address_arr = IFilter::act(IReq::get('radio_address'), 'int'); if (count($address_arr) != $need_choose_addr_num) { IError::show(403, '请选择' . $need_choose_addr_num . '个收货地址'); exit; } //加入促销活动 if ($promo && $active_id) { $activeObject = new Active($promo, $active_id, $user_id, $gid, $type, $num); $order_type = $activeObject->getOrderType(); } //获取红包减免金额 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)) { $dataArray['prop'] = $ticket_id; } //锁定红包状态 $propObj->setData(array('is_close' => 2)); $propObj->update('id = ' . $ticket_id); } } $paymentObj = new IModel('payment'); $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,name'); $paymentName = $paymentRow['name']; $paymentType = $paymentRow['type']; //记录seller_id $seller_id = 0; if ($gid) { $goodsObj = new IModel("goods"); $sell = $goodsObj->getObj("id = " . $gid, 'seller_id'); if ($sell['seller_id'] > 0) { $seller_id = $sell['seller_id']; } } //最终订单金额计算 $orderData = $countSumObj->countOrderFee($goodsResult['sum'], $goodsResult['final_sum'], $goodsResult['weight'], $province, $delivery_id, $payment, $goodsResult['freeFreight'], $insured, $taxes); //生成的订单数据 $dataArray = array('order_no' => $order_no, 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'postscript' => $order_message, 'accept_time' => $accept_time, 'exp' => $goodsResult['exp'], 'point' => $goodsResult['point'], 'type' => $order_type, 'prop' => isset($dataArray['prop']) ? $dataArray['prop'] : null, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $orderData['deliveryOrigPrice'], 'real_freight' => $orderData['deliveryPrice'], 'pay_fee' => $orderData['paymentPrice'], 'invoice' => $taxes ? 1 : 0, 'invoice_title' => $tax_title, 'taxes' => $taxes, 'promotions' => $goodsResult['proReduce'] + $goodsResult['reduce'] + (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'order_amount' => $orderData['orderAmountPrice'] - (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'if_insured' => $insured ? 1 : 0, 'insured' => $insured, 'takeself' => $takeself, 'active_id' => $active_id, 'seller_id' => $seller_id, 'address_id' => implode(',', $address_arr)); $dataArray['order_amount'] = $dataArray['order_amount'] <= 0 ? 0 : $dataArray['order_amount']; if ($seller_id) { $sellerObj = new IModel('seller'); $seller = $sellerObj->getObj("id = '{$seller_id}'"); if ($seller) { //商家的预存款不足以扣除订单总价的1.2% $nedd = floatval($dataArray['order_amount'] * (1.2 * 0.01)); if ($seller['balance'] <= 0 || $seller['balance'] < $nedd) { IError::show(403, '商家预存款不足,不能进行购买'); exit; } } } $orderObj = new IModel('order'); $orderObj->setData($dataArray); $this->order_id = $orderObj->add(); if ($this->order_id == false) { IError::show(403, '订单生成错误'); } /*将订单中的商品插入到order_goods表*/ $orderInstance = new Order_Class(); $orderInstance->insertOrderGoods($this->order_id, $goodsResult); //记录用户默认习惯的数据 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, 'takeself' => $takeself))); $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 = $paymentName; $this->paymentType = $paymentType; $this->delivery = $deliveryRow['name']; $this->tax_title = $tax_title; $this->deliveryType = $deliveryRow['type']; //订单金额为0时,订单自动完成 if ($this->final_sum <= 0) { $order_id = Order_Class::updateOrderStatus($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->setRenderData($dataArray); $this->redirect('cart3'); } }
/** * @brief 保存修改订单 */ public function order_update() { //获取必要数据 $order_id = IFilter::act(IReq::get('id'), 'int'); //生成order数据 $dataArray['invoice_title'] = IFilter::act(IReq::get('invoice_title')); $dataArray['invoice'] = IFilter::act(IReq::get('invoice'), 'int'); $dataArray['pay_type'] = IFilter::act(IReq::get('pay_type'), 'int'); $dataArray['accept_name'] = IFilter::act(IReq::get('accept_name')); $dataArray['postcode'] = IFilter::act(IReq::get('postcode')); $dataArray['telphone'] = IFilter::act(IReq::get('telphone')); $dataArray['province'] = IFilter::act(IReq::get('province'), 'int'); $dataArray['city'] = IFilter::act(IReq::get('city'), 'int'); $dataArray['area'] = IFilter::act(IReq::get('area'), 'int'); $dataArray['address'] = IFilter::act(IReq::get('address')); $dataArray['mobile'] = IFilter::act(IReq::get('mobile')); $dataArray['discount'] = $order_id ? IFilter::act(IReq::get('discount'), 'float') : 0; $dataArray['postscript'] = IFilter::act(IReq::get('postscript')); $dataArray['distribution'] = IFilter::act(IReq::get('distribution'), 'int'); $dataArray['accept_time'] = IFilter::act(IReq::get('accept_time')); $dataArray['takeself'] = IFilter::act(IReq::get('takeself')); //设置订单持有者 $username = IFilter::act(IReq::get('username')); $userDB = new IModel('user'); $userRow = $userDB->getObj('username = "******"'); $dataArray['user_id'] = isset($userRow['id']) ? $userRow['id'] : 0; //拼接要购买的商品或货品数据,组装成固有的数据结构便于计算价格 $goodsId = IFilter::act(IReq::get('goods_id')); $productId = IFilter::act(IReq::get('product_id')); $num = IFilter::act(IReq::get('goods_nums')); $goodsArray = array(); $productArray = array(); foreach ($goodsId as $key => $goods_id) { $pid = $productId[$key]; $nVal = $num[$key]; if ($pid > 0) { $productArray[$pid] = $nVal; } else { $goodsArray[$goods_id] = $nVal; } } //开始算账 $countSumObj = new CountSum($dataArray['user_id']); $cartObj = new Cart(); $goodsResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray))); $orderData = $countSumObj->countOrderFee($goodsResult, $dataArray['province'], $dataArray['distribution'], $dataArray['pay_type'], $dataArray['invoice'], $dataArray['discount']); if (is_string($orderData)) { IError::show(403, $orderData); exit; } //根据商品所属商家不同批量生成订单 foreach ($orderData as $seller_id => $goodsResult) { //获取原价的运费 $dataArray['payable_freight'] = $goodsResult['deliveryOrigPrice']; $dataArray['payable_amount'] = $goodsResult['sum']; $dataArray['real_amount'] = $goodsResult['final_sum']; $dataArray['real_freight'] = $goodsResult['deliveryPrice']; $dataArray['insured'] = $goodsResult['insuredPrice']; $dataArray['pay_fee'] = $goodsResult['paymentPrice']; $dataArray['taxes'] = $goodsResult['taxPrice']; $dataArray['promotions'] = $goodsResult['proReduce'] + $goodsResult['reduce']; $dataArray['order_amount'] = $goodsResult['orderAmountPrice']; $dataArray['exp'] = $goodsResult['exp']; $dataArray['point'] = $goodsResult['point']; //商家ID $dataArray['seller_id'] = $seller_id; //生成订单 $orderDB = new IModel('order'); //修改操作 if ($order_id) { //获取订单信息 $orderRow = $orderDB->getObj('id = ' . $order_id); //修改订单不能加入其他商家产品 if (count($orderData) != 1 || $orderRow['seller_id'] != $seller_id) { IError::show(403, "此订单中不能混入其他商家的商品"); exit; } $orderDB->setData($dataArray); $orderDB->update('id = ' . $order_id); //记录日志信息 $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "修改了订单信息", '订单号:' . $orderRow['order_no'])); } else { $dataArray['create_time'] = date('Y-m-d H:i:s'); $dataArray['order_no'] = Order_Class::createOrderNum(); $orderDB->setData($dataArray); $order_id = $orderDB->add(); //记录日志信息 $logObj = new log('db'); $logObj->write('operation', array("管理员:" . $this->admin['admin_name'], "添加了订单信息", '订单号:' . $dataArray['order_no'])); } //同步order_goods表 $orderInstance = new Order_Class(); $orderInstance->insertOrderGoods($order_id, $goodsResult['goodsResult']); } $this->redirect('order_list'); }
echo isset($item['goods_nums']) ? $item['goods_nums'] : ""; ?> </td> <td>¥<?php echo $item['real_price'] * $item['goods_nums']; ?> 元</td> </tr> <?php } ?> </tbody> </table> <?php $orderCount = CountSum::countOrderFee($goodsSum, $goodsSum, $orderWeight, $province, $distribution, 0, false, $if_insured, $invoice); ?> <table class="table f14" width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td align="right">商品总价:¥<?php echo isset($goodsSum) ? $goodsSum : ""; ?> 元</td> </tr> <tr> <td align="right">运费价格:¥<?php echo isset($orderCount['deliveryPrice']) ? $orderCount['deliveryPrice'] : ""; ?> 元</td> </tr> <tr>
/** * 生成订单 */ 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 = 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'); $taxes = IFilter::act(IReq::get('taxes'), 'int'); $tax_title = IFilter::act(IReq::get('tax_title')); $gid = IFilter::act(IReq::get('direct_gid'), 'int'); $num = IFilter::act(IReq::get('direct_num'), 'int'); $type = IFilter::act(IReq::get('direct_type')); //商品或者货品 $promo = IFilter::act(IReq::get('direct_promo')); $active_id = IFilter::act(IReq::get('direct_active_id'), 'int'); $takeself = IFilter::act(IReq::get('takeself'), 'int'); $ticketUserd = IFilter::act(IReq::get('ticketUserd'), 'int'); $order_type = 0; $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']; //配送方式,判断是否为货到付款 $deliveryObj = new IModel('delivery'); $deliveryRow = $deliveryObj->getObj('id = ' . $delivery_id); if ($deliveryRow['type'] == 0) { if ($payment == 0) { IError::show(403, '请选择正确的支付方式'); } } else { if ($deliveryRow['type'] == 1) { $payment = 0; } else { if ($deliveryRow['type'] == 2) { if ($takeself == 0) { IError::show(403, '请选择正确的自提点'); } } } } //如果不是自提方式自动清空自提点 if ($deliveryRow['type'] != 2) { $takeself = 0; } //计算费用 $countSumObj = new CountSum($user_id); $goodsResult = $countSumObj->cart_count($gid, $type, $num, $promo, $active_id); if (!$gid) { //清空购物车 IInterceptor::reg("cart@onFinishAction"); } //判断商品商品是否存在 if (is_string($goodsResult) || empty($goodsResult['goodsList'])) { IError::show(403, '商品数据错误'); exit; } //加入促销活动 if ($promo && $active_id) { $activeObject = new Active($promo, $active_id, $user_id, $gid, $type, $num); $order_type = $activeObject->getOrderType(); } $paymentObj = new IModel('payment'); $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,name'); $paymentName = $paymentRow['name']; $paymentType = $paymentRow['type']; //最终订单金额计算 $orderData = $countSumObj->countOrderFee($goodsResult, $province, $delivery_id, $payment, $taxes, 0, $promo, $active_id); if (is_string($orderData)) { IError::show(403, $orderData); exit; } //根据商品所属商家不同批量生成订单 $orderIdArray = array(); $orderNumArray = array(); $final_sum = 0; foreach ($orderData as $seller_id => $goodsResult) { //生成的订单数据 $dataArray = array('order_no' => Order_Class::createOrderNum(), 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'postscript' => $order_message, 'accept_time' => $accept_time, 'exp' => $goodsResult['exp'], 'point' => $goodsResult['point'], 'type' => $order_type, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $goodsResult['deliveryOrigPrice'], 'real_freight' => $goodsResult['deliveryPrice'], 'pay_fee' => $goodsResult['paymentPrice'], 'invoice' => $taxes ? 1 : 0, 'invoice_title' => $tax_title, 'taxes' => $goodsResult['taxPrice'], 'promotions' => $goodsResult['proReduce'] + $goodsResult['reduce'], 'order_amount' => $goodsResult['orderAmountPrice'], 'insured' => $goodsResult['insuredPrice'], 'takeself' => $takeself, 'active_id' => $active_id, 'seller_id' => $seller_id, 'note' => ''); //获取红包减免金额 if ($ticket_id && $ticketUserd == $seller_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 (!$ticketRow) { IError::show(403, '代金券不可用'); } if ($ticketRow['seller_id'] == 0 || $ticketRow['seller_id'] == $seller_id) { $ticketRow['value'] = $ticketRow['value'] >= $goodsResult['final_sum'] ? $goodsResult['final_sum'] : $ticketRow['value']; $dataArray['prop'] = $ticket_id; $dataArray['promotions'] += $ticketRow['value']; $dataArray['order_amount'] -= $ticketRow['value']; $goodsResult['promotion'][] = array("plan" => "代金券", "info" => "使用了¥" . $ticketRow['value'] . "代金券"); //锁定红包状态 $propObj->setData(array('is_close' => 2)); $propObj->update('id = ' . $ticket_id); } } } //促销规则 if (isset($goodsResult['promotion']) && $goodsResult['promotion']) { foreach ($goodsResult['promotion'] as $key => $val) { $dataArray['note'] .= " 【" . $val['info'] . "】 "; } } $dataArray['order_amount'] = $dataArray['order_amount'] <= 0 ? 0 : $dataArray['order_amount']; //生成订单插入order表中 $orderObj = new IModel('order'); $orderObj->setData($dataArray); $order_id = $orderObj->add(); if ($order_id == false) { IError::show(403, '订单生成错误'); } /*将订单中的商品插入到order_goods表*/ $orderInstance = new Order_Class(); $orderInstance->insertOrderGoods($order_id, $goodsResult['goodsResult']); //订单金额小于等于0直接免单 if ($dataArray['order_amount'] <= 0) { Order_Class::updateOrderStatus($dataArray['order_no']); } else { $orderIdArray[] = $order_id; $orderNumArray[] = $dataArray['order_no']; $final_sum += $dataArray['order_amount']; } } //记录用户默认习惯的数据 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, 'takeself' => $takeself))); $memberObj->setData($memberData); $memberObj->update('user_id = ' . $user_id); //收货地址的处理 if ($user_id) { $addressObj = new IModel('address'); $addressDefRow = $addressObj->getObj('user_id = ' . $user_id . ' and `default` = 1'); if (!$addressDefRow) { $radio_address = IFilter::act(IReq::get('radio_address'), 'int'); $addressObj->setData(array('default' => 1)); $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_id = join(",", $orderIdArray); $this->final_sum = $final_sum; $this->order_num = join(",", $orderNumArray); $this->payment = $paymentName; $this->paymentType = $paymentType; $this->delivery = $deliveryRow['name']; $this->tax_title = $tax_title; $this->deliveryType = $deliveryRow['type']; //订单金额为0时,订单自动完成 if ($this->final_sum <= 0) { $this->redirect('/site/success/message/' . urlencode("订单确认成功,等待发货") . '/?callback=ucenter/order'); } else { $this->setRenderData($dataArray); $this->redirect('cart3'); } }
/** * 生成订单 */ 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 = 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'); $taxes = IFilter::act(IReq::get('taxes'), 'float'); $insured = IFilter::act(IReq::get('insured'), 'float'); $tax_title = IFilter::act(IReq::get('tax_title'), 'text'); $gid = IFilter::act(IReq::get('direct_gid'), 'int'); $num = IFilter::act(IReq::get('direct_num'), 'int'); $type = IFilter::act(IReq::get('direct_type')); //商品或者货品 $promo = IFilter::act(IReq::get('direct_promo')); $active_id = IFilter::act(IReq::get('direct_active_id'), 'int'); $order_no = Order_Class::createOrderNum(); $order_type = 0; $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); 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; } //获取红包减免金额 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)) { $dataArray['prop'] = $ticket_id; } //锁定红包状态 $propObj->setData(array('is_close' => 2)); $propObj->update('id = ' . $ticket_id); } } //货到付款的方式 if ($payment == 0) { $paymentName = '货到付款'; $paymentType = 0; } else { $paymentObj = new IModel('payment'); $paymentRow = $paymentObj->getObj('id = ' . $payment, 'type,name'); $paymentName = $paymentRow['name']; $paymentType = $paymentRow['type']; } //最终订单金额计算 $orderData = $countSumObj->countOrderFee($goodsResult['sum'], $goodsResult['final_sum'], $goodsResult['weight'], $province, $delivery_id, $payment, $goodsResult['freeFreight'], $insured, $taxes); //生成的订单数据 $dataArray = array('order_no' => $order_no, 'user_id' => $user_id, 'accept_name' => $accept_name, 'pay_type' => $payment, 'distribution' => $delivery_id, 'postcode' => $zip, 'telphone' => $telphone, 'province' => $province, 'city' => $city, 'area' => $area, 'address' => $address, 'mobile' => $mobile, 'create_time' => ITime::getDateTime(), 'postscript' => $order_message, 'accept_time' => $accept_time, 'exp' => $goodsResult['exp'], 'point' => $goodsResult['point'], 'type' => $order_type, 'prop' => isset($dataArray['prop']) ? $dataArray['prop'] : null, 'payable_amount' => $goodsResult['sum'], 'real_amount' => $goodsResult['final_sum'], 'payable_freight' => $orderData['deliveryOrigPrice'], 'real_freight' => $orderData['deliveryPrice'], 'pay_fee' => $orderData['paymentPrice'], 'invoice' => $taxes ? 1 : 0, 'invoice_title' => $tax_title, 'taxes' => $taxes, 'promotions' => $goodsResult['proReduce'] + $goodsResult['reduce'] + (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'order_amount' => $orderData['orderAmountPrice'] - (isset($ticketRow['value']) ? $ticketRow['value'] : 0), 'if_insured' => $insured ? 1 : 0, 'insured' => $insured); $dataArray['order_amount'] = $dataArray['order_amount'] <= 0 ? 0 : $dataArray['order_amount']; $orderObj = new IModel('order'); $orderObj->setData($dataArray); $this->order_id = $orderObj->add(); if ($this->order_id == false) { IError::show(403, '订单生成错误'); } /*将订单中的商品插入到order_goods表*/ $orderInstance = new Order_Class(); $orderInstance->insertOrderGoods($this->order_id, $goodsResult); //记录用户默认习惯的数据 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 = $paymentName; $this->paymentType = $paymentType; $this->delivery = $deliveryRow['name']; $this->tax_title = $tax_title; $this->deliveryType = $deliveryRow['type']; //订单金额为0时,订单自动完成 if ($this->final_sum <= 0) { $order_id = Order_Class::updateOrderStatus($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->setRenderData($dataArray); $this->redirect('cart3'); } }
/** * @brief 配送方式计算管理模块 * @param $province int 省份的ID * @param $delivery_id int 配送方式ID * @param $goods_id array 商品ID * @param $product_id array 货品ID * @param $num array 商品数量 * @return array( * if_delivery => 0:支持配送;1:不支持配送; * price => 运费; * protect_price => 保价; * seller_id => array(price => 运费,protect_price => 保价,org_price => 原始运费) * ) */ public static function getDelivery($province, $delivery_id, $goods_id, $product_id = 0, $num = 1) { //获取默认的配送方式信息 $delivery = new IModel('delivery'); $deliveryDefaultRow = $delivery->getObj('is_delete = 0 and status = 1 and id = ' . $delivery_id); if (!$deliveryDefaultRow) { return "配送方式不存在"; } //最终返回结果 $result = array('name' => $deliveryDefaultRow['name'], 'description' => $deliveryDefaultRow['description'], 'if_delivery' => 0, 'org_price' => 0, 'price' => 0, 'protect_price' => 0); //读取全部商品,array('goodsSum' => 商品总价,'weight' => 商品总重量) $sellerGoods = array(); $goods_id = is_array($goods_id) ? $goods_id : array($goods_id); $product_id = is_array($product_id) ? $product_id : array($product_id); $num = is_array($num) ? $num : array($num); $goodsArray = array(); $productArray = array(); foreach ($goods_id as $key => $gid) { $pid = $product_id[$key]; $gnum = $num[$key]; if ($pid > 0) { $productArray[$pid] = $gnum; $goodsRow = Api::run("getProductInfo", array('#id#', $pid)); if (!$goodsRow) { throw new IException("计算商品运费货品ID【" . $pid . "】信息不存在"); } } else { $goodsArray[$gid] = $gnum; $goodsRow = Api::run("getGoodsInfo", array('#id#', $gid)); if (!$goodsRow) { throw new IException("计算商品运费商品ID【" . $gid . "】信息不存在"); } } if (!isset($sellerGoods[$goodsRow['seller_id']])) { $sellerGoods[$goodsRow['seller_id']] = array('goodsSum' => 0, 'weight' => 0); } $sellerGoods[$goodsRow['seller_id']]['weight'] += $goodsRow['weight'] * $gnum; $sellerGoods[$goodsRow['seller_id']]['goodsSum'] += $goodsRow['sell_price'] * $gnum; } //获取促销规则是否免运费 $countSumObj = new CountSum(self::$user_id); $cartObj = new Cart(); $countSumResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray))); //根据商家不同计算运费 $deliveryExtendDB = new IModel('delivery_extend'); foreach ($sellerGoods as $seller_id => $data) { $weight = $data['weight']; //计算运费 $goodsSum = $data['goodsSum']; //计算保价 //使用商家配置的物流运费 $deliverySellerRow = $deliveryExtendDB->getObj('delivery_id = ' . $delivery_id . ' and seller_id = ' . $seller_id); $deliveryRow = $deliverySellerRow ? $deliverySellerRow : $deliveryDefaultRow; //设置首重和次重 self::$firstWeight = $deliveryRow['first_weight']; self::$secondWeight = $deliveryRow['second_weight']; $deliveryRow['if_delivery'] = '0'; //当配送方式是统一配置的时候,不进行区分地区价格 if ($deliveryRow['price_type'] == 0) { $deliveryRow['price'] = self::getFeeByWeight($weight, $deliveryRow['first_price'], $deliveryRow['second_price']); } else { $matchKey = ''; $flag = false; //每项都是以';'隔开的省份ID $area_groupid = unserialize($deliveryRow['area_groupid']); foreach ($area_groupid as $key => $item) { //匹配到了特殊的省份运费价格 if (strpos($item, ';' . $province . ';') !== false) { $matchKey = $key; $flag = true; break; } } //匹配到了特殊的省份运费价格 if ($flag) { //获取当前省份特殊的运费价格 $firstprice = unserialize($deliveryRow['firstprice']); $secondprice = unserialize($deliveryRow['secondprice']); $deliveryRow['price'] = self::getFeeByWeight($weight, $firstprice[$matchKey], $secondprice[$matchKey]); } else { //判断是否设置默认费用了 if ($deliveryRow['open_default'] == 1) { $deliveryRow['price'] = self::getFeeByWeight($weight, $deliveryRow['first_price'], $deliveryRow['second_price']); } else { $deliveryRow['price'] = '0'; $deliveryRow['if_delivery'] = '1'; } } } $deliveryRow['org_price'] = $deliveryRow['price']; //促销规则满足免运费 if (isset($countSumResult['freeFreight']) && in_array($seller_id, $countSumResult['freeFreight'])) { $deliveryRow['price'] = 0; } //计算保价 if ($deliveryRow['is_save_price'] == 1) { $tempProtectPrice = $goodsSum * ($deliveryRow['save_rate'] * 0.01); $deliveryRow['protect_price'] = $tempProtectPrice <= $deliveryRow['low_price'] ? $deliveryRow['low_price'] : $tempProtectPrice; } else { $deliveryRow['protect_price'] = 0; } //无法送达 if ($deliveryRow['if_delivery'] == 1) { return $deliveryRow; } //更新最终数据 $result['org_price'] += $deliveryRow['org_price']; $result['price'] += $deliveryRow['price']; $result['protect_price'] += $deliveryRow['protect_price']; } return $result; }
public function countGoodsFee() { $seller_id = $this->seller['seller_id']; $start_time = IFilter::act(IReq::get('start_time')); $end_time = IFilter::act(IReq::get('end_time')); $queryObject = CountSum::getSellerGoodsFeeQuery($seller_id, $start_time, $end_time, 0); $countData = CountSum::countSellerOrderFee($queryObject->find()); if ($countData['countFee'] > 0) { $countData['start_time'] = $start_time; $countData['end_time'] = $end_time; $billString = AccountLog::sellerBillTemplate($countData); $result = array('result' => 'success', 'data' => $billString); } else { $result = array('result' => 'fail', 'data' => '当前没有任何款项可以结算'); } die(JSON::encode($result)); }
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'); } }