コード例 #1
0
ファイル: FlashSale.php プロジェクト: sammychan1981/quanpin
 public function getFlashSaleWithProducts()
 {
     $model = new Model("flash_sale");
     // $productSel = $model->limit(1)->fields("tiny_flash_sale.*, tiny_goods.name, tiny_goods.store_nums left join tiny_goods")->find();
     $productSel = $model->fields("*")->findAll();
     if ($productSel) {
         Tiny::log($productSel);
         return $productSel;
     } else {
         return NULL;
     }
 }
コード例 #2
0
ファイル: Bundling.php プロジェクト: sammychan1981/quanpin
 public function getBundlingList($ids)
 {
     $products = array();
     // $model = new Model("products as pr");
     Tiny::log(__FILE__ . __LINE__ . "------product---id----{$ids}---" . var_export($ids, true));
     if ($ids != '') {
         $str_ids = trim(implode(",", $ids), ',');
         $products = $this->model->fields("pr.*,go.img,go.name,go.prom_id,go.point,go.series_id as series_id, go.ship_id as ship_id")->join("left join goods as go on pr.goods_id = go.id ")->where("pr.id in({$str_ids})")->findAll();
         return $products;
     } else {
         return NULL;
     }
 }
コード例 #3
0
ファイル: api.php プロジェクト: sammychan1981/quanpin
 public function get_pic_url()
 {
     $this->apiModel = new ApiModel();
     // 取得欢迎页面图片的URL
     $data = $this->apiModel->getWelPicUrl();
     $url = $data['url'];
     Tiny::log($url);
     $retData = array("modifiedTime" => "", "imgUrl" => "");
     if (isset($url)) {
         $picUrl = Url::fullUrlFormat("/{$url}");
         Tiny::log($picUrl);
         $picTime = strtotime($data['last_update_time']);
         $time = date('YmdHis', $picTime);
         $retData["modifiedTime"] = $time;
         $retData["imgUrl"] = $picUrl;
     }
     //        echo  JSON::encode($retData,JSON_UNESCAPED_SLASHES);
     echo json_encode($retData, JSON_UNESCAPED_SLASHES);
 }
コード例 #4
0
ファイル: gateway.php プロジェクト: sammychan1981/quanpin
    private function returnXML($success = "true", $errorCode = "", $errorMsg = "")
    {
        echo '<?xml version="1.0" encoding="UTF-8" ?>
		        <response>
		        <success>' . $success . '</success>
			    <errorCode>' . $errorCode . '</errorCode>
			    <errorMsg>' . $errorMsg . '</errorMsg>
		    </response>';
        Tiny::log("returnXML【success:" . $success . "】errorCode【" . $errorCode . "】errorMsg【" . $errorMsg . "】");
        exit;
    }
コード例 #5
0
ファイル: simple.php プロジェクト: sammychan1981/quanpin
 public function order_info()
 {
     $id = Filter::int(Req::args('id'));
     $pids = Req::args('pid');
     $type = Req::args("type");
     $ship_id = 0;
     $num = Req::args('num');
     if ($num == NULL || $num == "") {
         $num = 1;
     }
     if ($this->checkOnline()) {
         if ($type == 'bundbuy') {
             $ship_id = NULL;
             //确认捆绑存在有效且所有的商品都在其中包括个数完全正确
             $pids = trim($pids, "-");
             $product_id_array = explode("-", $pids);
             foreach ($product_id_array as $key => $val) {
                 $product_id_array[$key] = Filter::int($val);
             }
             $product_ids = implode(',', $product_id_array);
             $product_id = implode('-', $product_id_array);
             $model = new Model("bundling");
             $bundling = $model->where("id={$id}")->find();
             if ($bundling) {
                 $goods_id_array = explode(',', $bundling['goods_id']);
                 $goods_inst = new Goods();
                 $ret = $goods_inst->getGoodsProducts($product_ids);
                 if (isset($ret['status']) && $ret['status'] == 1) {
                     $products = $ret['data'];
                 }
                 //检测库存与防偷梁换柱
                 // $tax_account = 0;
                 $store_nums = 10;
                 // 初始化为10
                 foreach ($products as $key => $value) {
                     // 处理products的ship_id  取第一个产品的ship_id
                     if ($key == 0 && isset($value["ship_id"]) && $value["ship_id"] != NULL) {
                         $ship_id = $value["ship_id"];
                     }
                     if ($value['store_nums'] <= 0 || !in_array($value['goods_id'], $goods_id_array)) {
                         $this->redirect("/index/bundbuy/id/{$id}");
                     }
                     if ($store_nums > $value['store_nums']) {
                         $store_nums = $value['store_nums'];
                     }
                     // $tax_account  += $value['sell_price'] * $value['tax_type_percent'];
                 }
                 $max_nums = $store_nums;
                 if ($ship_id == NULL) {
                     Tiny::log(__FILE__ . __LINE__ . "ship_id 不存在!");
                 }
                 $this->assign("ship_id", $ship_id);
                 $products_inst = new Products();
                 if (count($goods_id_array) == count($products)) {
                     $product = $products_inst->packBundbuyProducts($products);
                     $this->assign("product", $product);
                     $this->assign("bund", $bundling);
                 } else {
                     $this->redirect("/index/bundbuy/id/{$id}");
                 }
                 $goods_info = array();
                 $goods_info["bundling_id"] = $id;
                 $goods_info["products_ids"] = $pids;
                 $goods_info["bundling"] = $bundling;
                 $goods_info["ship_id"] = $ship_id;
                 $goods_info["products"] = $products;
                 // 套餐总数量 允许最多买的数量   store_nums , max_num 存放在 bundling中
                 $goods_info['store_nums'] = $store_nums;
                 $goods_info['max_nums'] = $max_nums;
                 $this->cart_inst = Cart::getCart();
                 //Tiny::log(__FILE__.__LINE__."--before bundling to cart---".var_export($cart, true));
                 $this->cart_inst->addBundling($goods_info, $num);
                 // Tiny::log(__FILE__.__LINE__."--add bundling to cart---".var_export($cart, true));
             } else {
                 $this->redirect("/index/msg", true, array('msg' => '你提交的套餐不存在!', 'type' => 'error'));
             }
         }
         $this->assign("id", $id);
         $this->assign("order_type", $type);
         $this->assign("pid", $product_id);
         $this->parserOrder($ship_id);
         $this->redirect("/simple/cart");
     } else {
         $this->redirect("login");
     }
 }
コード例 #6
0
ファイル: ajax.php プロジェクト: sammychan1981/quanpin
 /**
  * 生成短信验证码接口
  * AJAX
  * apikey 为云片分配的apikey
  * text 为短信内容
  * mobile 为接受短信的手机号
  */
 public function send_auth_code()
 {
     $info = array('status' => false, 'msg' => '验证码发送失败!');
     // $apikey = "06ec231c5d876ffe119b38013662f661";   // todo  短信接口部署时,需修改这里的APIKEY
     $phoneNumber = Filter::int(Req::args("mobile"));
     $config_inst = Config::getInstance();
     $config = $config_inst->get("sms");
     $apikey = $config['api_key'];
     $authChars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     //验证码生成
     $authCode = '';
     for ($i = 0; $i < 4; $i++) {
         $authCode .= substr($authChars, mt_rand(0, strlen($authChars) - 1), 1);
     }
     $authCode = strtolower($authCode);
     // 变成小写
     // $text = "【全品电台】您的验证码是".$authCode;
     $text = "【全品电台】感谢您的注册,您的验证码是 {$authCode} 。有效期为3分钟,请尽快验证";
     //$text = "【云片网】您的验证码是".$authCode;
     Tiny::log(__FILE__ . '--' . __LINE__ . '--' . $phoneNumber . "--" . $authCode . "--" . $text);
     //验证码与手机号码绑定
     $model = $this->model->table("auth_code");
     $obj = $model->where('phone_number=' . $phoneNumber)->find();
     $time = date('Y-m-d H:i:s', strtotime("+3 minutes"));
     if ($obj == null) {
         $data['phone_number'] = $phoneNumber;
         $data['auth_code'] = $authCode;
         $data['start_time'] = date('Y-m-d H:i:s');
         $data['end_time'] = $time;
         $auth_code_id = $this->model->table("auth_code")->data($data)->insert();
         if ($auth_code_id) {
             //发送验证码,发送成功
             //Tiny::log("auth_code 表 ID--".$auth_code_id);
             // todo SKM 要发短信验证码时,把下面注释去掉
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             // todo SKM SMS服务正式提供后,把下面一行代码注释掉
             //$ret = array('code' => 0, 'msg' => 'OK');
             if (isset($ret['code']) && $ret['code'] == 0) {
                 $info['status'] = true;
                 //$info['msg'] = "发送验证码成功!短信API接口返回:".$ret['msg'];
                 $info['msg'] = "发送验证码成功!";
             } else {
                 $info['status'] = false;
                 //$info['msg'] = "发送验证码失败!短信API接口返回:".$ret['msg'];
                 Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "短信接口发送失败:" . var_export($ret, true));
                 $info['msg'] = "发送验证码失败!";
             }
             echo JSON::encode($info);
         } else {
             // 插入失败
             Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "插入失败:auth_code--" . $auth_code_id);
             echo JSON::encode($info);
         }
     } else {
         // 1分钟内不能发送2次验证码
         $expired_time = strtotime("+3 minutes", intval($obj['start_time']));
         if ($expired_time > strtotime(date('y-m-d h:i:s'))) {
             $info['status'] = false;
             $info['msg'] = "两次验证码发送间隔不能少于60秒!";
             echo JSON::encode($info);
         } else {
             // 已经存在验证码,更新验证码, 从新发送到手机上
             $obj['auth_code'] = $authCode;
             $obj['start_time'] = date('Y-m-d H:i:s');
             $obj['end_time'] = $time;
             $model->data($obj)->update();
             // 重新发送
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             //$ret = array('code' => 0, 'msg' => 'OK');
             $info['status'] = true;
             $info['msg'] = "发送验证码成功!";
             echo JSON::encode($info);
         }
     }
 }
コード例 #7
0
ファイル: Cart.php プロジェクト: sammychan1981/quanpin
 public function all()
 {
     // 计算税金
     foreach ($this->items as $ship_id => $ship_item) {
         $ret = $this->getTaxAmountByShip($ship_id);
         if (isset($ret['status']) && $ret['status'] == 1) {
             $this->items[$ship_id]['tax_amount'] = $ret['data'];
         } else {
             $this->items[$ship_id]['tax_amount'] = 0;
         }
     }
     Tiny::log(__FILE__ . __LINE__ . "------------carts----------" . var_export($this->items, true));
     return $this->items;
 }
コード例 #8
0
ファイル: tiny.php プロジェクト: sammychan1981/quanpin
 /**
  * 处理错误机制
  * 
  * @access public
  * @param mixed $code 错误代码 
  * @param mixed $message 错误信息
  * @param mixed $file 错误文件
  * @param mixed $line 行号
  * @param mixed $errContext 错误内容
  * @return void
  */
 public static function handleError($code, $message, $file, $line, $errContext)
 {
     //页面中正确运行的部分
     if (ob_get_length() > 0) {
         ob_end_clean();
     }
     $errorStack = null;
     if ($code & error_reporting()) {
         restore_error_handler();
         restore_exception_handler();
         $log = "{$message} (" . str_replace(TINY_ROOT, "", $file) . ":{$line})\r\nStack trace:\r\n";
         $trace = debug_backtrace();
         self::paseErrorTrace($trace, $log);
         $errorStack = $trace;
     }
     try {
         $errorType;
         switch ($code) {
             case E_ERROR:
                 $errorType = 'ERROR';
                 break;
             case E_WARNING:
                 $errorType = 'WARNING';
                 break;
             case E_NOTICE:
                 $errorType = 'NOTICE';
                 break;
             case E_USER_ERROR:
                 $errorType = 'USER_ERROR';
                 break;
             case E_USER_WARNING:
                 $errorType = 'USER_WARNING';
                 break;
             case E_USER_NOTICE:
                 $errorType = 'USER_NOTICE';
                 break;
             case E_PARSE:
                 $errorType = 'PARSE_ERROR';
                 break;
             default:
                 $errorType = 'UNKNOWN';
                 break;
         }
         if (isset($log)) {
             Tiny::log($log, $errorType);
         }
         $error_file = new File($file);
         $codes = $error_file->gets($line);
         if (defined("APP_ROOT")) {
             $file = str_replace(APP_ROOT, "", $file);
         }
         $file = str_replace(TINY_ROOT, "", $file);
         $datas = array('errorType' => $errorType, 'file' => $file, 'line' => $line, 'codes' => htmlspecialchars($codes), 'errorStack' => $errorStack, 'errorContent' => $errContext);
         $error = new Error(Tiny::app(), $message, null, $datas);
         if ($error) {
             $error->handle();
             exit;
         } else {
             self::displayError($code, $message, $file, $line);
         }
     } catch (Exception $e) {
         self::displayException($e);
     }
     exit;
 }
コード例 #9
0
ファイル: index.php プロジェクト: sammychan1981/quanpin
 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");
     }
 }