/** * @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 promotionRuleAjax() { $goodsId = IFilter::act(IReq::get("goodsId"), 'int'); $productId = IFilter::act(IReq::get("productId"), 'int'); $num = IFilter::act(IReq::get("num"), 'int'); $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(); $cartObj = new Cart(); $countSumResult = $countSumObj->goodsCount($cartObj->cartFormat(array("goods" => $goodsArray, "product" => $productArray))); echo JSON::encode($countSumResult); }
/** * @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'); }
/** * @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; }