Beispiel #1
0
 public function addProduct($goods, $num = 1)
 {
     $product_id = NULL;
     $goods_id = NULL;
     $ship_id = NULL;
     if (isset($goods['product_id'])) {
         $product_id = $goods['product_id'];
     } else {
         $ret["msg"] = "添加商品失败,没有货品ID";
         $ret["status"] = false;
         return $ret;
         //Tiny::log(__FILE__ . __LINE__ . "------product---id----$goods_id---" . var_export($item, true));
     }
     $item = array();
     $prom_series = array();
     $prom_goods = array();
     $products_inst = new Products();
     $ret = $products_inst->getProduct($product_id);
     // 获取商品信息 item = product
     if (isset($ret['status']) && $ret['status'] == 1) {
         $item = $ret['data'];
     }
     if (!empty($item) && isset($item["goods_id"])) {
         $goods_id = $item["goods_id"];
     } else {
         $ret["msg"] = "添加商品失败,没有商品ID";
         $ret["status"] = false;
         return $ret;
     }
     if (isset($item["ship_id"]) && $item["ship_id"] > 0) {
         $ship_id = $item["ship_id"];
         // 默认所有的ship_id必须有
     } else {
         $ret["msg"] = "添加商品失败,该商品没有ship_id";
         $ret["status"] = false;
         return $ret;
     }
     $goods_info = array("ship_id" => $ship_id, "goods_id" => $goods_id, "product_id" => $product_id);
     if ($this->hasProducts($goods_info)) {
         $this->increaseProductsNum($goods_info, $num);
         $ret["msg"] = "添加商品成功!";
         $ret["status"] = true;
         return $ret;
     }
     //每个商品税种
     $tax_type_percent = 0;
     $tax_amount = 0;
     if (isset($item['tax_type_percent']) && $item['tax_type_percent'] >= 0) {
         $tax_type_percent = $item['tax_type_percent'];
         $tax_amount = $item['sell_price'] * $item['tax_type_percent'];
         // 税金暂时用销售价格计税  不按促销价格计税
     }
     $order_type = array("flash_sale" => false, "prom_goods" => false, "prom_series" => false, "bundling" => false);
     $prom_inst = new Prom();
     if (!empty($item)) {
         if ($num > $item['store_nums']) {
             $num = $item['store_nums'];
             //$this->modify_num($item, $num);
         }
         if ($num <= 0) {
             $this->delProducts($item);
         } else {
             $item['goods_nums'] = $num;
             //1 先判断限时抢购
             $flash_sale = array();
             $ret = $prom_inst->get_flash_sale($goods_info);
             if ($ret["status"] == 1 && isset($ret["data"])) {
                 $flash_sale = $ret["data"];
             }
             //Tiny::log(__FILE__ . __LINE__ . "------flash_sale-----" . var_export($flash_sale, true));
             if (!empty($flash_sale)) {
                 //$this->assign("flash_sale",$flash_sale);
                 $order_type["flash_sale"] = true;
                 $amount = sprintf("%01.2f", $flash_sale['price'] * $num);
                 $sell_total = $item['sell_price'] * $num;
                 $flash_sale['note'] = '抢购';
                 $products_item = array('product_id' => $item['id'], 'goods_id' => $item['goods_id'], 'goods_no' => $item['goods_no'], 'name' => $item['name'], 'img' => $item['img'], 'num' => $num, 'max_nums' => $item['store_nums'], 'store_nums' => $item['store_nums'], 'price' => $item['sell_price'], 'prom_id' => $item['prom_id'], 'real_price' => $flash_sale['price'], 'sell_price' => $item['sell_price'], 'spec' => unserialize($item['spec']), 'amount' => $amount, 'prom' => $flash_sale['note'], 'weight' => $flash_sale['weight'], 'point' => $flash_sale['point'], 'sell_total' => $sell_total, 'tax_type_percent' => $tax_type_percent, 'tax_amount' => $tax_amount, 'tax_code' => $item['tax_code'], "flash_sale" => $flash_sale, "order_type" => $order_type, 'origin_country' => $item['origin_country']);
             } else {
                 $amount = sprintf("%01.2f", $item['sell_price'] * $num);
                 // 普通商品不参加促销的情况下
                 $products_item = array('product_id' => $item['id'], 'goods_id' => $item['goods_id'], 'goods_no' => $item['goods_no'], 'name' => $item['name'], 'img' => $item['img'], 'num' => $num, 'max_nums' => $item['store_nums'], 'store_nums' => $item['store_nums'], 'price' => $item['sell_price'], 'prom_id' => $item['prom_id'], 'real_price' => $item['sell_price'], 'sell_price' => $item['sell_price'], 'spec' => unserialize($item['spec']), 'amount' => $amount, 'tax_type_percent' => $tax_type_percent, 'tax_amount' => $tax_amount, 'tax_code' => $item['tax_code'], 'prom' => "不参与促销", 'weight' => $item['weight'], 'point' => $item['point'] * $num, 'sell_total' => $amount, "order_type" => $order_type, 'origin_country' => $item['origin_country']);
                 //2 判断商品促销(单品)
                 $prom_goods = $prom_inst->get_prom_goods($item);
                 if (!empty($prom_goods)) {
                     $order_type["prom_goods"] = true;
                     $prom_goods['parse'] = $prom_inst->do_prom_goods($item, $prom_goods);
                     //$prom_goods = $prom_inst->do_prom_goods($item, $prom_goods_item);
                     if (Filter::int($prom_goods['expression']) == 0) {
                         $prom_goods['parse']['note'] = "";
                     }
                     if (isset($prom_goods['parse']['note']) && $prom_goods['parse']['note'] != '') {
                         $prom_goods['parse']['note'] = '商品优惠:' . $prom_goods['parse']['note'];
                     }
                     $amount = sprintf("%01.2f", $prom_goods['parse']['real_price'] * $num);
                     $sell_total = $item['sell_price'] * $num;
                     $products_item = array('product_id' => $item['id'], 'goods_id' => $item['goods_id'], 'goods_no' => $item['goods_no'], 'name' => $item['name'], 'img' => $item['img'], 'num' => $num, 'max_nums' => $item['store_nums'], 'store_nums' => $item['store_nums'], 'price' => $item['sell_price'], 'prom_id' => $item['prom_id'], 'real_price' => $prom_goods['parse']['real_price'], 'sell_price' => $item['sell_price'], 'spec' => unserialize($item['spec']), 'amount' => $amount, 'tax_type_percent' => $tax_type_percent, 'tax_amount' => $tax_amount, 'tax_code' => $item['tax_code'], 'prom' => $prom_goods['parse']['note'], 'weight' => $item['weight'], 'point' => $item['point'] * $num, 'sell_total' => $sell_total, "prom_goods" => $prom_goods, "flash_sale" => $flash_sale, "order_type" => $order_type, 'origin_country' => $item['origin_country']);
                 }
                 //3 系列促销
                 //商品促销与系列促销叠加运算
                 //$prom_series = $prom_inst->prom_series($item, $prom_goods);
                 $note = isset($prom_goods['note']) ? $prom_goods['note'] : "";
                 $prom_series = $prom_inst->get_prom_series($item);
                 if (!empty($prom_series)) {
                     $prom_series['parse'] = $prom_inst->do_prom_series($item, $prom_goods, $prom_series);
                     $order_type["prom_series"] = true;
                     if (Filter::int($prom_series['expression']) == 0) {
                         $prom_series['parse']['note'] = "";
                     }
                     if (isset($prom_series['parse']['note']) && $prom_series['parse']['note'] != '') {
                         $note .= '; 系列优惠:' . $prom_series['parse']['note'];
                     }
                     $amount = sprintf("%01.2f", $prom_series['parse']['real_price'] * $num);
                     $sell_total = $item['sell_price'] * $num;
                     //合并商品与系统促销
                     // 送积分
                     $multiple = 0;
                     if (isset($prom_series['multiple']) && $prom_series['multiple'] >= 0) {
                         $multiple = $prom_series['multiple'];
                     }
                     $prom_goods['series'] = $prom_series;
                     $products_item = array('product_id' => $item['id'], 'goods_id' => $item['goods_id'], 'goods_no' => $item['goods_no'], 'name' => $item['name'], 'img' => $item['img'], 'num' => $num, 'max_nums' => $item['store_nums'], 'store_nums' => $item['store_nums'], 'price' => $item['sell_price'], 'prom_id' => $item['prom_id'], 'real_price' => $prom_series['parse']['real_price'], 'sell_price' => $item['sell_price'], 'spec' => unserialize($item['spec']), 'amount' => $amount, 'tax_type_percent' => $tax_type_percent, 'tax_amount' => $tax_amount, 'tax_code' => $item['tax_code'], 'prom' => $note, 'weight' => $item['weight'], 'point' => $item['point'] * $multiple, 'sell_total' => $sell_total, "prom_goods" => $prom_goods, "prom_series" => $prom_series, "flash_sale" => $flash_sale, "order_type" => $order_type, 'origin_country' => $item['origin_country']);
                 }
             }
             // 商品 货品
             $this->items[$ship_id]['products'][$goods_id][$product_id] = $products_item;
             //Tiny::log(__FILE__.__LINE__."-------products item--------".var_export($products_item, true));
         }
     }
     $ship_inst = new Ship();
     $ship = $ship_inst->get_ship($item["ship_id"]);
     $this->items[$item["ship_id"]]['ship_name'] = $ship['ship_name'];
 }
Beispiel #2
0
 public function order_act()
 {
     if ($this->checkOnline()) {
         $ship_id = Filter::int(Req::args('ship_id'));
         // 发货库房位置 ID
         $address_id = Filter::int(Req::args('address_id'));
         // 地址
         $payment_id = Filter::int(Req::args('payment_id'));
         // 支付ID
         $prom_id = Filter::int(Req::args('prom_id'));
         // 去掉
         $is_invoice = Filter::int(Req::args('is_invoice'));
         //
         $invoice_type = Filter::int(Req::args('invoice_type'));
         //
         $invoice_title = Filter::text(Req::args('invoice_title'));
         //
         $user_remark = Filter::txt(Req::args('user_remark'));
         $voucher_id = Filter::int(Req::args('voucher'));
         //非普通促销信息
         // $type = Req::args("type");  // 去掉
         $id = Filter::int(Req::args('id'));
         $product_id = Req::args('product_id');
         $buy_num = Req::args('buy_num');
         if (!$address_id || !$payment_id || $is_invoice == 1 && $invoice_title == '') {
             // product_id  产品ID列表 处理
             if (is_array($product_id)) {
                 foreach ($product_id as $key => $val) {
                     $product_id[$key] = Filter::int($val);
                 }
                 $product_id = implode('-', $product_id);
             } else {
                 $product_id = Filter::int($product_id);
             }
             $data = Req::args();
             $data['is_invoice'] = $is_invoice;
             if (!$address_id) {
                 $data['msg'] = array('fail', "必需选择收货地址,才能确认订单。");
             } else {
                 if (!$payment_id) {
                     $data['msg'] = array('fail', "必需选择支付方式,才能确认订单。");
                 } else {
                     $data['msg'] = array('fail', "索要发票,必需写明发票抬头。");
                 }
             }
             // type 类型
             // 下面代码没有使用
             //if ($type == null)
             //    $this->redirect("order", false, $data);
             //else {
             unset($data['act']);
             Req::args('pid', $product_id);
             Req::args('id', $id);
             unset($_GET['act']);
             //     Req::args('type', $type);
             Req::args('msg', $data['msg']);
             $this->redirect("/simple/order", true, Req::args());
             //$this->redirect("/simple/order_info", true, Req::args());
             //}
             exit;
         }
         //地址信息
         $address_model = new Model('address');
         $address = $address_model->where("id={$address_id} and user_id=" . $this->user['id'])->find();
         if (!$address) {
             $data = Req::args();
             $data['msg'] = array('fail', "选择的地址信息不正确!");
             $this->redirect("order", false, $data);
             exit;
         }
         //if(!$payment_id)$this->redirect("order",false,Req::args());
         if ($this->getModule()->checkToken('order')) {
             //订单类型: 0普通订单 1团购订单 2限时抢购 3捆绑促销
             $order_type = 0;
             $model = new Model('');
             //团购处理
             // 这部分去掉
             /*
             if($type=="groupbuy"){
                 $product_id = Filter::int($product_id[0]);
                 $num = $buy_num[0];
                 $item = $model->table("groupbuy as gb")->join("left join goods as go on gb.goods_id=go.id left join products as pr on pr.id=$product_id")->fields("*,pr.id as product_id,pr.spec")->where("gb.id=$id")->find();
                 $order_products = $this->packGroupbuyProducts($item,$num);
             
                 $groupbuy = $model->table("groupbuy")->where("id=$id")->find();
                 unset($groupbuy['description']);
                 $data['prom'] = serialize($groupbuy);
                 $data['prom_id'] = $id;
                 $order_type = 1;
             
             }
               if($order_type==0){
                 $order_products = $this->cart[$ship_id]['products'];
                 $data['prom_id'] = $prom_id;
             }
             */
             // 购物车
             //$cart = Cart::getCart();
             $cart_info = $this->cart_inst->all();
             //商品总金额,重量,积分计算
             $payable_amount = 0.0;
             $real_amount = 0.0;
             $weight = 0;
             $point = 0;
             $order_products = array();
             $error = 0;
             // 是否促销
             $error_list = array();
             if (isset($cart_info[$ship_id]['products'])) {
                 $order_products =& $cart_info[$ship_id]['products'];
                 // 循环购物车cart中每个产品
                 // 在这判断每个商品的购买方式
                 //
                 $prom_inst = new Prom();
                 foreach ($order_products as $goods_id => $products) {
                     foreach ($products as $product_id => $item) {
                         $item_ref =& $order_products[$goods_id][$product_id];
                         // Tiny::log(__FILE__ . __LINE__ . "-------products item----$key----" . var_export($item, true));
                         // 校验 所有商品的库存和活动是否结束
                         if (isset($item["order_type"])) {
                             if (is_array($item["order_type"])) {
                                 if ($item["order_type"]["flash_sale"] == true) {
                                     // test OK
                                     $goods_info = array("product_id" => $item["product_id"], 'goods_id' => $item['goods_id']);
                                     $flash_sale = array();
                                     $ret = $prom_inst->get_flash_sale($goods_info);
                                     if ($ret["status"] == 1 && isset($ret["data"])) {
                                         $flash_sale = $ret["data"];
                                         // 抢购促销校验
                                         // 是否有库存
                                         if ($flash_sale['max_num'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($flash_sale['max_num'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $flash_sale['max_num'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                     } else {
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--抢购已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_series"] == true && $item["order_type"]["prom_goods"] == true) {
                                     //2 判断商品促销(单品)
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $item_new['goods_nums'] = $item['num'];
                                     // get prom goods 需要传参数goods_nums
                                     $prom_goods = $prom_inst->get_prom_goods($item_new);
                                     if (!empty($prom_goods)) {
                                         $prom_goods['parse'] = $prom_inst->do_prom_goods($item_new, $prom_goods);
                                         if (isset($prom_goods['parse']['note']) && $prom_goods['parse']['note'] != '') {
                                             $prom_goods['parse']['note'] = '商品优惠:' . $prom_goods['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_goods['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容 价格
                                         $item_ref['real_price'] = $prom_goods['parse']['real_price'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_goods'] = false;
                                         $item_ref['real_price'] = $item_ref['sell_price'];
                                         // 真正价格 为 原来的 销售价格
                                         $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--商品促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                     //3 系列促销
                                     //商品促销与系列促销叠加运算
                                     //$prom_series = $prom_inst->prom_series($item, $prom_goods);
                                     $prom_series = $prom_inst->get_prom_series($item_new);
                                     if (!empty($prom_series)) {
                                         $prom_series['parse'] = $prom_inst->do_prom_series($item_new, $prom_goods, $prom_series);
                                         $note = isset($prom_goods['parse']['note']) ? $prom_goods['parse']['note'] : "";
                                         if (isset($prom_series['parse']['note']) && $prom_series['parse']['note'] != '') {
                                             $note .= '; 系列优惠:' . $prom_series['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_series['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         //合并商品与系统促销
                                         // 送积分
                                         $multiple = 0;
                                         if (isset($prom_series['multiple']) && $prom_series['multiple'] >= 0) {
                                             $multiple = $prom_series['multiple'];
                                         }
                                         $prom_goods['series'] = $prom_series;
                                         // 是否有库存 --- 上面检查过库存  下面部分代码不需要检查库存
                                         /*
                                                                                    *   if ($item_new['store_nums'] <= 0) {    // test OK
                                                                                         $error = 1;
                                                                                         $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!',
                                                                                             "product_id" => $item['product_id'],
                                                                                         );
                                                                                         $error_list[] = $error_item;
                                                                                     } else if ($item_new['store_nums'] < $item["num"]) {          // test OK
                                                                                         $error = 1;
                                                                                         $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!',
                                                                                             "product_id" => $item['product_id'],
                                                                                         );
                                                                                         $error_list[] = $error_item;
                                                                                     }  */
                                         //修改ITEM内容
                                         $item_ref['real_price'] = $prom_series['parse']['real_price'];
                                         $item_ref['prom'] = $note;
                                         //$item_ref['store_nums']  = $prom_goods['store_nums'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_series'] = false;
                                         // $item_ref['real_price'] = $item_ref['sell_price'];   // 真正价格 为 原来的 销售价格  上一步执行
                                         // $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--系列促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_goods"] == true) {
                                     //2 判断商品促销(单品)
                                     $products_inst = new Products();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $item_new['goods_nums'] = $item['num'];
                                     // get prom goods 需要传参数goods_nums
                                     $prom_goods = $prom_inst->get_prom_goods($item_new);
                                     if (!empty($prom_goods)) {
                                         $prom_goods['parse'] = $prom_inst->do_prom_goods($item_new, $prom_goods);
                                         if (isset($prom_goods['parse']['note']) && $prom_goods['parse']['note'] != '') {
                                             $prom_goods['parse']['note'] = '商品优惠:' . $prom_goods['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_goods['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容 价格
                                         $item_ref['real_price'] = $prom_goods['parse']['real_price'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_goods'] = false;
                                         $item_ref['real_price'] = $item_ref['sell_price'];
                                         // 真正价格 为 原来的 销售价格
                                         $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--商品促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } elseif ($item["order_type"]["prom_series"] == true) {
                                     //3 系列促销
                                     //商品促销与系列促销叠加运算
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $note = "";
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     $prom_series = $prom_inst->get_prom_series($item_new);
                                     if (!empty($prom_series)) {
                                         $prom_series['parse'] = $prom_inst->do_prom_series($item_new, NULL, $prom_series);
                                         if (isset($prom_series['parse']['note']) && $prom_series['parse']['note'] != '') {
                                             $note .= '; 系列优惠:' . $prom_series['parse']['note'];
                                         }
                                         $amount = sprintf("%01.2f", $prom_series['parse']['real_price'] * $item["num"]);
                                         $sell_total = $item['sell_price'] * $item["num"];
                                         //合并商品与系统促销
                                         $multiple = 0;
                                         if (isset($prom_series['multiple']) && $prom_series['multiple'] >= 0) {
                                             $multiple = $prom_series['multiple'];
                                         }
                                         $prom_goods['series'] = $prom_series;
                                         // 是否有库存
                                         if ($item_new['store_nums'] <= 0) {
                                             // test OK
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 // test OK
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                         //修改ITEM内容
                                         $item_ref['real_price'] = $prom_series['parse']['real_price'];
                                         $item_ref['prom'] = $note;
                                         // $item_ref['store_nums']  = $prom_goods['store_nums'];
                                     } else {
                                         // 单品--商品促销结束
                                         $item_ref['order_type']['prom_series'] = false;
                                         // $item_ref['real_price'] = $item_ref['sell_price'];   // 真正价格 为 原来的 销售价格  上一步执行
                                         // $item_ref['prom'] = "";
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--系列促销已经结束!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 } else {
                                     // 正常的销售
                                     $products_inst = new Products();
                                     $products_item = array();
                                     $ret = $products_inst->getProduct($item['product_id']);
                                     // 获取商品信息 item = product
                                     if (isset($ret['status']) && $ret['status'] == 1) {
                                         $item_new = $ret['data'];
                                     }
                                     // 是否有库存
                                     if (isset($item_new)) {
                                         if ($item_new['store_nums'] <= 0) {
                                             $error = 1;
                                             $error_item = array("msg" => '商品:' . $item['name'] . '--库存已经没有!', "product_id" => $item['product_id']);
                                             $error_list[] = $error_item;
                                         } else {
                                             if ($item_new['store_nums'] < $item["num"]) {
                                                 $error = 1;
                                                 $error_item = array("msg" => '商品:' . $item['name'] . '--库存只有' . $item_new['store_nums'] . '个!', "product_id" => $item['product_id']);
                                                 $error_list[] = $error_item;
                                             }
                                         }
                                     } else {
                                         $error = 1;
                                         $error_item = array("msg" => '商品:' . $item['name'] . '--已经下线!', "product_id" => $item['product_id']);
                                         $error_list[] = $error_item;
                                     }
                                 }
                             }
                         }
                         $payable_amount += $item['sell_price'] * $item['num'];
                         // 成交价格
                         $real_amount += $item['real_price'] * $item['num'];
                         // 真实成交价格
                         // $payable_amount += $item['sell_total'];
                         //$real_amount += $item['amount'];
                         $weight += $item['weight'] * $item['num'];
                         $point += $item['point'] * $item['num'];
                     }
                 }
             }
             $order_bundling = null;
             $error_bd_list = array();
             if (!empty($cart_info[$ship_id]['bundling_list'])) {
                 //Tiny::log(__FILE__ . __LINE__ . "------cart info---" . var_export($cart_info, true));
                 $order_bundling =& $cart_info[$ship_id]['bundling_list'];
                 foreach ($order_bundling as $b_key => $b_val) {
                     // Tiny::log(__FILE__ . __LINE__ . "-------products item----$key----" . var_export($item, true));
                     // 判断是否存在
                     $bundling_total = 0;
                     foreach ($b_val as $v_key => $v_val) {
                         $num = $v_val['num'];
                         // 计算
                         $payable_amount += $v_val["val"]['price'] * $v_val["num"];
                         //$real_amount += $v_val["val"]['price'];  // 在item里面增加amount 项目
                         $real_amount += $v_val["val"]['price'] * $v_val["num"];
                         $bundling_total += $v_val["num"];
                         $arr_id = explode('-', $v_key);
                         //$str_ids = join(',', $arr_id);
                         $product_list = array();
                         if (!empty($arr_id)) {
                             $product_inst = new Products();
                             $ret = $product_inst->getProducts($arr_id);
                             if (isset($ret['status']) && $ret['status'] == 1) {
                                 $product_list = $ret['data'];
                             }
                         }
                         //SKM-ORDER-STORE  todo 判断库存是否足够
                         foreach ($product_list as $p_k => $p_v) {
                             if ($p_v['store_nums'] < $num) {
                                 // test OK
                                 $error = 1;
                                 $error_item = array("msg" => '套餐中商品:' . $p_v['name'] . '--库存只有' . $p_v['store_nums'] . '个!');
                                 $error_bd_list[] = $error_item;
                             }
                         }
                     }
                 }
             }
             if ($error == 1) {
                 $this->assign('error_list', $error_list);
                 $this->assign('error_bd_list', $error_bd_list);
                 // Req::args('msg', "提交订单失败");
                 //$this->redirect("/simple/cart", true, Req::args());
                 $this->redirect("/simple/cart", false);
                 exit;
             }
             // 处理整个订单
             //计算运费
             $fare = new Fare($weight);
             $payable_freight = $fare->calculate($address_id);
             $real_freight = $payable_freight;
             //计算订单优惠
             $prom_order = array();
             $discount_amount = 0;
             // order_type 购买的方式
             //if ($order_type == 0) {
             if ($prom_id) {
                 // 往Prom_Order 表中查询
                 // 这部分属于整个订单促销活动
                 $prom = new Prom($real_amount);
                 $prom_order = $model->table("prom_order")->where("id={$prom_id}")->find();
                 //防止非法会员使用订单优惠
                 $user = $this->user;
                 $group_id = ',0,';
                 if (isset($user['group_id'])) {
                     $group_id = ',' . $user['group_id'] . ',';
                 }
                 if (stripos(',' . $prom_order['group'] . ',', $group_id) !== false) {
                     $prom_parse = $prom->parsePorm($prom_order);
                     $discount_amount = $prom_parse['value'];
                     if ($prom_order['type'] == 4) {
                         $discount_amount = $payable_freight;
                     } else {
                         if ($prom_order['type'] == 2) {
                             $multiple = intval($prom_order['expression']);
                             $multiple = $multiple == 0 ? 1 : $multiple;
                             $point = $point * $multiple;
                         }
                     }
                     $data['prom'] = serialize($prom_order);
                 } else {
                     $data['prom'] = serialize(array());
                 }
             }
             // }
             //税计算
             $tax_fee = 0;
             /*
             $config = Config::getInstance();
             $config_other = $config->get('other');
             $open_invoice = isset($config_other['other_is_invoice']) ? !!$config_other['other_is_invoice'] : false;
             $tax = isset($config_other['other_tax']) ? intval($config_other['other_tax']) : 0;
             if ($open_invoice && $is_invoice) {
                 $tax_fee = $real_amount * $tax / 100;
             }
             */
             $ret = $this->cart_inst->getTaxAmountByShip($ship_id);
             if (isset($ret['status']) && $ret['status'] == 1 && $ret['data'] > 0) {
                 $tax_fee = $ret['data'];
             }
             //代金券处理
             $voucher_value = 0;
             $voucher = array();
             if ($voucher_id) {
                 $voucher = $model->table("voucher")->where("id={$voucher_id} and is_send=1 and user_id=" . $this->user['id'] . " and status = 0 and '" . date("Y-m-d H:i:s") . "' <=end_time and '" . date("Y-m-d H:i:s") . "' >=start_time and money<=" . $real_amount)->find();
                 if ($voucher) {
                     $voucher_value = $voucher['value'];
                     if ($voucher_value > $real_amount) {
                         $voucher_value = $real_amount;
                     }
                 }
             }
             if ($tax_fee <= 50) {
                 $tax_fee = 0;
             }
             //计算订单总金额
             $order_amount = $real_amount + $payable_freight + $tax_fee - $discount_amount - $voucher_value;
             $payable_amount += $payable_freight + $tax_fee;
             //填写订单
             $data['order_no'] = Common::createOrderNo();
             $data['user_id'] = $this->user['id'];
             $data['sender_name'] = $this->user['name'];
             $data['payment'] = $payment_id;
             $data['status'] = 2;
             $data['pay_status'] = 0;
             $data['accept_name'] = $address['accept_name'];
             $data['phone'] = $address['phone'];
             $data['mobile'] = $address['mobile'];
             $data['province'] = $address['province'];
             $data['city'] = $address['city'];
             $data['county'] = $address['county'];
             $data['addr'] = $address['addr'];
             $data['zip'] = $address['zip'];
             $data['payable_amount'] = $payable_amount;
             $data['payable_freight'] = $payable_freight;
             $data['real_freight'] = $real_freight;
             $data['create_time'] = date('Y-m-d H:i:s');
             $data['user_remark'] = $user_remark;
             $data['is_invoice'] = $is_invoice;
             if ($is_invoice == 1) {
                 $data['invoice_title'] = $invoice_type . ':' . $invoice_title;
             } else {
                 $data['invoice_title'] = '';
             }
             $data['taxes'] = $tax_fee;
             $data['discount_amount'] = $discount_amount;
             $data['order_amount'] = $order_amount;
             $data['real_amount'] = $real_amount;
             $data['point'] = $point;
             $data['type'] = $order_type;
             // type -> order_type
             $data['voucher_id'] = $voucher_id;
             $data['voucher'] = serialize($voucher);
             //var_dump($order_products);exit();
             // TODO SKM 写入订单数据
             $order_id = $model->table("order")->data($data)->insert();
             //写入订单商品
             // 单品 加入订单详情表
             foreach ($order_products as $goods_id => $products) {
                 foreach ($products as $product_id => $item) {
                     $tem_data = array('order_id' => '', 'goods_id' => '', 'product_id' => '', 'goods_name' => '', 'goods_price' => '', 'real_price' => '', 'goods_nums' => '', 'tax_code' => '', 'spec' => '');
                     if (isset($item["order_type"])) {
                         if (is_array($item["order_type"])) {
                             if ($item["order_type"]["flash_sale"] == true) {
                             } elseif ($item["order_type"]["prom_series"] == true) {
                                 $tem_data['prom_goods'] = serialize($item['prom_goods']);
                             } elseif ($item["order_type"]["prom_series"] == false && $item["order_type"]["prom_goods"] == true) {
                                 $tem_data['prom_goods'] = serialize($item['prom_goods']);
                             } elseif ($item["order_type"]["bundling"] == true) {
                             }
                         }
                     }
                     $tem_data['order_id'] = $order_id;
                     $tem_data['goods_id'] = $item['goods_id'];
                     $tem_data['goods_no'] = $item['goods_no'];
                     $tem_data['product_id'] = $product_id;
                     $tem_data['goods_name'] = $item['name'];
                     $tem_data['goods_price'] = $item['sell_price'];
                     $tem_data['real_price'] = $item['real_price'];
                     $tem_data['goods_nums'] = $item['num'];
                     //$tem_data['goods_weight'] = $item['weight'];
                     $tem_data['tax_code'] = $item['tax_code'];
                     // todo SKM 跟税种相关
                     $tem_data['origin_country'] = $item['origin_country'];
                     $tem_data['spec'] = serialize($item['spec']);
                     $model->table("order_goods")->data($tem_data)->insert();
                 }
             }
             // 捆绑销售 加入订单详情表
             if (!empty($cart_info[$ship_id]['bundling_list'])) {
                 $order_bundling = $cart_info[$ship_id]['bundling_list'];
                 foreach ($order_bundling as $item) {
                     $tem_data = array();
                     //$tem_data['prom_goods'] = serialize($item['prom_goods']);
                     foreach ($item as $key_bundling => $val_bundling) {
                         $bundling = $val_bundling;
                         $arr_products_id = explode('-', $key_bundling);
                         $str_products_ids = join(',', $arr_products_id);
                         $tem_data['order_id'] = $order_id;
                         $tem_data['goods_ids'] = $bundling["val"]['goods_id'];
                         $tem_data['products_ids'] = $str_products_ids;
                         //  $tem_data['goods_price'] = $item['sell_price'];
                         $tem_data['title'] = $bundling["val"]['title'];
                         $tem_data['prom_type'] = "bundling";
                         $tem_data['bundling_id'] = $bundling["val"]['id'];
                         $tem_data['real_price'] = $bundling['val']['price'];
                         $tem_data['goods_nums'] = $bundling['num'];
                         // $tem_data['goods_weight'] = $item['weight'];
                         //  $tem_data['spec'] = serialize($item['spec']);
                         $model->table("order_goods")->data($tem_data)->insert();
                     }
                 }
             }
             //优惠券锁死
             if (!empty($voucher)) {
                 $model->table("voucher")->where("id={$voucher_id} and user_id=" . $this->user['id'])->data(array('status' => 2))->update();
             }
             //清空购物车与表单缓存
             if ($order_type == 0) {
                 $this->cart_inst = Cart::getCart();
                 $this->cart_inst->clearShip($ship_id);
                 // 清空 ship_id 购物车   分库位置
                 //$cart->clear();
                 Session::clear("order_status");
             }
             $this->redirect("/simple/order_status/order_id/{$order_id}");
         } else {
             $msg = array('type' => 'fail', 'msg' => '非法提交订单!');
             $this->redirect('/index/msg', false, $msg);
         }
     } else {
         $this->redirect("login");
     }
 }
Beispiel #3
0
 public function product()
 {
     //todo 测试代码 加入购物车
     /*
     $addid = Filter::int(Req::args('addid'));
     if(isset($addid)){
         $goods_info = array("product_id" => $addid);
         $cart = Cart::getCart();
         //Tiny::log(__FILE__.__LINE__."---------------------add cart--------------------".var_export($cart, true));
         $cart->addProduct($goods_info, 1);
     }
     */
     $parse = array('直接打折', '减价优惠', '固定金额', '买就赠优惠券', '买M件送N件');
     $id = Filter::int(Req::args('id'));
     $this->assign('id', $id);
     $id = is_numeric($id) ? $id : 0;
     // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 START
     //$goods = $this->model->table("goods as go")->join("left join tiny_goods_category as gc on go.category_id = gc.id")->fields("go.*,gc.path")->where("go.id=$id and go.is_online=0")->find();
     $goods = $this->model->table("goods as go")->join("left join tiny_goods_category as gc on go.category_id = gc.id left join tiny_tax_type as ttt on go.tax_type_id = ttt.tax_type_id")->fields("go.*,gc.path,ttt.tax_type_percent")->where("go.id={$id} and go.is_online=0")->find();
     // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 END
     $order_type = array("flash_sale" => false, "prom_goods" => false, "prom_series" => false, "bundling" => false);
     //Tiny::log(__FILE__.__LINE__.var_export($goods, true));
     if ($goods) {
         // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 START
         if (!isset($goods["tax_type_percent"])) {
             $goods["tax_type_percent"] = 0;
         }
         // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 END
         $skumap = array();
         $products = $this->model->table("products")->fields("sell_price,market_price,store_nums,specs_key,pro_no,id")->where("goods_id = {$id}")->findAll();
         //Tiny::log( __FILE__.__LINE__.var_export($products, true));
         if ($products) {
             foreach ($products as $product) {
                 $skumap[$product['specs_key']] = $product;
             }
         }
         $path = trim($goods['path'], ',');
         $category = Category::getInstance();
         $childCategory = $category->getCategoryChild($path);
         $category = $this->model->table("goods_category")->where("id in ({$path})")->order("field(`id`,{$path})")->findAll();
         $time = "'" . date('Y-m-d H:i:s') . "'";
         $attr_array = unserialize($goods['attrs']);
         $goods_attrs = array();
         if ($attr_array) {
             $rows = $this->model->fields("ga.*,av.name as vname,av.id as vid")->table("goods_attr as ga")->join("left join attr_value as av on ga.id=av.attr_id")->where("ga.type_id = {$goods['type_id']}")->findAll();
             $attrs = $_attrs = array();
             foreach ($rows as $row) {
                 $attrs[$row['id'] . '-' . $row['vid']] = $row;
                 $_attrs[$row['id']] = $row;
             }
             foreach ($attr_array as $key => $value) {
                 if (isset($attrs[$key . '-' . $value])) {
                     $goods_attrs[] = $attrs[$key . '-' . $value];
                 } else {
                     $_attrs[$key]['vname'] = $value;
                     $goods_attrs[] = $_attrs[$key];
                 }
             }
             unset($attrs, $_attrs);
         }
         //评论
         $comment = array();
         $review = array('1' => 0, '2' => 0, '3' => 0, '4' => 0, '5' => 0);
         $rows = $this->model->table("review")->fields("count(id) as num,point")->where("status=1 and goods_id = {$id}")->group("point")->findAll();
         foreach ($rows as $row) {
             $review[$row['point']] = intval($row['num']);
         }
         $a = $review[4] + $review[5];
         $b = $review[3];
         $c = $review[1] + $review[1];
         $total = $a + $b + $c;
         $comment['total'] = $total;
         if ($total == 0) {
             $total = 1;
         }
         $comment['a'] = array('num' => $a, 'percent' => round(100 * $a / $total));
         $comment['b'] = array('num' => $b, 'percent' => round(100 * $b / $total));
         $comment['c'] = array('num' => $c, 'percent' => round(100 * $c / $total));
         if ($goods['seo_title'] != '') {
             $seo_title = $goods['seo_title'];
         } else {
             if ($goods['name'] != '') {
                 $seo_title = $goods['name'];
             }
         }
         if ($seo_title != '') {
             $this->assign('seo_title', $seo_title);
         }
         if ($goods['seo_keywords'] != '') {
             $this->assign('seo_keywords', $goods['seo_keywords']);
         }
         if ($goods['seo_description'] != '') {
             $this->assign('seo_description', $goods['seo_description']);
         }
         // 2 商品促销
         $goods['goods_nums'] = PHP_INT_MAX;
         $prom_inst = new Prom();
         // 1 限时抢购   与下面的冲突  优先级最高
         // 2 捆绑销售   单独分支
         // 3 商品促销   与 4 系列促销 叠加处理
         //4  系列促销
         $prom_goods = NULL;
         $prom_series = NULL;
         $goods_info = array("goods_id" => $goods["id"], "prom_id" => $goods["prom_id"], "ship_id" => $goods["ship_id"], "series_id" => $goods["series_id"], "sell_price" => $goods["sell_price"], "goods_nums" => $goods['goods_nums']);
         $flash_sale = array();
         $ret = $prom_inst->get_flash_sale($goods_info);
         if ($ret["status"] == 1 && isset($ret["data"])) {
             $flash_sale = $ret["data"];
         }
         if ($flash_sale) {
             $this->assign("flash_sale", $flash_sale);
             $order_type["flash_sale"] = true;
         } else {
             // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 START
             $goods["real_price"] = $goods["sell_price"];
             // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 END
             $prom_goods = $prom_inst->get_prom_goods($goods_info);
             //Tiny::log(__FILE__.__LINE__.var_export($prom_goods, true));
             if (!empty($prom_goods)) {
                 $prom_goods['parse'] = $prom_inst->do_prom_goods($goods_info, $prom_goods);
                 // 商品促销
                 $order_type["prom_goods"] = true;
                 // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 START
                 $goods["real_price"] = $prom_goods['parse']["real_price"];
                 if ($goods["sell_price"] == $goods["real_price"]) {
                     $order_type["prom_goods"] = false;
                 }
                 // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 END
             }
             // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 START
             //$prom_series_item = $prom_inst->get_prom_series($goods_info, $prom_goods);
             //if (!empty($prom_series_item)) {
             //$prom_goods['parse'] = $prom_inst->do_prom_goods($goods, $prom_goods); // 商品促销
             $prom_series = $prom_inst->get_prom_series($goods_info, $prom_goods);
             // 系列促销
             if (!empty($prom_series)) {
                 //$prom_series = $prom_inst->do_prom_series($goods_info, $prom_goods, $prom_series_item);
                 $prom_series["parse"] = $prom_inst->do_prom_series($goods_info, $prom_goods, $prom_series);
                 // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 END
                 $order_type["prom_series"] = true;
                 // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 START
                 $goods["real_price"] = $prom_series['parse']["real_price"];
                 if ($goods["sell_price"] == $goods["real_price"]) {
                     $order_type["prom_series"] = false;
                 }
                 // EC 变更 2015-06-04 10:16 抢购以外的场合,促销价,销售价,优惠信息的修正 END
             }
         }
         //Tiny::log( __FILE__.__LINE__."--flash_sale--".var_export($flash_sale, true));
         //Tiny::log( __FILE__.__LINE__."--goods--".var_export($prom_goods, true));
         //Tiny::log( __FILE__.__LINE__."--series--".var_export($prom_series, true));
         //售后保障
         $sale_protection = $this->model->table('help')->where("title='售后保障'")->find();
         if ($sale_protection) {
             $this->assign("sale_protection", $sale_protection['content']);
         }
         $this->assign("child_category", $childCategory);
         $this->assign("prom_g", $prom_goods);
         $this->assign("prom", $prom_series);
         $this->assign("order_type", $order_type);
         $this->assign("flash_sale", $flash_sale);
         $this->assign("goods", $goods);
         $this->assign("ship_id", $goods["ship_id"]);
         $this->assign("goods_attrs", $goods_attrs);
         $this->assign("category_nav", $category);
         $this->assign("skumap", $skumap);
         $this->assign("comment", $comment);
         // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 START
         //            $tax_amount = 0;
         //            if ($order_type["flash_sale"]) {
         //                $tax_amount = $this->checkProductTax_p($goods["ship_id"], $flash_sale['price'], $goods["tax_type_percent"], 1);
         //            } else {
         //                $tax_amount = $this->checkProductTax_p($goods["ship_id"], $goods["real_price"], $goods["tax_type_percent"], 1);
         //            }
         $tax_amount = $this->checkProductTax_p($goods["ship_id"], $goods["sell_price"], $goods["tax_type_percent"], 1);
         $this->assign("taxAmount", $tax_amount);
         // EC 变更 2015-06-16 14:58 关税大于50元,提示信息表示 END
         // 是否过了促销期
         $instFlashSale = new FlashSale();
         Tiny::log("             id       " . var_export($id, true));
         $goodSel = $instFlashSale->getFlashSale($id);
         if ($goodSel != null) {
             $sTimeEnd = $goodSel['end_time'];
             $sTimeNow = date("Y-m-d H:i:s");
             Tiny::log("id        " . var_export($id, true));
             Tiny::log("now        " . var_export(strtotime($sTimeNow), true));
             Tiny::log("end        " . var_export(strtotime($sTimeEnd), true));
             if (strtotime($sTimeNow) > strtotime($sTimeEnd)) {
                 $this->assign("OnFlashTime", false);
             } else {
                 $this->assign("OnFlashTime", true);
             }
         } else {
             $this->assign("OnFlashTime", false);
         }
         $this->redirect();
     } else {
         Tiny::Msg($this, "404");
     }
 }