示例#1
0
 /**
  * 获取当前用户的订单列表
  */
 public function getOrderList()
 {
     $userId = $this->getUserId();
     $m = M('orders');
     $status = I('status', -999);
     $sql = "select o.payType,o.orderId,o.orderNo,o.orderStatus,o.needPay,o.createTime,o.totalMoney,s.shopName,s.shopId \n\t\t    from __PREFIX__orders o,__PREFIX__shops s WHERE o.shopId=s.shopId and o.userId={$userId} AND orderFlag=1 ";
     if ($status != -999) {
         //待付款
         if ($status == -2) {
             $sql .= " and orderStatus=-2";
         }
         //待受理
         if ($status == 0) {
             $sql .= " and orderStatus=0";
         }
         //待收货
         if ($status == 3) {
             $sql .= " and orderStatus in(1,2,3)";
         }
         //未评价
         if ($status == 4) {
             $sql .= " and orderStatus in(4,5) and isAppraises=0 ";
         }
         //已消费
         if ($status == 5) {
             $sql .= " and orderStatus = 5 ";
         }
     }
     $sql .= " order by o.orderId desc";
     $rs = $m->pageQuery($sql);
     //獲取這些訂單下的商品信息
     if (count($rs['root']) > 0) {
         $ids = array();
         foreach ($rs['root'] as $key => $v) {
             $ids[] = $v['orderId'];
         }
         $sql = "select og.goodsThums,og.goodsId,og.goodsName,og.orderId,og.goodsNums,og.goodsPrice\n\t\t\t    from __PREFIX__order_goods og\n\t\t\t    where og.orderId in(" . implode(',', $ids) . ") ";
         $grs = $m->query($sql);
         $ogrs = array();
         foreach ($grs as $v) {
             $ogrs[$v['orderId']][] = $v;
         }
         //合并数据
         foreach ($rs['root'] as $key => $v) {
             $ogrs['goodsThums'] = WSTMoblieImg($ogrs['goodsThums']);
             $rs['root'][$key]['data'] = $ogrs[$v['orderId']];
         }
     }
     return $rs;
 }
示例#2
0
 /**
  * 获取广告
  */
 public function getAds($areaId2, $adType)
 {
     //获取所在省份
     $sql = "select parentId from " . $this->tablePrefix . "areas where areaId=" . $areaId2;
     $rs = $this->queryRow($sql);
     $areaId1 = $rs['parentId'];
     $today = date("Y-m-d");
     $sql = "select * from " . $this->tablePrefix . "ads WHERE (areaId2 = {$areaId2} or areaId1 = 0 or areaId1=" . $areaId1 . ")\n\t\t\t\tAND adStartDate<='{$today}' AND adEndDate >='{$today}' and adPositionId=" . $adType . " order by adSort asc";
     $rs = $this->query($sql);
     $data = array();
     foreach ($rs as $key => $v) {
         $rs[$key]['adFile'] = WSTMoblieImg($v['adFile']);
         $data[] = $rs[$key];
     }
     return $data;
 }
 /**
  * 商品列表
  */
 public function getGoodsList()
 {
     $areaId2 = session('areaId2');
     $goodsCatId1 = (int) I('goodsCatId1');
     $goodsCatId2 = (int) I('goodsCatId2');
     $goodsCatId3 = (int) I('goodsCatId3');
     $currPage = (int) I("currPage", 0);
     $key = I('key');
     $brandId = (int) I('brandId');
     $pageSize = (int) (I('pageSize') ? I('pageSize') : 10);
     $sortArr = array('desc' => array('shopPrice', 'saleCount', 'totalScore'), 'descType' => array('asc', 'desc'));
     $latitude = session('wstRealLatitude');
     $latitude = $latitude != '' ? $latitude : 0;
     $longitude = session('wstRealLongitude');
     $longitude = $longitude != '' ? $longitude : 0;
     $sql = "select s.shopName,s.shopId,g.goodsId,g.goodsName,g.goodsThums,g.shopPrice,fn_getDistance(s.longitude,s.latitude," . $longitude . "," . $latitude . ") as userDistance,gs.totalScore,gs.totalUsers,\n\t\t        g.goodsStock,s.deliveryStartMoney,ga.id goodsAttrId,ga.attrStock,ga.attrPrice \n\t\t        from __PREFIX__goods g left join __PREFIX__goods_attributes ga on g.goodsId=ga.goodsId and ga.isRecomm=1\n\t\t        left join __PREFIX__goods_scores gs on gs.goodsId=g.goodsId ,__PREFIX__shops s\n\t \t           where g.shopId=s.shopId and s.shopFlag=1 and s.shopStatus=1 and g.goodsStatus=1 and g.goodsFlag=1 and g.isSale=1 ";
     if ($key != '') {
         $sql .= " and g.goodsName like '%" . $key . "%' ";
     }
     if ($goodsCatId1 > 0) {
         $sql .= " and g.goodsCatId1=" . $goodsCatId1;
     }
     if ($goodsCatId2 > 0) {
         $sql .= " and g.goodsCatId2=" . $goodsCatId2;
     }
     if ($goodsCatId3 > 0) {
         $sql .= " and g.goodsCatId3=" . $goodsCatId3;
     }
     if ($brandId > 0) {
         $sql .= " and g.brandId=" . $brandId;
     }
     $sql .= " order by " . $sortArr['desc'][(int) I('desc')] . " " . $sortArr['descType'][(int) I('descType')];
     $page = $this->pageQuery($sql, $currPage, $pageSize);
     if (count($page['root']) > 0) {
         foreach ($page['root'] as $key => $v) {
             $page['root'][$key]['goodsThums'] = WSTMoblieImg($v['goodsThums']);
             $page['root'][$key]['score'] = round($v['totalScore'] / $v['totalUsers'], 1);
             if ($page['root'][$key]['goodsAttrId'] > 0) {
                 $page['root'][$key]['goodsStock'] = $v['attrStock'];
                 $page['root'][$key]['shopPrice'] = $v['attrPrice'];
             }
             unset($page['root'][$key]['attrStock'], $page['root'][$key]['attrPrice'], $page['root'][$key]['totalScore'], $page['root'][$key]['totalUsers']);
         }
     }
     return $page;
 }
示例#4
0
/**
 * 获取首页分类及商品
 */
function WSTCatsAndGoods($areaId2)
{
    $m = M('goods_cats');
    $rs1 = S("WST_CACHE_GOODS_CAT_GOODS_WP_" . $areaId2);
    if (!$cats) {
        //查询一级分类
        $sql = "select catId,catName from __PREFIX__goods_cats WHERE parentId = 0 AND isShow =1 AND catFlag = 1 order by catSort asc limit 6";
        $rs1 = $m->query($sql);
        foreach ($rs1 as $key => $v) {
            $ids = array();
            $ids[] = $v['catId'];
            //查询二级分类
            $sql = "select catId from __PREFIX__goods_cats WHERE parentId in(" . implode(',', $ids) . ") AND isShow =1 AND catFlag = 1 order by catSort asc ";
            $rs2 = $m->query($sql);
            $ids = array();
            foreach ($rs2 as $v2) {
                $ids[] = $v2['catId'];
            }
            //查询三级分类
            $sql = "select catId from __PREFIX__goods_cats WHERE parentId in(" . implode(',', $ids) . ") AND isShow =1 AND catFlag = 1 order by catSort asc ";
            $rs3 = $m->query($sql);
            $ids = array();
            foreach ($rs3 as $v3) {
                $ids[] = $v3['catId'];
            }
            //查询三级分类下的商品
            $sql = "SELECT sp.shopName,sp.shopId , g.goodsCatId1,g.goodsId , g.goodsName,g.goodsThums,g.shopPrice,ga.id goodsAttrId,ga.attrPrice\n\t\t\t\t\t\tFROM __PREFIX__goods g left join __PREFIX__goods_attributes ga on g.goodsId=ga.goodsId and ga.isRecomm=1,__PREFIX__shops sp\n\t\t\t\t\t\tWHERE g.shopId = sp.shopId AND sp.shopStatus = 1 AND g.goodsFlag = 1 AND g.isAdminBest = 1 AND g.isSale = 1 \n\t\t\t\t\t\tAND g.goodsStatus = 1 AND g.goodsCatId3 in(" . implode(',', $ids) . ") AND sp.areaId2={$areaId2}\n\t\t\t\t\t\torder by g.saleCount desc limit 6";
            $goods = $m->query($sql);
            foreach ($goods as $key2 => $v) {
                $goods[$key2]['goodsThums'] = WSTMoblieImg($v['goodsThums']);
                if ($goods[$key2]['goodsAttrId'] > 0) {
                    $goods[$key2]['goodsStock'] = $goods[$key2]['attrStock'];
                    $goods[$key2]['shopPrice'] = $goods[$key2]['attrPrice'];
                    unset($goods['attrStock'], $goods['attrPrice']);
                } else {
                    $goods[$key2]['goodsAttrId'] = 0;
                }
            }
            $rs1[$key]['data'] = $goods;
        }
        S("WST_CACHE_GOODS_CAT_GOODS_WP_" . $areaId2, $rs1, 31536000);
    }
    return $rs1;
}
 /**
  * 获取订单详情
  */
 public function getOrderDetails()
 {
     $USER = session('WST_USER');
     $userId = (int) $USER['userId'];
     $shopId = (int) $USER['shopId'];
     $orderId = (int) I("orderId");
     $data = array();
     $morders = D('Mobile/Orders');
     $sql = "SELECT * FROM __PREFIX__orders WHERE orderId = {$orderId} and (userId=" . $userId . " or shopId=" . $shopId . ")";
     $order = $this->queryRow($sql);
     if (empty($order)) {
         return $data;
     }
     $data["order"] = $order;
     $sql = "select og.orderId, og.goodsId ,g.goodsSn, og.goodsNums, og.goodsName , og.goodsPrice shopPrice,og.goodsThums,og.goodsAttrName,og.goodsAttrName \n\t\t\t\tfrom __PREFIX__goods g , __PREFIX__order_goods og \n\t\t\t\tWHERE g.goodsId = og.goodsId AND og.orderId = {$orderId}";
     $goods = $this->query($sql);
     if (!empty($goods)) {
         foreach ($goods as $k => $v) {
             $goods[$k]['goodsThums'] = WSTMoblieImg($v['goodsThums']);
             $goods[$k]['money'] = $v['goodsNums'] * $v['shopPrice'];
         }
     }
     $data["goodsList"] = $goods;
     for ($i = 0; $i < count($ogoodsList); $i++) {
         $sgoods = $ogoodsList[$i];
         $sql = "update __PREFIX__goods set goodsStock=goodsStock+" . $sgoods['goodsNums'] . " where goodsId=" . $sgoods["goodsId"];
         $this->execute($sql);
     }
     $sql = "SELECT * FROM __PREFIX__log_orders WHERE orderId = {$orderId} ";
     $logs = $this->query($sql);
     $data["logs"] = $logs;
     return $data;
 }
 /**
  * 获取商家商品列表
  */
 public function getShopGoodsList($shopId)
 {
     $shopCatId1 = (int) I('shopCatId1');
     $shopCatId2 = (int) I('shopCatId2');
     $startPrice = (double) I('startPrice');
     $endPrice = (double) I('endPrice');
     $latitude = session('wstRealLatitude');
     $latitude = $latitude != '' ? $latitude : 0;
     $longitude = session('wstRealLongitude');
     $longitude = $longitude != '' ? $longitude : 0;
     $currPage = (int) I("currPage", 0);
     $pageSize = (int) (I('pageSize') ? I('pageSize') : 10);
     $desc = I('desc') != '' ? (int) I('desc') : 1;
     $descType = I('descType') != '' ? (int) I('descType') : 1;
     if ($shopId == 0) {
         return array();
     }
     $sortArr = array('code' => array('saleCount', 'shopPrice', 'totalScore'), 'descType' => array('asc', 'desc'));
     $sql = "select g.goodsId,g.goodsName,g.goodsThums,g.shopPrice,sh.shopName,g.shopId,sh.deliveryStartMoney,sh.deliveryFreeMoney,\n\t\t        fn_getDistance(sh.longitude,sh.latitude," . $longitude . "," . $latitude . ") as userDistance,g.goodsStock,ga.id goodsAttrId,ga.attrStock,ga.attrPrice,totalScore,totalUsers\n\t\t        from __PREFIX__goods g left join __PREFIX__goods_attributes ga on g.goodsId=ga.goodsId and ga.isRecomm=1\n\t \t        left join __PREFIX__goods_scores gs on g.goodsId=gs.goodsId and g.shopId=gs.shopId,__PREFIX__shops sh\n\t \t        where g.shopId=sh.shopId and g.goodsStatus=1 and g.goodsFlag=1 and isSale=1 and g.shopId=" . $shopId;
     if ($shopCatId1 > 0) {
         $sql .= " and g.shopCatId1=" . $shopCatId1;
     }
     if ($shopCatId2 > 0) {
         $sql .= " and g.shopCatId2=" . $shopCatId2;
     }
     if ($startPrice > 0) {
         $sql .= " and g.shopPrice>=" . $startPrice;
     }
     if ($endPrice > 0) {
         $sql .= " and g.shopPrice<=" . $endPrice;
     }
     $sql .= " order by " . $sortArr['code'][$desc] . " " . $sortArr['descType'][$descType];
     $page = $this->pageQuery($sql, $currPage, $pageSize);
     if (count($page['root']) > 0) {
         foreach ($page['root'] as $key => $v) {
             $page['root'][$key]['goodsThums'] = WSTMoblieImg($v['goodsThums']);
             $page['root'][$key]['totalScore'] = round($v['totalScore'] / $v['totalUsers'], 1);
             if ($page['root'][$key]['goodsAttrId'] > 0) {
                 $page['root'][$key]['goodsStock'] = $v['attrStock'];
                 $page['root'][$key]['shopPrice'] = $v['attrPrice'];
             }
             unset($page['root'][$key]['attrStock'], $page['root'][$key]['attrPrice'], $page['root'][$key]['totalUsers']);
         }
     }
     return $page;
 }
示例#7
0
 /**
  * 结算-获取商品分组列表
  */
 public function groupGoodsForOrder()
 {
     $userId = $this->getUserId();
     $goodsIds = trim(I('goodsIds'));
     if ($goodsIds == '') {
         return array();
     }
     $goodsIds = explode(';', $goodsIds);
     $shopIds = array();
     $shopGoodsMap = array();
     //获取商品信息
     foreach ($goodsIds as $v) {
         $tmp = explode('_', $v);
         $goodsId = (int) $tmp[0];
         $goodsAttrId = (int) $tmp[1];
         $goodsNum = (int) $tmp[2];
         $sql = "SELECT  g.shopId,g.goodsThums,g.goodsId,g.shopPrice,g.isBook,g.goodsName,g.shopId,g.goodsStock,\n\t\t\t            ga.id goodsAttrId,ga.attrPrice,ga.attrStock,ga.attrVal,a.attrName ,g.goodsSn\n\t\t\t\t        FROM __PREFIX__goods g left join __PREFIX__goods_attributes ga on g.goodsId=ga.goodsId and ga.id=" . $goodsAttrId . "\n\t\t\t\t\t\tleft join __PREFIX__attributes  a on a.attrId=ga.attrId\n\t\t\t\t\t\tWHERE g.goodsId = {$goodsId} AND g.goodsFlag = 1 and g.isSale=1 and g.goodsStatus=1";
         $goods = $this->queryRow($sql);
         $goods['goodsThums'] = WSTMoblieImg($goods['goodsThums']);
         $goods['goodsNum'] = $goodsNum;
         if (empty($goods)) {
             continue;
         }
         if ($goods['goodsAttrId'] > 0) {
             $goods['shopPrice'] = $goods['attrPrice'];
             $goods['goodsStock'] = $goods['attrStock'];
             $goods['goodsName'] = $goods['goodsName'] . "【" . $goods['attrName'] . ":" . $goods['attrVal'] . "】";
         }
         unset($goods['goodsAttrId'], $goods['attrPrice'], $goods['attrStock']);
         if (!in_array($goods['shopId'], $shopIds)) {
             $shopIds[] = $goods['shopId'];
         }
         $shopGoodsMap[$goods['shopId']][] = $goods;
     }
     if (empty($shopGoodsMap)) {
         return array();
     }
     //获取店铺数据
     $sql = "select shopId,shopName,deliveryType,shopAtive,deliveryTime,isInvoice,deliveryMoney,deliveryFreeMoney,\n\t\t       deliveryStartMoney,serviceStartTime,serviceEndTime from __PREFIX__shops where shopStatus=1 and shopFlag=1 and shopId in(" . implode(',', $shopIds) . ")";
     $shopRs = $this->query($sql);
     //获取店铺配送的社区
     $sql = "select shopId,communityId from __PREFIX__shops_communitys where shopId in(" . implode(',', $shopIds) . ")";
     $communityRs = $this->query($sql);
     $shopCommunityRs = array();
     foreach ($communityRs as $v) {
         $shopCommunityRs[$v['shopId']][] = $v['communityId'];
     }
     //组合数据
     $shops = array();
     $reachStartTime = $reachEndTime = array();
     foreach ($shopRs as $v) {
         $shops[$v['shopId']]['shopInfo'] = $v;
         $shops[$v['shopId']]['goods'] = $shopGoodsMap[$v['shopId']];
         $shops[$v['shopId']]['communitys'] = $shopCommunityRs[$v['shopId']];
         if (strpos($v["serviceStartTime"], '.5')) {
             $shops[$v['shopId']]['shopInfo']['serviceStartTime'] = str_replace('.5', ':30', $v["serviceStartTime"]);
         }
         if (strpos($v["serviceStartTime"], '.0')) {
             $shops[$v['shopId']]['shopInfo']['serviceStartTime'] = str_replace('.0', ':00', $v["serviceStartTime"]);
         }
         if (strpos($v["serviceEndTime"], '.5')) {
             $shops[$v['shopId']]['shopInfo']['serviceEndTime'] = str_replace('.5', ':30', $v["serviceEndTime"]);
         }
         if (strpos($v["serviceEndTime"], '.0')) {
             $shops[$v['shopId']]['shopInfo']['serviceEndTime'] = str_replace('.0', ':00', $v["serviceEndTime"]);
         }
         $reachStartTime[] = $v['serviceStartTime'];
         $reachEndTime[] = $v['serviceEndTime'];
     }
     //再取出组合
     $rshops = array();
     foreach ($shops as $v) {
         $rshops[] = $v;
     }
     rsort($reachStartTime);
     sort($reachEndTime);
     $reachTime = array($reachStartTime[0], $reachEndTime[0]);
     //各店铺营业时间的交集,用来确定订单的期望送达时间的范围
     return array('cartInfo' => $rshops, 'reachTime' => $reachTime);
 }