/** * 选择配送方式的接口 * @params object 控制器入口 * @params string 最后一级地区的id * @params array 标准购物车数据 */ public function select_delivery_method(&$controller, $area_id = '', $sdf_cart) { //$dly_types = &$controller->app->model('dlytype'); //$all_dly_types = $dly_types->get_dlytype($area_id); $all_dly_types = $this->get_dlytype($controller, $area_id); foreach ($all_dly_types as $rows) { $rows['money'] = utils::cal_fee($rows['dt_expressions'], $sdf_cart['subtotal_weight'], $sdf_cart['subtotal'], $rows['firstprice']); $shipping[] = $rows; } $controller->pagedata['shippings'] =& $shipping; return $controller->fetch("site/cart/checkout_shipping.html"); }
public function get_special_delivery(&$controller, $area_id = 0, $sdf_cart, $shipping_id = 0) { $objdlytype = $controller->app->model('dlytype'); $dlytype = $objdlytype->getList('*', array('dt_id' => $shipping_id, 'dt_status' => '1'), 0, -1, 'ordernum ASC'); $cost_item = $sdf_cart['subtotal']; if ($dlytype) { $rows = $dlytype[0]; if ($rows['is_threshold']) { if ($rows['threshold']) { $rows['threshold'] = unserialize(stripslashes($rows['threshold'])); if (isset($rows['threshold']) && $rows['threshold']) { foreach ($rows['threshold'] as $res) { if ($res['area'][1] > 0) { if ($cost_item >= $res['area'][0] && $cost_item < $res['area'][1]) { $rows['firstprice'] = $res['first_price']; $rows['continueprice'] = $res['continue_price']; } } else { if ($cost_item >= $res['area'][0]) { $rows['firstprice'] = $res['first_price']; $rows['continueprice'] = $res['continue_price']; } } } } } } if ($rows['area_fee_conf']) { $area_fee_conf = unserialize($rows['area_fee_conf']); if ($area_fee_conf && is_array($area_fee_conf) && !$rows['setting']) { foreach ($area_fee_conf as $k => $v) { $areas = explode(',', $v['areaGroupId']); // 再次解析字符 foreach ($areas as &$strArea) { if (strpos($strArea, '|') !== false) { $strArea = substr($strArea, 0, strpos($strArea, '|')); // 取当前area id对应的最上级的区域id $objRegions = app::get('ectools')->model('regions'); $tmp = $objRegions->getList('*', array('region_id' => $area_id)); $arrRegion = $tmp[0]; while ($row = $objRegions->getRegionByParentId($arrRegion['p_region_id'])) { $arrRegion = $row; $tmp_area_id = $row['region_id']; if ($tmp_area_id == $strArea) { $area_id = $tmp_area_id; break; } } } } if (in_array($area_id, $areas)) { //如果地区在其中,优先使用地区设置的配送费用,及公式 $rows['firstprice'] = $v['firstprice']; $rows['continueprice'] = $v['continueprice']; $rows['dt_expressions'] = $v['dt_expressions']; break; } } } } if (isset($sdf_cart['is_free_shipping']) && $sdf_cart['is_free_shipping']) { $rows['money'] = 0; } else { $rows['money'] = @utils::cal_fee($rows['dt_expressions'], $sdf_cart['subtotal_weight'], $cost_item, $rows['firstprice'], $rows['continueprice'], $rows['firstprice']); } $shipping = $rows; $controller->pagedata['shipping'] =& $shipping; $str_html = $controller->fetch("site/cart/checkout_shipping_info.html"); $obj_ajax_view_help = kernel::single('b2c_view_ajax'); return $obj_ajax_view_help->get_html($str_html, 'b2c_order_dlytype', 'get_special_delivery'); } }
/** * 生成订单总计详细 * @params object 控制器 * @params object cart objects * @params array sdf array */ public function payment_detail(&$controller, $cart, $sdf_order) { $objMath = kernel::single('ectools_math'); //$cart_info = $cart->get_objects(true); $cart_info = $cart; $cost_item = $cart_info['subtotal']; //购物车里商品总费用 $cost_item = $objMath->number_minus(array($cost_item, $cart_info['discount_amount_prefilter'])); $items_weight = $cart_info['subtotal_weight']; //购物车里商品总重量 if (isset($cart_info['is_free_shipping']) && $cart_info['is_free_shipping']) { $items_weight = 0; } else { if ($cart_info['object']['goods']) { foreach ($cart_info['object']['goods'] as $item_obj) { if (isset($item_obj['is_free_shipping']) && $item_obj['is_free_shipping']) { if (isset($item_obj['obj_items']['products'][0]) && $item_obj['obj_items']['products'][0]) { $product_item = $item_obj['obj_items']['products'][0]; if ($product_item['package_use']) { $items_weight_added = $objMath->number_multiple(array($product_item['package_unit'], $item_obj['quantity'], $product_item['weight'])); } else { $items_weight_added = $objMath->number_multiple(array($product_item['weight'], $item_obj['quantity'])); } $items_weight = $objMath->number_minus(array($items_weight, $items_weight_added)); } } } } } $objCurrency = app::get('ectools')->model('currency'); $arrDefCurrency = $objCurrency->getDefault(); $strDefCurrency = $arrDefCurrency['cur_code']; $aCur = $objCurrency->getcur($sdf_order['cur']); if ($sdf_order['shipping_id']) { $dlytype = $controller->app->model('dlytype'); //配送方式 $dlytype_info = $dlytype->dump($sdf_order['shipping_id'], '*'); if ($sdf_order['is_protect'] === 'true' || $sdf_order['is_protect'] === '1' || $sdf_order['is_protect'] === true) { //配送设置了保价 //$cost_protect = ($cost_item*$dlytype_info['protect_rate']); $cost_protect = $objMath->number_multiple(array($cost_item, $dlytype_info['protect_rate'])); $cost_protect = $cost_protect > $dlytype_info['minprice'] ? $cost_protect : $dlytype_info['minprice']; //保价费 } if (!$dlytype_info['setting']) { $arrArea = explode(':', $sdf_order['area']); $area_id = $arrArea[2]; if (isset($dlytype_info['area_fee_conf']) && $dlytype_info['area_fee_conf']) { $area_fee_conf = unserialize($dlytype_info['area_fee_conf']); foreach ($area_fee_conf as $k => $v) { $areas = explode(',', $v['areaGroupId']); // 再次解析字符 foreach ($areas as &$strArea) { if (strpos($strArea, '|') !== false) { $strArea = substr($strArea, 0, strpos($strArea, '|')); } } // 取当前area id对应的最上级的区域id $objRegions = app::get('ectools')->model('regions'); $arrRegion = $objRegions->dump($area_id); while ($row = $objRegions->getRegionByParentId($arrRegion['p_region_id'])) { $arrRegion = $row; $area_id = $row['region_id']; } if (in_array($area_id, $areas)) { //如果地区在其中,优先使用地区设置的配送费用,及公式 $dlytype_info['firstprice'] = $v['firstprice']; $dlytype_info['continueprice'] = $v['continueprice']; $dlytype_info['dt_expressions'] = $v['dt_expressions']; break; } } } } $cost_freight = utils::cal_fee($dlytype_info['dt_expressions'], $items_weight, $cost_item); //配送费 } if (isset($cart_info['is_free_shipping']) && $cart_info['is_free_shipping']) { $cost_freight = 0; $cost_protect = 0; } if ($sdf_order['payment'] && $sdf_order['payment'] != -1) { $payment_info = app::get('ectools')->model('payment_cfgs')->getPaymentInfo($sdf_order['payment']); $pay_fee = $payment_info['pay_fee']; //支付费率 } else { $pay_fee = 0; } if ($sdf_order['is_tax'] == 'true') { $cost_tax = $objMath->number_multiple(array($controller->app->getConf("site.tax_ratio"), $cost_item)); } $total_amount = $objMath->number_plus(array($cost_item, $cost_protect, $cost_freight)); $cost_payment = $objMath->number_multiple(array($total_amount, $pay_fee)); $total_amount = $objCurrency->amount_nocur($objMath->number_plus(array($total_amount, $cost_payment, $cost_tax)), $sdf_order['cur'], false, false); $total_amount = $objMath->number_minus(array($total_amount, $cart_info['discount_amount_order'])); $demical = $controller->app->getConf('system.money.operation.decimals'); $odr_decimals = $controller->app->getConf('system.money.decimals'); $system_money_operation_carryset = $controller->app->getConf('system.money.operation.carryset'); $total_amount_odr = $objMath->get($total_amount, $odr_decimals); $order_discount = $objMath->number_minus(array($total_amount, $total_amount_odr)); if ($total_amount < 0) { $total_amount = 0; } // 取到商店积分规则 $policy_method = $controller->app->getConf("site.get_policy.method"); switch ($policy_method) { case '1': $subtotal_consume_score = 0; $subtotal_gain_score = 0; $totalScore = 0; break; case '2': $subtotal_consume_score = round($cart_info['subtotal_consume_score']); $policy_rate = $controller->app->getConf('site.get_rate.method'); $subtotal_gain_score = round($objMath->number_multiple(array($total_amount_odr, $policy_rate))); $totalScore = round($objMath->number_minus(array($subtotal_gain_score, $subtotal_consume_score))); break; case '3': $subtotal_consume_score = round($cart_info['subtotal_consume_score']); $subtotal_gain_score = round($cart_info['subtotal_gain_score']); $totalScore = round($objMath->number_minus(array($subtotal_gain_score, $subtotal_consume_score))); break; default: $subtotal_consume_score = 0; $subtotal_gain_score = 0; $totalScore = 0; break; } if ($sdf_order['member_id']) { // 得到当前会员的积分 $obj_members = $controller->app->model('members'); $arr_member = $obj_members->dump($sdf_order['member_id'], 'point'); $member_point = $arr_member['score']['total']; $totalScore = $member_point; } else { $totalScore = 0; } $payment_detail = array('cost_item' => $objCurrency->amount_nocur($cost_item, $sdf_order['cur'], false, false), 'cost_protect' => $objCurrency->amount_nocur($cost_protect, $sdf_order['cur'], false, false), 'cost_freight' => $objCurrency->amount_nocur($cost_freight, $sdf_order['cur'], false, false), 'cost_payment' => $objCurrency->amount_nocur($cost_payment, $sdf_order['cur'], false, false), 'total_amount' => $total_amount_odr, 'currency' => $sdf_order['cur'], 'pmt_amount' => $cart_info['discount_amount'], 'cost_tax' => $cost_tax, 'trigger_tax' => $sdf_order['is_tax'], 'discount' => $order_discount, 'cur_code' => $strDefCurrency, 'cur_display' => $sdf_order['cur'], 'cur_rate' => $aCur['cur_rate'], 'final_amount' => $objCurrency->changer_odr($total_amount, $sdf_order['cur'], true, false, $odr_decimals, $system_money_operation_carryset), 'tax_company' => $sdf_order['tax_company'], 'totalConsumeScore' => $subtotal_consume_score, 'totalGainScore' => $subtotal_gain_score, 'totalScore' => $totalScore); //print_r($payment_detail);exit; return $payment_detail; }
/** * 生成订单总计详细 * @params object 控制器 * @params object cart objects * @params array sdf array */ public function payment_detail(&$controller, $cart, $sdf_order) { $objMath = kernel::single('ectools_math'); $cart_info = $cart; $cost_item = $cart_info['subtotal']; //购物车里商品总费用 $items_weight = $cart_info['subtotal_weight']; //购物车里商品总重量 if (!isset($cart_info['is_free_shipping']) || !$cart_info['is_free_shipping']) { if ($cart_info['object']['goods']) { foreach ($cart_info['object']['goods'] as $item_obj) { if (isset($item_obj['is_free_shipping']) && $item_obj['is_free_shipping']) { $cart_info['is_free_shipping'] = true; break; } } } } $objCurrency = app::get('ectools')->model('currency'); $arrDefCurrency = $objCurrency->getDefault(); $strDefCurrency = $arrDefCurrency['cur_code']; $aCur = $objCurrency->getcur($sdf_order['cur']); if ($sdf_order['shipping_id']) { $dlytype = $controller->app->model('dlytype'); //配送方式 $dlytype_info = $dlytype->dump($sdf_order['shipping_id'], '*'); if ($sdf_order['is_protect'] === 'true' || $sdf_order['is_protect'] === '1' || $sdf_order['is_protect'] === true) { //配送设置了保价 if ($dlytype_info['protect'] == 'true') { /** 保价费界定为商品的最原始价格 **/ $cost_protect = $objMath->number_multiple(array($cost_item, $dlytype_info['protect_rate'])); $cost_protect = $cost_protect > $dlytype_info['minprice'] ? $cost_protect : $dlytype_info['minprice']; //保价费 } } /** 阶梯费用只能根据优惠后的金额来处理 - 除去商品优惠和订单优惠后的最终价格 **/ $subtotal_order_after = $objMath->number_minus(array($cost_item, $cart_info['discount_amount_prefilter'], $cart_info['discount_amount_order'])); if ($dlytype_info['is_threshold']) { if ($dlytype_info['threshold']) { $dlytype_info['threshold'] = unserialize(stripslashes($dlytype_info['threshold'])); if (isset($dlytype_info['threshold']) && $dlytype_info['threshold']) { foreach ($dlytype_info['threshold'] as $res) { if ($res['area'][1] > 0) { if ($subtotal_order_after >= $res['area'][0] && $subtotal_order_after < $res['area'][1]) { $dlytype_info['firstprice'] = $res['first_price']; $dlytype_info['continueprice'] = $res['continue_price']; } } else { if ($subtotal_order_after >= $res['area'][0]) { $dlytype_info['firstprice'] = $res['first_price']; $dlytype_info['continueprice'] = $res['continue_price']; } } } } } } if (!$dlytype_info['setting']) { if ($sdf_order['area_id']) { $area_id = $sdf_order['area_id']; } else { $arrArea = explode(':', $sdf_order['area']); $area_id = $arrArea[2]; } if (isset($dlytype_info['area_fee_conf']) && $dlytype_info['area_fee_conf']) { $area_fee_conf = unserialize($dlytype_info['area_fee_conf']); foreach ($area_fee_conf as $k => $v) { $areas = explode(',', $v['areaGroupId']); // 再次解析字符 foreach ($areas as &$strArea) { if (strpos($strArea, '|') !== false) { $strArea = substr($strArea, 0, strpos($strArea, '|')); // 取当前area id对应的最上级的区域id $objRegions = app::get('ectools')->model('regions'); $arrRegion = $objRegions->dump($area_id); while ($row = $objRegions->getRegionByParentId($arrRegion['p_region_id'])) { $arrRegion = $row; $tmp_area_id = $row['region_id']; if ($tmp_area_id == $strArea) { $area_id = $tmp_area_id; break; } } } } if (in_array($area_id, $areas)) { //如果地区在其中,优先使用地区设置的配送费用,及公式 if ($dlytype_info['firstprice']) { $dlytype_info['firstprice'] = $v['firstprice']; } $dlytype_info['continueprice'] = $v['continueprice']; $dlytype_info['dt_expressions'] = $v['dt_expressions']; break; } } } } $cost_freight = @utils::cal_fee($dlytype_info['dt_expressions'], $items_weight, $cost_item, $dlytype_info['firstprice'], $dlytype_info['continueprice']); //配送费 } /** * 订单免运费 */ if (isset($cart_info['is_free_shipping']) && $cart_info['is_free_shipping']) { $cart_info['discount_amount_order'] = $objMath->number_plus(array($cart_info['discount_amount_order'], $cost_freight, $cost_protect)); $cart_info['discount_amount'] = $objMath->number_plus(array($cart_info['discount_amount'], $cost_freight, $cost_protect)); } /** end **/ if ($sdf_order['payment'] && $sdf_order['payment'] != -1) { $payment_info = app::get('ectools')->model('payment_cfgs')->getPaymentInfo($sdf_order['payment']); $pay_fee = $payment_info['pay_fee']; //支付费率 } else { $pay_fee = 0; } if ($sdf_order['is_tax'] == 'true') { $tax_ratio = $controller->app->getConf("site." . $sdf_order['tax_type'] . "_tax_ratio"); // 税率计算埋点 foreach (kernel::servicelist('b2c.order_ratio_calulate') as $services) { if (is_object($services)) { if (method_exists($services, 'ratioCalculate')) { $services->ratioCalculate($controller, $sdf_order['tax_type'], $tax_ratio); } } } $cost_tax = $objMath->number_multiple(array($tax_ratio, $objMath->number_minus(array($cost_item, $cart_info['discount_amount_prefilter'])))); } $total_amount = $objMath->number_plus(array($cost_item, $cost_protect, $cost_freight)); $total_amount = $objMath->number_minus(array($total_amount, $cart_info['discount_amount'])); $total_amount = $objMath->number_plus(array($total_amount, $cost_tax)); // 积分兑换 $total_point = '0'; $subtotal_consume_score = 0; $obj_point_dis = kernel::service('b2c_cart_point_discount'); $site_point_usage = app::get('b2c')->getConf('site.point_usage'); $over_real_point = 'false'; if ($obj_point_dis && $site_point_usage == '2') { $over_real_point = $obj_point_dis->generate_total($sdf_order, $total_amount, $subtotal_consume_score, $total_point); $total_discount_consume_score = $subtotal_consume_score; } $cost_payment = $objMath->number_multiple(array($total_amount, $pay_fee)); $total_amount = $objCurrency->amount_nocur($objMath->number_plus(array($total_amount, $cost_payment)), $sdf_order['cur'], false, false); $demical = $controller->app->getConf('system.money.operation.decimals'); $odr_decimals = $controller->app->getConf('system.money.decimals'); $system_money_operation_carryset = $controller->app->getConf('system.money.operation.carryset'); $total_amount_odr = $objCurrency->changer_odr($total_amount, $sdf_order['cur'], true, false, $odr_decimals, $system_money_operation_carryset); #$objMath->get($total_amount, $odr_decimals); $order_discount = $objMath->number_minus(array($total_amount, $total_amount_odr)); if ($total_amount < 0) { $total_amount = 0; } if ($total_amount_odr < 0) { $total_amount_odr = 0; } // 取到商店积分规则 $policy_method = $controller->app->getConf("site.get_policy.method"); switch ($policy_method) { case '1': $subtotal_gain_score = 0; $totalScore = 0; break; case '2': $subtotal_consume_score += round($cart_info['subtotal_consume_score']); $policy_rate = $controller->app->getConf('site.get_rate.method'); $subtotal_gain_score = round($cart_info['subtotal_gain_score']); $totalScore = round($objMath->number_minus(array($subtotal_gain_score, $subtotal_consume_score))); break; case '3': $subtotal_consume_score += round($cart_info['subtotal_consume_score']); $subtotal_gain_score = round($cart_info['subtotal_gain_score']); $totalScore = round($objMath->number_minus(array($subtotal_gain_score, $subtotal_consume_score))); break; default: $subtotal_gain_score = 0; $totalScore = 0; break; } if ($sdf_order['member_id']) { // 得到当前会员的积分 $obj_members = $controller->app->model('members'); #$arr_member = $obj_members->dump($sdf_order['member_id'], 'point'); $arr_member = $obj_members->getList('point', array('member_id' => $sdf_order['member_id'])); $arr_member = $arr_member[0]; $member_point = $arr_member['score']['total']; $obj_extend_point = kernel::service('b2c.member_extend_point_info'); if ($obj_extend_point) { // 当前会员实际可以使用的积分 $obj_extend_point->get_usage_point($sdf_order['member_id'], $member_point); } if ($member_point < 0) { $totalScore = 0; } else { $totalScore = $member_point; } } else { $totalScore = 0; $subtotal_gain_score = 0; //如果是非会员购买获得积分为0,@lujy } foreach ((array) $cart_info['promotion']['order'] as $k => $v) { $pmt_order_info .= $v['desc'] . "<br>"; } $cost_item = $objMath->number_minus(array($cost_item, $cart_info['discount_amount_prefilter'])); $payment_detail = array('cost_item' => $objCurrency->amount_nocur($cost_item, $sdf_order['cur'], false, false), 'cost_protect' => $objCurrency->amount_nocur($cost_protect, $sdf_order['cur'], false, false), 'cost_freight' => $objCurrency->amount_nocur($cost_freight, $sdf_order['cur'], false, false), 'cost_payment' => $objCurrency->amount_nocur($cost_payment, $sdf_order['cur'], false, false), 'total_amount' => $total_amount_odr, 'currency' => $sdf_order['cur'], 'pmt_order' => $cart_info['discount_amount_order'], 'pmt_amount' => $cart_info['discount_amount'], 'cost_tax' => $cost_tax, 'trigger_tax' => $sdf_order['is_tax'], 'discount' => $order_discount, 'cur_code' => $strDefCurrency, 'cur_display' => $sdf_order['cur'], 'cur_rate' => $aCur['cur_rate'], 'final_amount' => $objCurrency->changer_odr($total_amount, $sdf_order['cur'], true, false, $odr_decimals, $system_money_operation_carryset), 'totalConsumeScore' => $subtotal_consume_score, 'totalGainScore' => $subtotal_gain_score, 'totalScore' => $totalScore, 'pmt_order_info' => $pmt_order_info); if ($obj_point_dis && $site_point_usage == '2') { $point_extend_html = $obj_point_dis->gen_payment_detail($payment_detail); $payment_detail['point_extend_html'] = $point_extend_html; } return $payment_detail; }
/** * 管理员手工编辑订单 * @params string 提交过来的数组 * @params boolean 附件库存不足时是否需要删除的标记 * @return string message */ public function generate(&$aData, $delMark = true, &$message = '') { $obj_orders = $this->app->model('orders'); if ($aData['order_id'] == '') { $obj_orders->save($aData); } else { $orderid = $aData['order_id']; } if (!isset($aData['aItems']) || !$aData['aItems']) { $message = app::get('b2c')->_('订单明细不能为空!'); return false; } $mdl_order_items = $this->app->model('order_items'); $mdl_order_objects = $this->app->model('order_objects'); $mdl_goods = $this->app->model('goods'); $mdl_products = $this->app->model('products'); $addStore = array(); $is_error = false; if (isset($aData['aItems']['product_id']) && $aData['aItems']['product_id'] && isset($aData['aItems']['object_id']) && $aData['aItems']['object_id']) { foreach ($aData['aItems']['product_id'] as $key => $productId) { //得到订单数据,不包含下级的数据 $aStore = $mdl_products->dump($productId, '*'); /**ajx 添加ocs、淘管编辑订单时,无库存可购买的商品报库存不足的问题的解决方法*/ $goods_id = $aStore['goods_id']; $goods_detail = $mdl_goods->getList('nostore_sell', array('goods_id' => $goods_id)); $nostore_sell = $goods_detail[0]['nostore_sell']; /**ajx end*/ $storage_enable = $this->app->getConf('site.storage.enabled'); $object_id = $aData['aItems']['object_id'][$key]; if (!is_null($aStore['store']) && $aStore['store'] !== '') { $rows = $mdl_order_items->getList('*', array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); $aRet = $rows[0]; $gStore = $this->objMath->number_plus(array($this->objMath->number_minus(array(floatval($aStore['store']), floatval($aStore['freez']))), floatval($aRet['nums']))); if (!$nostore_sell && $gStore < $aData['aNum'][$key] && $storage_enable != 'true') { //return false; $is_error = true; $message .= $aRet['name'] . ',' . app::get('b2c')->_('商品货号:') . $aRet['bn'] . app::get('b2c')->_('的货品库存不足!') . "\r\n"; $aData['aNum'][$key] = $aRet['nums']; continue; } // 需要改变的库存 if (isset($addStore[$productId]) && $addStore[$productId]) { $addStore[$productId] = $this->objMath->number_plus(array($addStore[$productId], $this->objMath->number_minus(array(floatval($aData['aNum'][$key]), floatval($aRet['nums']))))); } else { $addStore[$productId] = $this->objMath->number_minus(array(floatval($aData['aNum'][$key]), floatval($aRet['nums']))); } } } } if (isset($aData['ajunctItems']['product_id']) && $aData['ajunctItems']['product_id'] && isset($aData['ajunctItems']['object_id']) && $aData['ajunctItems']['object_id']) { // 得到商品允许添加的配件数目 if (isset($aData['ajunctItems']['goods_id']) && $aData['ajunctItems']['goods_id']) { $arr_goods = $mdl_goods->dump($aData['ajunctItems']['goods_id']); $arr_ajunct = unserialize($arr_goods['adjunct']); if (is_null($arr_ajunct['max_num'])) { $max_junct_nums = 99999; } else { $max_junct_nums = $arr_ajunct['max_num']; } } else { $max_junct_nums = 0; } foreach ($aData['ajunctItems']['product_id'] as $key => $productId) { //得到订单数据,不包含下级的数据 $aStore = $mdl_products->dump($productId, '*'); $storage_enable = $this->app->getConf('site.storage.enabled'); $object_id = $aData['ajunctItems']['object_id'][$key]; if (!is_null($aStore['store']) && $aStore['store'] !== '') { $rows = $mdl_order_items->getList('*', array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); $aRet = $rows[0]; $gStore = $this->objMath->number_plus(array($this->objMath->number_minus(array(floatval($aStore['store']), floatval($aStore['freez']))), floatval($aRet['nums']))); if (!$nostore_sell && $gStore < $aData['ajunctNum'][$key] && $storage_enable != 'true') { //return false; $is_error = true; $message .= $aRet['name'] . ',' . app::get('b2c')->_('商品货号:') . $aRet['bn'] . app::get('b2c')->_('的货品库存不足!') . "\r\n"; $aData['ajunctNum'][$key] = $aRet['nums']; continue; } else { if ($max_junct_nums < $aData['ajunctNum'][$key]) { $is_error = true; $message .= $aRet['name'] . ',' . app::get('b2c')->_('配件货号:') . $aRet['bn'] . app::get('b2c')->_('的购买量超过了允许购买的最大值!') . "\r\n"; $aData['ajunctNum'][$key] = $aRet['nums']; continue; } } if (isset($addStore[$productId]) && $addStore[$productId]) { $addStore[$productId] = $this->objMath->number_plus(array($addStore[$productId], $this->objMath->number_minus(array(floatval($aData['ajunctNum'][$key]), floatval($aRet['nums']))))); } else { $addStore[$productId] = $this->objMath->number_minus(array(floatval($aData['ajunctNum'][$key]), floatval($aRet['nums']))); } } } } if (isset($aData['aItems']['product_id']) && $aData['aItems']['product_id'] && isset($aData['aItems']['object_id']) && $aData['aItems']['object_id']) { reset($aData['aItems']['product_id']); if ($aData['ajunctItems']['product_id']) { reset($aData['ajunctItems']['product_id']); } if ($aData['ajunctItems']['product_id']) { $aData['aItems']['product_id'] = array_merge($aData['aItems']['product_id'], $aData['ajunctItems']['product_id']); } if ($aData['ajunctItems']['object_id']) { $aData['aItems']['object_id'] = array_merge($aData['aItems']['object_id'], $aData['ajunctItems']['object_id']); } if ($aData['ajunctPrice']) { $aData['aPrice'] = array_merge($aData['aPrice'], $aData['ajunctPrice']); } if ($aData['ajunctNum']) { $aData['aNum'] = array_merge($aData['aNum'], $aData['ajunctNum']); } $itemsFund = 0; $item_weight = 0; // 所有的goods type 处理的服务的初始化. $is_decomposition_types = array(); $is_cal_itemsfund_types = array(); $arr_service_goods_type = kernel::servicelist('order_goodstype_operation'); foreach ($arr_service_goods_type as $obj_service_goods_type) { if ($obj_service_goods_type->is_decomposition()) { $is_decomposition_types[] = $obj_service_goods_type->get_goods_type(); } if (method_exists($obj_service_goods_type, 'is_cal_itemsfund') && $obj_service_goods_type->is_cal_itemsfund()) { $is_cal_itemsfund_types[$obj_service_goods_type->get_goods_type()] = $obj_service_goods_type; } } $is_add_item_amount = array(); $arr_order_object = $mdl_order_objects->getList('obj_id,amount,weight,obj_type', array('order_id' => $orderid)); if ($arr_order_object) { foreach ($arr_order_object as $str_order_object) { if (isset($is_cal_itemsfund_types[$str_order_object['obj_type']]) && is_object($is_cal_itemsfund_types[$str_order_object['obj_type']])) { if (in_array($str_order_object['obj_id'], $aData['aItems']['object_id'])) { $is_add_item_amount[$str_order_object['obj_id']] = true; $itemsFund = $this->objMath->number_plus(array($itemsFund, $is_cal_itemsfund_types[$str_order_object['obj_type']]->getItemFund($str_order_object, $aData['aItems']))); } } else { if (!in_array($str_order_object['obj_type'], $is_decomposition_types)) { if (in_array($str_order_object['obj_id'], $aData['aItems']['object_id'])) { $is_add_item_amount[$str_order_object['obj_id']] = true; $itemsFund = $this->objMath->number_plus(array($itemsFund, $str_order_object['amount'])); $item_weight = $this->objMath->number_plus(array($item_weight, $str_order_object['weight'])); } } } } } $cost_item = 0; $arr_insert_objects = array(); foreach ($aData['aItems']['product_id'] as $key => $productId) { $aItem = array(); $aItem['order_id'] = $orderid; $aItem['product_id'] = $productId; $object_id = $aData['aItems']['object_id'][$key]; if (!$is_add_item_amount || !$is_add_item_amount[$object_id]) { $aItem['price'] = $aData['aPrice'][$key]; } $aItem['quantity'] = $aData['aNum'][$key]; $aItem['amount'] = $this->objMath->number_multiple(array($aItem['price'], $aItem['quantity'])); $cost_item = $this->objMath->number_plus(array($cost_item, $aItem['amount'])); //todo 库存冻结量,库存是否足够 / 商品配件 $rows = $mdl_order_items->dump(array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); if (isset($rows['item_id']) && $rows['item_id']) { $item_weight = $this->objMath->number_plus(array($item_weight, $this->objMath->number_multiple(array($rows['weight'], $aItem['quantity'])))); $aProduct['edit'][] = array('product_id' => $productId, 'object_id' => $object_id); $aItem['item_id'] = $rows['item_id']; $mdl_order_items->save($aItem); } else { $aPdtinfo = $mdl_products->dump($productId, 'goods_id, bn, name, cost, store, weight, spec_desc'); $item_weight = $this->objMath->number_plus(array($item_weight, $this->objMath->number_multiple(array($aPdtinfo['weight'], $aItem['quantity'])))); $aItem['weight'] = $this->objMath->number_multiple(array($aPdtinfo['weight'], $aItem['quantity'])); unset($aPdtinfo['price']); $aGoodsinfo = $mdl_goods->dump($aPdtinfo['goods_id'], 'type_id'); $aItem = array_merge($aItem, $aPdtinfo); $aItem['type_id'] = $aGoodsinfo['type']['type_id']; // 订单附加信息 $strAddon = ""; $arrAddon = array(); $obj_specification = $this->app->model('specification'); $obj_spec_values = $this->app->model('spec_values'); foreach ($aPdtinfo['spec_desc']['spec_value_id'] as $spec_key => $str_spec_value_id) { $arr_spec_value = $obj_spec_values->dump($str_spec_value_id); $arr_specification = $obj_specification->dump($arr_spec_value['spec_id']); $arrAddon['product_attr'][$spec_key] = array('label' => $arr_specification['spec_name'], 'value' => $arr_spec_value['spec_value']); } $strAddon = serialize($arrAddon); $arr_insert_objects[] = array('obj_type' => 'goods', 'obj_alias' => app::get('b2c')->_('商品区块'), 'goods_id' => $aItem['goods_id'], 'order_id' => $aItem['order_id'], 'bn' => $aItem['bn'], 'name' => $aItem['name'], 'price' => $aItem['price'], 'quantity' => 1, 'amount' => $aItem['amount'], 'weight' => $aItem['weight'], 'score' => 0, 'order_items' => array(array('products' => array('product_id' => $productId), 'goods_id' => $aItem['goods_id'], 'order_id' => $aItem['order_id'], 'item_type' => 'product', 'bn' => $aItem['bn'], 'name' => $aItem['name'], 'type_id' => $aItem['type_id'], 'cost' => $aItem['cost'], 'quantity' => $aItem['quantity'], 'sendnum' => 0, 'amount' => $aItem['amount'], 'price' => $aItem['price'], 'g_price' => $aItem['price'], 'weight' => $aItem['weight'], 'addon' => $strAddon))); $aProduct['edit'][] = array('product_id' => $productId, 'object_id' => $object_id); } $itemsFund = $this->objMath->number_plus(array($itemsFund, $aItem['amount'])); $freezTime = $this->app->getConf('system.goods.freez.time'); $tmpdata = array(); if ($freezTime == 1) { $tmpdata['product_id'] = $productId; if (isset($addStore[$productId])) { if (floatval($addStore[$productId]) >= 0) { // 冻结库存 $tmpdata['freez'] = $this->objMath->number_plus(array($row['freez'], floatval($addStore[$productId]))); $mdl_goods->freez($aItem['goods_id'], $productId, abs(floatval($addStore[$productId]))); } else { $tmpdata['freez'] = $this->objMath->number_plus(array($row['freez'], floatval($addStore[$productId]))); $mdl_goods->unfreez($aItem['goods_id'], $productId, abs(floatval($addStore[$productId]))); } } } } if ($aData['shipping_id']) { $dlytype = $this->app->model('dlytype'); //配送方式 $dlytype_info = $dlytype->dump($aData['shipping_id'], '*'); if ($aData['is_protect'] == 'true' || $aData['is_protect'] == '1') { //配送设置了保价 /*$cost_protect = $this->objMath->number_multiple(array($itemsFund, $dlytype_info['protect_rate'])); $cost_protect = $cost_protect>$dlytype_info['minprice']?$cost_protect:$dlytype_info['minprice'];//保价费 $aData['cost_protect'] = $cost_protect;*/ } else { $aData['cost_protect'] = '0.00'; } if ($dlytype_info['is_threshold']) { if ($dlytype_info['threshold']) { $dlytype_info['threshold'] = unserialize(stripslashes($dlytype_info['threshold'])); if (isset($dlytype_info['threshold']) && $dlytype_info['threshold']) { foreach ($dlytype_info['threshold'] as $res) { if ($res['area'][1] > 0) { if ($itemsFund >= $res['area'][0] && $v < $res['area'][1]) { $dlytype_info['firstprice'] = $res['first_price']; $dlytype_info['continueprice'] = $res['continue_price']; } } else { if ($itemsFund >= $res['area'][0]) { $dlytype_info['firstprice'] = $res['first_price']; $dlytype_info['continueprice'] = $res['continue_price']; } } } } } } if (!$dlytype_info['setting']) { $arrArea = explode(':', $aData['ship_area']); $area_id = $arrArea[2]; if (isset($dlytype_info['area_fee_conf']) && $dlytype_info['area_fee_conf']) { $area_fee_conf = unserialize($dlytype_info['area_fee_conf']); foreach ($area_fee_conf as $k => $v) { $areas = explode(',', $v['areaGroupId']); // 再次解析字符 foreach ($areas as &$strArea) { if (strpos($strArea, '|') !== false) { $strArea = substr($strArea, 0, strpos($strArea, '|')); // 取当前area id对应的最上级的区域id $objRegions = app::get('ectools')->model('regions'); $arrRegion = $objRegions->dump($area_id); while ($row = $objRegions->getRegionByParentId($arrRegion['p_region_id'])) { $arrRegion = $row; $tmp_area_id = $row['region_id']; if ($tmp_area_id == $strArea) { $area_id = $tmp_area_id; break; } } } } if (in_array($area_id, $areas)) { //如果地区在其中,优先使用地区设置的配送费用,及公式 $dlytype_info['firstprice'] = $v['firstprice']; $dlytype_info['continueprice'] = $v['continueprice']; $dlytype_info['dt_expressions'] = $v['dt_expressions']; break; } } } } $aData['cost_freight'] = @utils::cal_fee($dlytype_info['dt_expressions'], $item_weight, $itemsFund, $dlytype_info['firstprice'], $dlytype_info['continueprice']); //配送费 } if ($delMark) { $this->execDelItems($orderid, $aProduct['edit']); } else { //$itemsFund = $this->getCostItems($orderid); } // 存储新增的订单项目 if (isset($arr_insert_objects) && $arr_insert_objects) { foreach ($arr_insert_objects as $order_objects) { $mdl_order_objects->save($order_objects); } } $aDataTmp['cost_item'] = $itemsFund; $aDataTmp['shipping']['cost_shipping'] = $aData['cost_freight']; $aDataTmp['shipping']['cost_protect'] = $aData['cost_protect']; $rate = $obj_orders->dump($orderid, 'cur_rate,discount,pmt_order,pmt_goods'); $aData['discount'] = $this->objMath->number_minus(array($aData['discount'], $rate['discount'])); $aDataTmp['total_amount'] = $this->objMath->number_plus(array($itemsFund, $aData['cost_freight'], $aData['cost_protect'], $aData['cost_payment'], $aData['cost_tax'], $rate['discount'], $aData['discount'], -$rate['pmt_order'])); if ($aDataTmp['total_amount'] < 0) { $aDataTmp['total_amount'] = 0; } $aDataTmp['weight'] = $item_weight ? $item_weight : 0; $aDataTmp['discount'] = $this->objMath->number_plus(array($rate['discount'], $aData['discount'])); $aDataTmp['cur_amount'] = $this->objMath->number_multiple(array($aDataTmp['total_amount'], $rate['cur_rate'])); $aDataTmp['order_id'] = $orderid; if ($obj_orders->save($aDataTmp) && !$is_error) { // 添加日志. $orderLog = $this->app->model("order_log"); $log_text[] = array('txt_key' => '订单修改成功!', 'data' => array()); $log_text = serialize($log_text); $sdf_order_log = array('rel_id' => $orderid, 'op_id' => $aData['user_id'], 'op_name' => $aData['account']['login_name'], 'alttime' => time(), 'bill_type' => 'order', 'behavior' => 'updates', 'result' => 'SUCCESS', 'log_text' => $log_text); $orderLog->save($sdf_order_log); return true; } else { return false; } } else { if (isset($aData['aItems']) && $aData['aItems']) { $obj_order_obj = $this->app->model('order_objects'); $tmp = $obj_order_obj->getList('amount', array('order_id' => $aData['order_id'])); if ($tmp) { foreach ($tmp as $obj_items) { $itemsFund = $this->objMath->number_plus(array($itemsFund, $obj_items['amount'])); } } $aDataTmp['cost_item'] = $itemsFund; $aDataTmp['shipping']['cost_shipping'] = $aData['cost_freight']; $aDataTmp['total_amount'] = $this->objMath->number_minus(array($this->objMath->number_plus(array($itemsFund, $aData['cost_freight'], $aData['cost_protect'], $aData['cost_payment'], $aData['cost_tax'], $aData['discount'])), $aData['pmt_order'])); $aDataTmp['weight'] = $item_weight ? $item_weight : '0.000'; $aDataTmp['discount'] = $aData['discount'] >= 0 ? abs($aData['discount']) : $this->objMath->number_minus(array(0, abs($aData['discount']))); $rate = $obj_orders->dump($orderid, 'cur_rate'); $aDataTmp['cur_amount'] = $this->objMath->number_multiple(array($aDataTmp['total_amount'], $rate['cur_rate'])); $aDataTmp['order_id'] = $orderid; if ($obj_orders->save($aDataTmp) && !$is_error) { // 添加日志. $orderLog = $this->app->model("order_log"); $log_text[] = array('txt_key' => '订单修改成功!', 'data' => array()); $log_text = serialize($log_text); $sdf_order_log = array('rel_id' => $orderid, 'op_id' => $aData['user_id'], 'op_name' => $aData['account']['login_name'], 'alttime' => time(), 'bill_type' => 'order', 'behavior' => 'updates', 'result' => 'SUCCESS', 'log_text' => $log_text); $orderLog->save($sdf_order_log); return true; } else { return false; } } } return true; }
/** * 根据地区ID,获取在次购物车中配送方式和配送价格 */ public function get_dlytype($params, &$service) { if (!$this->check_accesstoken($params['accesstoken'], $params['member_id'])) { return $service->send_user_error('100001', 'accesstoken fail'); } $mCart = app::get('b2c')->model('cart'); $aCart = $mCart->get_objects($aData); $all_dly_types = kernel::single('b2c_order_dlytype')->get_dlytype($this, $params['area_id'], $aCart); foreach ($all_dly_types as $i => $rows) { if ($rows['is_threshold'] && $rows['threshold']) { $rows['threshold'] = unserialize(stripslashes($rows['threshold'])); if (isset($rows['threshold']) && $rows['threshold']) { foreach ($rows['threshold'] as $res) { if ($res['area'][1] > 0) { if ($cost_item >= $res['area'][0] && $cost_item < $res['area'][1]) { $rows['firstprice'] = $res['first_price']; $rows['continueprice'] = $res['continue_price']; } } else { if ($cost_item >= $res['area'][0]) { $rows['firstprice'] = $res['first_price']; $rows['continueprice'] = $res['continue_price']; } } } } } $delivery[$i]['dt_id'] = $rows['dt_id']; $delivery[$i]['has_cod'] = $rows['has_cod']; $delivery[$i]['dt_name'] = $rows['dt_name']; $delivery[$i]['detail'] = $rows['detail']; $delivery[$i]['protect'] = $rows['protect']; $delivery[$i]['protect_rate'] = $rows['protect_rate']; $delivery[$i]['minprice'] = $rows['minprice']; $delivery[$i]['money'] = utils::cal_fee($rows['dt_expressions'], $aCart['subtotal_weight'], $aCart['subtotal'], $rows['firstprice'], $rows['continueprice'], $rows['firstprice']); } return $delivery; }
/** * 管理员手工编辑订单 * @params string 提交过来的数组 * @params boolean 附件库存不足时是否需要删除的标记 * @return string message */ private function editOrder(&$aData, $delMark = true, &$message = '') { $obj_orders = $this->app->model('orders'); if ($aData['order_id'] == '') { $obj_orders->save($aData); } else { $orderid = $aData['order_id']; } $mdl_order_items = $this->app->model('order_items'); $mdl_order_objects = $this->app->model('order_objects'); $mdl_goods = $this->app->model('goods'); $mdl_products = $this->app->model('products'); $addStore = array(); $is_error = false; if (isset($aData['aItems']['product_id']) && $aData['aItems']['product_id'] && isset($aData['aItems']['object_id']) && $aData['aItems']['object_id']) { foreach ($aData['aItems']['product_id'] as $key => $productId) { //得到订单数据,不包含下级的数据 $aStore = $mdl_products->dump($productId, '*'); $storage_enable = $this->app->getConf('site.storage.enabled'); $object_id = $aData['aItems']['object_id'][$key]; if (!is_null($aStore['store']) && $aStore['store'] !== '') { $rows = $mdl_order_items->getList('*', array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); $aRet = $rows[0]; $gStore = $this->objMath->number_plus($this->objMath->number_minus(array(floatval($aStore['store']), floatval($aStore['freez']))), floatval($aRet['nums'])); if ($gStore < $aData['aNum'][$key] && $storage_enable != 'true') { //return false; $is_error = true; $message .= $aRet['name'] . ',商品货号:' . $aRet['bn'] . '的货品库存不足!' . "\r\n"; $aData['aNum'][$key] = $aRet['nums']; continue; } // 需要改变的库存 if (isset($addStore[$productId]) && $addStore[$productId]) { $addStore[$productId] = $this->objMath->number_plus(array($addStore[$productId], $this->objMath->number_minus(array(floatval($aData['aNum'][$key]), floatval($aRet['nums']))))); } else { $addStore[$productId] = $this->objMath->number_minus(array(floatval($aData['aNum'][$key]), floatval($aRet['nums']))); } } } } if (isset($aData['ajunctItems']['product_id']) && $aData['ajunctItems']['product_id'] && isset($aData['ajunctItems']['object_id']) && $aData['ajunctItems']['object_id']) { // 得到商品允许添加的配件数目 if (isset($aData['ajunctItems']['goods_id']) && $aData['ajunctItems']['goods_id']) { $arr_goods = $mdl_goods->dump($aData['ajunctItems']['goods_id']); $arr_ajunct = unserialize($arr_goods['adjunct']); if (is_null($arr_ajunct['max_num'])) { $max_junct_nums = 99999; } else { $max_junct_nums = $arr_ajunct['max_num']; } } else { $max_junct_nums = 0; } foreach ($aData['ajunctItems']['product_id'] as $key => $productId) { //得到订单数据,不包含下级的数据 $aStore = $mdl_products->dump($productId, '*'); $storage_enable = $this->app->getConf('site.storage.enabled'); $object_id = $aData['ajunctItems']['object_id'][$key]; if (!is_null($aStore['store']) && $aStore['store'] !== '') { $rows = $mdl_order_items->getList('*', array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); $aRet = $rows[0]; $gStore = $this->objMath->number_plus($this->objMath->number_minus(array(floatval($aStore['store']), floatval($aStore['freez']))), floatval($aRet['nums'])); if ($gStore < $aData['ajunctNum'][$key] && $storage_enable != 'true') { //return false; $is_error = true; $message .= $aRet['name'] . ',商品货号:' . $aRet['bn'] . '的货品库存不足!' . "\r\n"; $aData['ajunctNum'][$key] = $aRet['nums']; continue; } else { if ($max_junct_nums < $aData['ajunctNum'][$key]) { $is_error = true; $message .= $aRet['name'] . ',配件货号:' . $aRet['bn'] . '的购买量超过了允许购买的最大值!' . "\r\n"; $aData['ajunctNum'][$key] = $aRet['nums']; continue; } } if (isset($addStore[$productId]) && $addStore[$productId]) { $addStore[$productId] = $this->objMath->number_plus(array($addStore[$productId], $this->objMath->number_minus(array(floatval($aData['ajunctNum'][$key]), floatval($aRet['nums']))))); } else { $addStore[$productId] = $this->objMath->number_minus(array(floatval($aData['ajunctNum'][$key]), floatval($aRet['nums']))); } } } } reset($aData['aItems']['product_id']); if ($aData['ajunctItems']['product_id']) { reset($aData['ajunctItems']['product_id']); } if ($aData['ajunctItems']['product_id']) { $aData['aItems']['product_id'] = array_merge($aData['aItems']['product_id'], $aData['ajunctItems']['product_id']); } if ($aData['ajunctItems']['object_id']) { $aData['aItems']['object_id'] = array_merge($aData['aItems']['object_id'], $aData['ajunctItems']['object_id']); } if ($aData['ajunctPrice']) { $aData['aPrice'] = array_merge($aData['aPrice'], $aData['ajunctPrice']); } if ($aData['ajunctNum']) { $aData['aNum'] = array_merge($aData['aNum'], $aData['ajunctNum']); } $itemsFund = 0; $item_weight = 0; $cost_item = 0; $arr_insert_objects = array(); foreach ($aData['aItems']['product_id'] as $key => $productId) { $aItem = array(); $aItem['order_id'] = $orderid; $aItem['product_id'] = $productId; $aItem['price'] = $aData['aPrice'][$key]; $aItem['quantity'] = $aData['aNum'][$key]; $aItem['amount'] = $this->objMath->number_multiple(array($aItem['price'], $aItem['quantity'])); $object_id = $aData['aItems']['object_id'][$key]; $cost_item = $this->objMath->number_plus(array($cost_item, $aItem['amount'])); //todo 库存冻结量,库存是否足够 / 商品配件 $rows = $mdl_order_items->dump(array('order_id' => $orderid, 'product_id' => $productId, 'obj_id' => $object_id)); if (isset($rows['item_id']) && $rows['item_id']) { $item_weight = $this->objMath->number_plus(array($item_weight, $this->objMath->number_multiple(array($rows['weight'], $aItem['quantity'])))); $aProduct['edit'][] = array('product_id' => $productId, 'object_id' => $object_id); $aItem['item_id'] = $rows['item_id']; $mdl_order_items->save($aItem); } else { $aPdtinfo = $mdl_products->dump($productId, 'goods_id, bn, name, cost, store, weight'); $item_weight = $this->objMath->number_plus(array($item_weight, $this->objMath->number_multiple(array($aPdtinfo['weight'], $aItem['quantity'])))); $aPdtinfo['weight'] *= $aItem['quantity']; unset($aPdtinfo['price']); $aGoodsinfo = $mdl_goods->dump($aPdtinfo['goods_id'], 'type_id'); $aItem = array_merge($aItem, $aPdtinfo); $aItem['type_id'] = $aGoodsinfo['type']['type_id']; $arr_insert_objects[] = array('obj_type' => 'goods', 'obj_alias' => '商品区块', 'goods_id' => $aItem['goods_id'], 'order_id' => $aItem['order_id'], 'bn' => $aItem['bn'], 'name' => $aItem['name'], 'price' => $aItem['price'], 'quantity' => 1, 'amount' => $aItem['amount'], 'weight' => $aItem['weight'], 'score' => 0, 'order_items' => array(array('products' => array('product_id' => $productId), 'goods_id' => $aItem['goods_id'], 'order_id' => $aItem['order_id'], 'item_type' => 'product', 'bn' => $aItem['bn'], 'name' => $aItem['name'], 'type_id' => $aItem['type_id'], 'cost' => $aItem['cost'], 'quantity' => $aItem['quantity'], 'sendnum' => 0, 'amount' => $aItem['amount'], 'price' => $aItem['price'], 'weight' => $aItem['weight'], 'addon' => 0))); $aProduct['edit'][] = array('product_id' => $productId, 'object_id' => $object_id); } $itemsFund = $this->objMath->number_plus(array($itemsFund, $aItem['amount'])); $freezTime = $this->app->getConf('system.goods.freez.time'); $tmpdata = array(); if ($freezTime == 1) { $tmpdata['product_id'] = $productId; if (isset($addStore[$productId])) { if (floatval($addStore[$productId]) >= 0) { // 冻结库存 $tmpdata['freez'] = $this->objMath->number_plus(array($row['freez'], floatval($addStore[$productId]))); $mdl_goods->freez($aItem['goods_id'], $productId, abs(floatval($addStore[$productId]))); } else { $tmpdata['freez'] = $this->objMath->number_plus(array($row['freez'], floatval($addStore[$productId]))); $mdl_goods->unfreez($aItem['goods_id'], $productId, abs(floatval($addStore[$productId]))); } } } } if ($aData['shipping_id']) { $dlytype = $this->app->model('dlytype'); //配送方式 $dlytype_info = $dlytype->dump($aData['shipping_id'], '*'); if ($aData['is_protect'] == 'true' || $aData['is_protect'] == '1') { //配送设置了保价 //$cost_protect = ($cost_item*$dlytype_info['protect_rate']); $cost_protect = $this->objMath->number_multiple(array($cost_item, $dlytype_info['protect_rate'])); $cost_protect = $cost_protect > $dlytype_info['minprice'] ? $cost_protect : $dlytype_info['minprice']; //保价费 } if (!$dlytype_info['setting']) { $arrArea = explode(':', $aData['ship_area']); $area_id = $arrArea[2]; if (isset($dlytype_info['area_fee_conf']) && $dlytype_info['area_fee_conf']) { $area_fee_conf = unserialize($dlytype_info['area_fee_conf']); foreach ($area_fee_conf as $k => $v) { $areas = explode(',', $v['areaGroupId']); // 再次解析字符 foreach ($areas as &$strArea) { if (strpos($strArea, '|') !== false) { $strArea = substr($strArea, 0, strpos($strArea, '|')); } } // 取当前area id对应的最上级的区域id $objRegions = app::get('ectools')->model('regions'); $arrRegion = $objRegions->dump($area_id); while ($row = $objRegions->getRegionByParentId($arrRegion['p_region_id'])) { $arrRegion = $row; $area_id = $row['region_id']; } if (in_array($area_id, $areas)) { //如果地区在其中,优先使用地区设置的配送费用,及公式 $dlytype_info['firstprice'] = $v['firstprice']; $dlytype_info['continueprice'] = $v['continueprice']; $dlytype_info['dt_expressions'] = $v['dt_expressions']; break; } } } } $aData['cost_freight'] = utils::cal_fee($dlytype_info['dt_expressions'], $item_weight, $cost_item); //配送费 } if ($delMark) { $this->execDelItems($orderid, $aProduct['edit']); } else { //$itemsFund = $this->getCostItems($orderid); } // 存储新增的订单项目 if (isset($arr_insert_objects) && $arr_insert_objects) { foreach ($arr_insert_objects as $order_objects) { $mdl_order_objects->save($order_objects); } } $aDataTmp['cost_item'] = $itemsFund; $aDataTmp['shipping']['cost_shipping'] = $aData['cost_freight']; $aDataTmp['total_amount'] = $this->objMath->number_minus(array($this->objMath->number_plus(array($itemsFund, $aData['cost_freight'], $aData['cost_protect'], $aData['cost_payment'], $aData['cost_tax'], $aData['discount'])), $aData['pmt_order'])); $aDataTmp['weight'] = $item_weight; $aDataTmp['discount'] = abs($aData['discount']); $rate = $obj_orders->dump($orderid, 'cur_rate'); $aDataTmp['cur_amount'] = $this->objMath->number_multiple(array($aDataTmp['total_amount'], $rate['cur_rate'])); $aDataTmp['order_id'] = $orderid; if ($obj_orders->save($aDataTmp) && !$is_error) { // 添加日志. $orderLog = $this->app->model("order_log"); $sdf_order_log = array('rel_id' => $orderid, 'op_id' => $aData['user_id'], 'op_name' => $aData['account']['login_name'], 'alttime' => time(), 'bill_type' => 'order', 'behavior' => 'updates', 'result' => 'SUCCESS'); $orderLog->save($sdf_order_log); return true; } else { return false; } return $aMsg; }