Esempio n. 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'];
 }