Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

BIN
hyhproject/app/model/.DS_Store vendored Executable file

Binary file not shown.

BIN
hyhproject/app/model/._.DS_Store Executable file

Binary file not shown.

BIN
hyhproject/app/model/._Goods.php Executable file

Binary file not shown.

BIN
hyhproject/app/model/._Shops.php Executable file

Binary file not shown.

224
hyhproject/app/model/AppPort.php Executable file
View File

@ -0,0 +1,224 @@
<?php
namespace wstmart\app\model;
use think\Model;
use think\Db;
/**
* ============================================================================
* 文章类
*/
class AppPort extends Model{
/*
* APP首页轮播图
* */
public function appBanner(){
$result=listAds('app_new_top_banner',8,0);
return $result;
}
/**
* app新版桔子头条
*/
public function appNews(){
$catId=8;
$where = array();
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$catIds=db('article_cats')->where(['parentId'=>$catId,'dataFlag'=>1])->column('catId');
$where['catId']=array('in',$catIds);
$result = Db::name('articles')->where($where)->field('articleId,articleTitle,catId')->select();
return $result;
}
/**
* app新版桔子头条分类接口
*/
public function appNewsClass(){
$catId=(int)input('catId/d');
$where = array();
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$id=db('article_cats')->where(['catId'=>$catId,'dataFlag'=>1])->value('parentId');
$where['parentId']=$id;
$result = Db::name('article_cats')->where($where)->select();
return $result;
}
/**
* app新版桔子头条
*/
public function appNewsLists(){
$catId=(int)input('catId/d');
$articleId=(int)input('articleId');
$where = array();
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$id=db('article_cats')->where(['catId'=>$catId,'dataFlag'=>1])->value('parentId');
$where['parentId']=$id;
$result = Db::name('article_cats')->where($where)->select();
return $result;
}
/**
* app新版桔子头条详情页借口
*/
public function appNewsDetail(){
$articleId=(int)input('articleId');
$where = array();
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$where['articleId']=$articleId;
$result = Db::name('articles')->where($where)->select();
return $result;
}
/*
* app新版秒杀接口
* */
public function appSecKill(){
$now=time();
$where=[];
$where['startTime']=array('elt',$now);
$where['endTime']=array('egt',$now);
$result=Db::name('hyhsale_goods')->alias('gu')
->join('__GOODS__ g','gu.goodsId=g.goodsId','inner')
->where('g.dataFlag=1 and g.isSale=1 and g.goodsStatus=1 and gu.dataFlag=1 and gu.hyhsaleStatus=1 and gu.isSelf=0')
->where($where)
->field('gu.goodsId,g.marketPrice,gu.goodsPrice,gu.totalNum,gu.startTime,gu.endTime,g.goodsName,g.goodsImg,gu.specsId')
->select();
foreach($result as &$v){
$v['goodsImg']=WSTImg($v['goodsImg'],3);
}
return $result;
}
/*
* app新版ect专区/活动层接口
* */
public function appEctAct(){
$result['ect']=listAds('app_new_ect_left',1,0);
$result['act']=listAds('app_new_act_photo',1,0);
return $result;
}
/*
* app新版品牌热卖接口
* */
public function appBrands(){
$result['brands']=listAds('app_new_page_brand',1,0);
$result['brandsList']=db('brands b')
->join('hyhbrands_rec hr','b.brandId=hr.brandId')
->whereNotIn('hr.isSelf',1)
->field('b.brandId,brandName,brandImg,shopId,findOrder')
->where(['dataFlag'=>1])->limit(6)->order('findOrder desc')->select();
return $result;
}
/*
* app新版居家好帮手广告位接口
* */
public function appJadvertis(){
//居家好帮手左上位置
$row['left']=listAds('app_new_jujia_lt',2,0);
$row['right']=listAds('app_new_jujia_rt',2,0);
$result['zxz']=listAds('app_new_jujia_lul',1,0);
$result['zxy']=listAds('app_new_jujia_lur',1,0);
$result['yxz']=listAds('app_new_jujia_rul',1,0);
$result['yxy']=listAds('app_new_jujia_rur',1,0);
$row['under']= array_merge($result['zxz'],$result['zxy'],$result['yxz'],$result['yxy']);
return $row;
}
/*
* app新版潮流先锋广告位接口
* */
public function appCadvertis(){
//潮流先锋左上位置
$row['left']=listAds('app_new_chao_lt',2,0);
//潮流先锋左下左位置
$result['zxz']=listAds('app_new_chao_lul',1,0);
//潮流先锋左下右位置
$result['zxy']=listAds('app_new_chao_lur',1,0);
//潮流先锋右上位置
$row['right']=listAds('app_new_chao_rt',2,0);
//潮流先锋右下左位置
$result['yxz']=listAds('app_new_chao_rul',1,0);
//潮流先锋右下右位置
$result['yxy']=listAds('app_new_chao_rur',1,0);
$row['under']= array_merge($result['zxz'],$result['zxy'],$result['yxz'],$result['yxy']);
return $row;
}
/*
* app新版食品超市广告位接口
* */
public function appSadvertis(){
//食品超市左上位置
$row['left']=listAds('app_new_shi_lt',2,0);
//食品超市左下左位置
$result['zxz']=listAds('app_new_shi_lul',1,0);
//食品超市左下右位置
$result['zxy']=listAds('app_new_shi_lur',1,0);
//食品超市右上位置
$row['right']=listAds('app_new_shi_rt',2,0);
//食品超市右下左位置
$result['yxz']=listAds('app_new_shi_rul',1,0);
//食品超市右下右位置
$result['yxy']=listAds('app_new_shi_rur',1,0);
$row['under']= array_merge($result['zxz'],$result['zxy'],$result['yxz'],$result['yxy']);
return $row;
}
/*
* app新版家电馆广告位接口
* */
public function appDadvertis(){
//家电馆左上位置
$row['left']=listAds('app_new_dian_lt',2,0);
//家电馆左下左位置
$result['zxz']=listAds('app_new_dian_lul',1,0);
//家电馆左下右位置
$result['zxy']=listAds('app_new_dian_lur',1,0);
//家电馆右上位置
$row['right']=listAds('app_new_dian_rt',2,0);
//家电馆右下左位置
$result['yxz']=listAds('app_new_dian_rul',1,0);
//家电馆右下右位置
$result['yxy']=listAds('app_new_dian_rur',1,0);
$row['under']= array_merge($result['zxz'],$result['zxy'],$result['yxz'],$result['yxy']);
return $row;
}
/*
* app为你推荐接口
* */
public function recommend(){
$userId=session('WST_USER.userId');
$page = (int)input('post.page/d');
$cacheData = cache('APP_CATS_RECOMMEND_'.$page.'_'.$userId);
if($cacheData)return $cacheData;
$childId=[];
$catId=[];
$goodsCat=[];
$goods_ids=db('page_view')->where('userId',$userId)->field('count(goodsId)num,goodsId')->group('goodsId')->order('num desc')->limit('10')->select();
foreach($goods_ids as $key=>$value){
$childId[]=$value['goodsId'];
}
if(!$userId ||count($childId)<4){
$goods_ids=db('page_view')->field('count(goodsId)num,goodsId')->group('goodsId')->order('num desc')->limit('10')->select();
foreach($goods_ids as $key=>$value){
$childId[]=$value['goodsId'];
}
}
$catIds=db('goods')->whereIn('goodsId',$childId)->field('goodsCatIdPath')->select();
foreach($catIds as $key=>$value){
$cat=explode("_",$value['goodsCatIdPath']);
//$goodsCat=current($cat);
$goodsCatId=next($cat);
$cat=db('goods_cats')->where(['catId'=>$goodsCatId,'dataFlag'=>1])->value('catId');
$catId[]=$cat;
}
$catId=array_unique(array_filter($catId));
//dump($catId);
$childId=db('goods_cats')->whereIn('parentId',$catId)->field('catId')->select();
//dump($childId);
foreach($childId as $k=>$v){
foreach($v as $kk=>$vv){
$goodsCat[]=$vv;
}
}
$goods=db('goods')->whereIn('goodsCatId',$goodsCat)->where('dataFlag=1 AND isSale=1 AND goodsStatus=1')
->field('goodsId,goodsName,goodsImg,shopId,marketPrice,shopPrice')
->paginate(input('pagesize/d'))->toArray();
cache('APP_CATS_RECOMMEND_'.$page.'_'.$userId,$goods,3600);
return $goods;
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace wstmart\app\model;
use think\Db;
/**
* ============================================================================
* 文章类
*/
class Articles extends Base{
/**
* 获取资讯中心的子集分类id
*/
public function getChildIds(){
$ids = cache('NEW_IDS');
if(!$ids){
$data = Db::name('article_cats')->cache(true)->select();
foreach($data as $k=>$v){
if($v['parentId']!=7 && $v['catId']!=7 && $v['parentId']!=0 ){
$ids[] = $v['catId'];
}
}
cache('NEW_IDS',$ids);
}
return $ids;
}
/**
* 获取咨询中中心所有文章
*/
public function getArticles(){
// 获取咨询中心下的所有分类id
$ids = $this->getChildIds();
$rs = $this->alias('a')
->field('a.*')
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
->where(['a.catId'=>['in',$ids],
'a.isShow'=>1,
'a.dataFlag'=>1,
'ac.dataFlag'=>1,
'ac.isShow'=>1,
'ac.catType'=>0,
])
->order('createTime desc')
->paginate((int)input('pagesize'));
return $rs;
}
/**
* 根据id获取资讯文章
*/
public function getNewsById(){
$id = (int)input('id');
WSTArticleVisitorNum($id);// 统计文章访问量
return $this->alias('a')
->field('a.*')
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
->where('ac.catType=0 and a.dataFlag=1 and a.isShow=1')
->cache(true)
->find($id);
}
}

9
hyhproject/app/model/Base.php Executable file
View File

@ -0,0 +1,9 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Base as CBase;
/**
* ============================================================================
* 基础模型器
*/
class Base extends CBase {}

303
hyhproject/app/model/Carts.php Executable file
View File

@ -0,0 +1,303 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Carts as CCarts;
use think\Db;
/**
* 购物类
*/
class Carts extends CCarts{
/**
* 购买保存下参数
* @param integer $goodsId [description]
* @param integer $goodsSpecId [description]
* @param integer $buyNum [description]
* @param integer $uId [description]
* @return [type] [description]
*/
public function buy($goodsId=0, $goodsSpecId=0, $buyNum =0, $uId=0){
$userId = ($uId==0)?(int)session('WST_USER.userId'):$uId;
if(!$userId){
return WSTReturn('购买失败,请先登录',-999);
}
$goodsId = ($goodsId==0)?input('goodsId/d'):$goodsId;
if(!$goodsId){
exit(jsonReturn('请输入参数值!',-1));
}
$goodsSpecId = ($goodsSpecId==0)?input('goodsSpecId/d',0):$goodsSpecId;
$buyNum = ($buyNum==0)?input('buyNum/d',1):$buyNum;
$goodsType = (int)input('goodsType/d',1); //1逛商都2助微吧
$buyNum = ($buyNum>0)?$buyNum:1;
//验证传过来的商品是否合法
$chk = $this->checkGoodsSaleSpec($goodsId,$goodsSpecId);
if($chk['status']==-1)return $chk;
$goodsSpecId = $chk['data']['goodsSpecId'];
//检测库存是否足够
if($chk['data']['stock']<$buyNum){
return WSTReturn("购买失败,商品库存不足", -1);
}
$carts = [];
$carts['goodsId'] = $goodsId;
$carts['goodsSpecId'] = $goodsSpecId;
$carts['buyNum'] = $buyNum;
$carts['goodsType'] = $goodsType;
session('HYH_CARTS',$carts);
return WSTReturn("添加成功", 1);
}
/**
* 现在购买
* isSettlement 是结算页面
* uId 会员ID默认为当前ID
* userAddress 会员地址
*/
public function buyNow($areaId2=0, $uId=0){
$hyhCarts = session('HYH_CARTS');
$goodsId = $hyhCarts['goodsId'];
$goodsSpecId =$hyhCarts['goodsSpecId'];
$buyNum = $hyhCarts['buyNum'];
$areaId2 = ($areaId2==0)?input('areaId2/d'):$areaId2;
$userId = ($uId==0)?(int)session('WST_USER.userId'):$uId;
if(!$goodsId){
exit(jsonReturn('请勿重新下单!',-2));
}
if(!$userId){
exit(jsonReturn('请重新登录下单!',-999));
}
$where = [];
$where['g.goodsId'] = $goodsId;
$where['g.dataFlag'] = 1;
$where['g.goodsStatus'] = 1;
$where['g.isSale'] = 1;
$where['s.dataFlag'] = 1;
$where['s.shopStatus'] = 1;
$where['s.status'] = 1;
if($goodsSpecId){
$where['gs.id'] = $goodsSpecId;
}
//获取商品和商店信息
$rs = Db::name('goods g')
->join('__SHOPS__ s','s.shopId=g.shopId','left')
->join('__GOODS_SPECS__ gs','g.goodsId=gs.goodsId','left')
->where($where)
->field('s.userId,s.shopId,s.shopName,s.userId shopUserId,s.shopLevel,g.goodsId,g.goodsName,g.shopPrice,g.goodsStock,g.isSpec,g.marketPrice,gs.specPrice,gs.specStock,g.goodsImg,gs.specIds,g.goodsCatId,g.freight,g.isFreeShipping,gs.initNum,gs.whslePrice')
->find();
if(!$rs){
exit(jsonReturn('商品读取失败',-1));
}
$cartsInfo[$rs['shopId']]['isFreeShipping'] = (bool)$rs['isFreeShipping'];
$cartsInfo[$rs['shopId']]['promotion'] = [];
$cartsInfo[$rs['shopId']]['promotionMoney'] = 0;
$cartsInfo[$rs['shopId']]['shopId'] = $rs['shopId'];
$cartsInfo[$rs['shopId']]['shopName'] = $rs['shopName'];
$cartsInfo[$rs['shopId']]['userId'] = $rs['userId'];
if($rs['isSpec']==1){
$rs['shopPrice'] = $rs['specPrice'];
$rs['goodsStock'] = $rs['specStock'];
}else{
$rs['initNum'] = 0;
$rs['whslePrice'] = 0;
}
$hyhCarts['goodsType'] = (int) $hyhCarts['goodsType'];
if(2 == $hyhCarts['goodsType']){//助微吧购物判断店主等级
$tm = Model('common/Table');
$tm->setTable('shops');
//换算为3级循环等级
if(0 == $rs['shopLevel']){
$maxSaleMoney = dataConf('helpLevel0MaxSaleMoney');
}else{
//$nowLevel = $rs['shopLevel'] % 3;
$tm->setTable('users');
//最大可销售金额
$maxSaleMoney = $tm->getField(['userId'=>$rs['shopUserId']],'helpMaxSaleMoney');
}
$tm->setTable('shops');
//当前销售值
$nowSaleMoney = $tm->getSum(['userId'=>$rs['shopUserId']],'helpSaleMoney');
if(($nowSaleMoney+$rs['shopPrice']) > $maxSaleMoney ){
exit(jsonReturn('当前助微吧商户可销售额不足!',-1));
}
}
$cartsInfo[$rs['shopId']]['goodsMoney'] = $rs['shopPrice'] * $buyNum;
//判断能否购买预设allowBuy值为10为将来的各种情况预留10个情况值从0到9
$rs['allowBuy'] = 10;
if($rs['goodsStock']<=0){
//$rs['allowBuy'] = 0;//库存不足
exit(jsonReturn('库存不足',-1));
}else if($rs['goodsStock']<$buyNum){
//$rs['allowBuy'] = 1;//库存比购买数小
$buyNum = $rs['goodsStock'];
}
$rs['specNames'] = [];
//加载规格值
if($goodsSpecId>0){
$specs = DB::name('spec_items')->alias('s')->join('__SPEC_CATS__ sc','s.catId=sc.catId','left')
->where(['s.goodsId'=>$rs['goodsId'],'s.dataFlag'=>1])->field('catName,itemId,itemName')->select();
if(count($specs)>0){
$specMap = [];
foreach ($specs as $key =>$v){
$specMap[$v['itemId']] = $v;
}
$strName = [];
if($rs['specIds']!=''){
$str = explode(':',$rs['specIds']);
foreach ($str as $vv){
if(isset($specMap[$vv]))$strName[] = $specMap[$vv];
}
$rs['specNames'] = $strName;
}
}
}
$cartsInfo[$rs['shopId']]['list']['0'] = $rs;
$cartsInfo[$rs['shopId']]['list']['0']['promotion'] = [];
$cartsInfo[$rs['shopId']]['list']['0']['goodsSpecId'] = $goodsSpecId;
$cartsInfo[$rs['shopId']]['list']['0']['cartNum'] = $buyNum;
$cartsInfo[$rs['shopId']]['list']['0']['cartId'] = $goodsSpecId;
$goodsTotalMoney = $rs['shopPrice'] * $buyNum ;
$goodsTotalNum = 1;
$cartData = ['carts'=>$cartsInfo,'goodsTotalMoney'=>$goodsTotalMoney,'goodsTotalNum'=>$goodsTotalNum,'promotionMoney'=>0];
//秒杀活动监听
hook("beforeSettlement",["carts"=>&$cartData]);
$allShippingMoney = 0;
if(empty($cartData['carts']['is_seckilling'])){
//批发插件 mart hsf 20171116
hook("mobileControllerCartsSettlement",["carts"=>&$cartData]);
//店铺优惠活动监听
hook('afterQueryCarts',["carts"=>&$cartData,'isSettlement'=>true,'isVirtual'=>false,'uId'=>$userId]);
//ect整合相关优惠还有判断不能和在线支付商品一块
hook("ectIntegration",["carts"=>&$cartData,'isSettlement'=>true,'uId'=>$userId]);
//11.11会场商品结算钩子
hook("orderCatsDoubleEleven",["carts"=>&$cartData,'isSettlement'=>true,'uId'=>$userId]);
}
//添加运费计算
if($rs['isFreeShipping']){
$cartData['carts'][$rs['shopId']]["shippingMoney"] = 0;
}else{
$cartData['carts'][$rs['shopId']]["shippingMoney"] = $rs['freight'];
// if($areaId2){
// $cartData['carts'][$rs['shopId']]["shippingMoney"] = WSTOrderFreight($rs['shopId'],$areaId2);
// }else{
// $cartData['carts'][$rs['shopId']]["shippingMoney"] = WSTOrderFreight($rs['shopId'],-1);
// }
$allShippingMoney += $cartData['carts'][$rs['shopId']]["shippingMoney"];
}
if($allShippingMoney){
$cartData['goodsTotalMoney'] += $allShippingMoney;
}
$cartData['allShippingMoney'] = $allShippingMoney;//添加总运费
$cartData['goodsType'] = $hyhCarts['goodsType'];
return $cartData;
}
/**
* 计算订单金额
*/
public function getMoney($areaId2=0, $uId=0){
$data = ['shops'=>[],'totalMoney'=>0,'totalGoodsMoney'=>0];
$userId = $uId==0?(int)session('WST_USER.userId'):$uId;
$areaId = input('post.areaId2/d',-1);
//计算各店铺运费及金额
$deliverType = (int)input('deliverType');//0是快递1是自提自提的不要运费先取消
$carts = $this->buyNow($areaId,$userId);
$shopFreight = 0;
$maxScoreMoney = 0;//初始化最大可用惠宝数 mark hsf 20171117
$total_promotion_money = 0;//初始化合计优惠 mark hsf 20170303
$data['maxScoreMoneySum'] = 0;
foreach ($carts['carts'] as &$v){//优化一下循环效率 mark hsf 20171118
// if($v['isFreeShipping']){
// $data['shops'][$v['shopId']]['freight'] = 0;
// }else{
// $shopFreight = ($deliverType==1)?0:WSTOrderFreight($v['shopId'],$areaId);
// $data['shops'][$v['shopId']]['freight'] = $shopFreight;
// }
if($v['isFreeShipping']){
$shopFreight = 0;
}else{
if($deliverType == 0){
$shopFreight = $v['shippingMoney'];
}
}
$data['shops'][$v['shopId']]['freight'] = $shopFreight;
$data['shops'][$v['shopId']]['oldGoodsMoney'] = $v['goodsMoney'];
$data['shops'][$v['shopId']]['goodsMoney'] = $v['goodsMoney']+$shopFreight-$v['promotionMoney'];
$data['totalGoodsMoney'] += $v['goodsMoney']-$v['promotionMoney'];
$data['totalMoney'] += $v['goodsMoney'] + $shopFreight-$v['promotionMoney'];
$total_promotion_money += $v['promotionMoney'];//合计优惠 mark hsf 20170303
/*
* 计算最大可用惠宝,添加验证批发价的惠宝可抵用 mark hsf 20171117
*/
// foreach ($v['list'] as &$val) {
// if(isset($val['isWhsle'])){//是批发价的
// $maxScoreMoney += (int)($val['shopPrice'] * $val['cartNum'] * HuiWhsleScale());//可用惠宝默认抵10%
// }else{
// $maxScoreMoney += (int)($val['shopPrice'] * $val['cartNum'] * HuiScale());
// }
// }
/*
*----------end-------------
*/
}
//批发插件 mart hsf 20171116
hook("mobileControllerCartsSettlement",["carts"=>&$carts]);
//放钩子计算11.11订单的分类商品使用优惠券后的金额
hook("orderCatsCouponEleven",['data'=>&$data,'carts'=>&$carts,'isSettlement'=>true,'uId'=>$userId]);
if(isset($data['couponMoney']) && $data['couponMoney'] > 0 ){
$total_promotion_money += $data['couponMoney'];
}
//此处放钩子计算商家使用优惠券后的金额-根据优惠券ID计算
hook("afterCalculateCartMoney",["data"=>&$data,'carts'=>$carts,'isVirtual'=>false,'uId'=>$userId]);
//ect整合相关优惠还有判断不能和在线支付商品一块
hook("ectIntegration",["carts"=>&$carts,'isSettlement'=>true,'uId'=>$userId]);
$maxScoreMoney = $data['maxScoreMoneySum']-($total_promotion_money * HuiScale());//减去优惠过的
$maxScoreMoney = $maxScoreMoney < 0 ? 0 : $maxScoreMoney;
$data['totalGoodsMoney'] = ($data['totalGoodsMoney']>$data['totalMoney'])?$data['totalMoney']:$data['totalGoodsMoney'];
//echo $data['totalGoodsMoney'];
$data['maxScore'] = 0;
$data['maxScoreMoney'] = 0;
$data['useScore'] = 0;
$data['scoreMoney'] = 0;
// //计算最大可用惠宝
// /**
// * 最多金额抵用20% mark 20170907
// */
// //$maxScoreMoney = (int)($data['totalGoodsMoney'] * HuiScale());//$data['totalGoodsMoney']; //惠宝最多可抵用20% mark 20170907
// $maxScore = WSTScoreToMoney($maxScoreMoney,true);//WSTScoreToMoney($data['totalGoodsMoney'],true);
// /*
// -------------------end----------------
// */
// //最大可用惠宝不能大于用户惠宝
// $user = model('users')->getFieldsById($userId,'userScore');
// if($maxScore>$user['userScore']){
// $maxScore = $user['userScore'];
// $maxScoreMoney = WSTScoreToMoney($maxScore);
// }
// $data['maxScore'] = $maxScore;
// $data['maxScoreMoney'] = $maxScoreMoney;
// //判断是否使用惠宝
// $isUseScore = (int)input('isUseScore');
// if($isUseScore==1){
// //不能比用户惠宝还多
// $useScore = (float)input('useScore');
// if($useScore>$maxScore)$useScore = $maxScore;
// $data['useScore'] = $useScore;
// $data['scoreMoney'] = WSTScoreToMoney($useScore);
// }
// if((isset($carts['is_seckilling']) && $carts['is_seckilling'] == 1) || (isset($carts['promotion_goods']) && $carts['promotion_goods'] == 1)){//不可抵用惠宝
// $data['useScore']=0;
// $data['scoreMoney']=0;
// }
//$carts['promotionMoney'] = isset($carts['promotionMoney']) ? $carts['promotionMoney'] : 0;
$data['couponMoney'] = isset($data['couponMoney']) ? $data['couponMoney'] : 0;
$data['realTotalMoney'] = WSTPositiveNum($data['totalMoney'] - $data['scoreMoney'] - $data['couponMoney']);
//dump($data);
return WSTReturn('',1,$data);
}
}

32
hyhproject/app/model/Chain3.php Executable file
View File

@ -0,0 +1,32 @@
<?php
namespace wstmart\app\model;
/**
* ============================================================================
* 基础模型器
*/
class Chain3 extends Chain3base {
protected $tokenabi;
protected $bytecode;
public function __construct(){
parent::__construct();
}
protected function get_Balance(){
$this->wei=8;
$address = trim(input('post.address'));
$this->web3->eth->getBalance($address , function ($err, $balance) {
if ($err !== null) {
exit(jsonReturn($err->getMessage()));
// echo 'Error: ' . $err->getMessage();
//return;
}else{
$my_balance = $balance->toString();
$my_balance = $my_balance/pow(10,$this->wei);
$data['balance'] = $my_balance;
exit(jsonReturn('',1,$data));
}
});
}
}

View File

@ -0,0 +1,115 @@
<?php
namespace wstmart\app\model;
use think\Model;
use think\Db;
Vendor('web3.vendor.autoload');
use Web3\Web3;
/**
* ============================================================================
* 基础模型器
*/
class Chain3base extends Model{
/**
* web3
*
* @var \Web3\Web3
*/
protected $web3;
protected $wei = 18;
/**
* testHost
*
* @var string
*/
protected $testHost = 'http://localhost:8545';
/**
* coinbase
*
* @var string
*/
protected $coinbase=0;
public function __construct(){
parent::__construct();
$web3 = new Web3($this->testHost);
$this->web3 = $web3;
}
public function getCoinbase(){
$this->web3->eth->coinbase(function ($err, $coinbase) {
if ($err !== null) {
//return $this->fail($err->getMessage());
}else{
$this->coinbase = $coinbase;
}
});
return $this->coinbase;
////获取本机账号列表
// $this->web3->eth->accounts(function ($err, $accounts) use ($eth) {
// if ($err !== null) {
// echo 'Error: ' . $err->getMessage();
// return;
// }
// dump($accounts);
// });
}
/**
*创建账号
*
* @return void
*/
public function createAccount($pass){
$web3->personal->newAccount($pass, function ($err, $account) use (&$newAccount) {
if ($err !== null) {
return WSTReturn($err->getMessage());
// echo 'Error: ' . $err->getMessage();
//return;
}else{
$data['account'] = $account;
return WSTReturn('',1,$data);
}
});
}
public function getBalance($address){
$msg='';
$status=-1;
$data['balance']=0;
$this->web3->eth->getBalance($address , function ($err, $balance) use (&$msg,&$status,&$data) {
if ($err !== null) {
$msg=$err->getMessage();
//return WSTReturn($err->getMessage());
//echo 'Error: ' . $err->getMessage();
//return;
}else{
$my_balance = $balance->toString();
$my_balance = $my_balance/pow(10,$this->wei);
$status=1;
$data['balance'] = $my_balance;
}
});
return WSTReturn($msg,$status,$data);
}
//账号解锁
public function unlock_account($pass,$address){
$web3->personal->unlockAccount($address, $pass, function ($err, $unlocked) {
if ($err !== null) {
exit(jsonReturn($err->getMessage()));
// echo 'Error: ' . $err->getMessage();
// return;
}
if($unlocked) {
$data['unlock'] = 1;//$unlocked;
return WSTReturn('',1,$data);
} else {
$data['unlock'] = 0;
return WSTReturn('',1,$data);
//echo 'New account isn\'t unlocked' . PHP_EOL;
}
});
}
}

73
hyhproject/app/model/Ect.php Executable file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,102 @@
<?php
namespace wstmart\app\model;
use think\Db;
use think\Loader;
/**
* 双十一优惠券
*/
class EctElevenPay extends Base{
/**
* 返回获取双11优惠券所需的ect数量和价格
* @return [type] [description]
*/
public function getEctNum(){
try{
$url ='https://api.tokencan.net/exchange-open-api/open/api/get_ticker?symbol=ectusdt';
$t_info = $this->getHTTPS($url);
$t_info = json_decode($t_info);
if(is_object($t_info)){
$total_money = 11.11;//input('total_money');
$t_usdt_price = $t_info->data->last;
$now_doller = Db::name('doller')->where('id=1')->value('doller');
$now_rmb = round($t_usdt_price*$now_doller,2);
$to_ect_num = round($total_money/$now_rmb,2);
$msg='';
session('ect_rmb_price',$now_rmb);
exit(jsonReturn($msg,1,['now_rmb'=>$now_rmb,'ect_num'=>$to_ect_num]));
}
}catch (\Exception $e) {
exit(jsonReturn('获取价格失败!',-1));
}
}
private function getHTTPS($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* 支付双十一优惠券的ect价格
*/
public function payElevenEct(){
try{
$userId = (int)session('WST_USER.userId');
if(!$userId) exit(jsonReturn('请先登录!',-999));
//获取用户钱包
$user = model('users')->get($userId);
// if($user->payPwd=='')return WSTReturn('您未设置支付密码,请先设置密码',-1);
// if($user->payPwd!=md5($payPwd.$user->loginSecret))return WSTReturn('您的支付密码不正确',-1);
$ect_rmb_price = session('ect_rmb_price');
if($ect_rmb_price<0.05){
exit(jsonReturn('ECT价格出错',-1));
}
$price = 11.11;
$needPay = round($price/$ect_rmb_price,2);
$needPay = $needPay > 0 ? $needPay : 0;
if($needPay > $user->userECT) exit(jsonReturn('您的钱包ECT不足!',-2));
$cfgm = Db::name('coupon_record')->where(['couponId'=>11,'userId'=>$userId])->find();
if($cfgm){
exit(jsonReturn('您已购买过该优惠券,不可重复购买!',-3));
}
//创建一条支出流水记录
// $lm = [];
// $lm['targetType'] = 0;
// $lm['targetId'] = $userId;
// $lm['dataId'] = 0;
// $lm['dataSrc'] = 1;
// $lm['remark'] = '购买双十一神券支出¥'.$needPay;
// $lm['moneyType'] = 0;
// $lm['money'] = $needPay;
// $lm['payType'] = 'ect';
// $a = model('common/LogMoneys')->add($lm);
ectLog($userId,$needPay,11,'11.11神券支出',['userECT'=>['exp','userECT-'.$needPay]],2);
$m = new \addons\hyhcouponset\model\Hyhcouponset();
$data= $m->giftBag($userId,$secTypeId = 104);
// dump($data);die;
// Db::commit();
exit(jsonReturn('扣款成功!',1));
}catch(\Exception $e){
// Db::rollback();errLog($e);
exit(jsonReturn('扣款失败!',-1));
}
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Favorites as CFavorites;
/**
* ============================================================================
*
* ============================================================================
* 收藏类
*/
class Favorites extends CFavorites{
/**
* 获取会员关注商品数和关注商家数
*/
function getFavoritesNum($userId){
$data['goodsFavoritesNum'] = $this->where(['userId'=>$userId,'favoriteType'=>0])->count();
$data['shopFavoritesNum'] = $this->where(['userId'=>$userId,'favoriteType'=>1])->count();
return $data;
}
/**
* 获取关注商家数
*/
function getFavoritesShopsNum($shopId=0){
$shopId=$shopId==0?(int)input('shopId'):$shopId;
return $this->where(['targetId'=>$shopId,'favoriteType'=>1])->cache('true',3600)->count();
}
/**
* 获取商品是否关注
*/
function isGetFavorites($goodsId,$userId){
$goodsId=$goodsId==0?(int)input('goodsId'):$goodsId;
$userId=$userId==0?(int)input('userId'):$userId;
return $this->where(['userId'=>$userId,'favoriteType'=>0,'targetId'=>$goodsId])->find();
}
/**
* 上新的店铺列表
*/
public function listShopQuery(){
$pagesize = input("param.pagesize/d",5);
$goodsSize = input("param.goodsSize/d",6);
$userId = 0;//(int)session('WST_USER.userId');0就是显示所有商铺
if($userId){
$page = db("favorites")->alias('f')
->join('__SHOPS__ s','s.shopId = f.targetId','left')
->field('f.favoriteId,f.targetId,s.shopId,s.shopName,s.shopImg')
->where(['f.userId'=> $userId,'favoriteType'=> 1])//'s.shopId'=>['in','1,2,3,6,20']])
->order('f.favoriteId desc')
->paginate($pagesize)->toArray();
}else{
$page = db("shops s")
->join('__GOODS__ g','s.shopId = g.shopId','left')
->field('s.shopId,count(goodsId) as goodsNum,s.shopName,s.shopImg')
->where(['g.isSale'=>1, 'g.goodsStatus'=>1,'g.dataFlag'=>1])
->group('g.shopId')
->order('saleTime DESC')
->cache(true,7200)
->paginate($pagesize)
->toArray();
}
foreach ($page['Rows'] as &$v){
$field = 'goodsId,goodsImg,saleTime';//goodsName,shopPrice,
$goods = db('goods')
->where(['dataFlag'=> 1,'isSale'=>1,'goodsStatus'=> 1,'shopId'=> $v["shopId"]])
->field($field)
->cache(true,7200)
->limit($goodsSize)
->order('saleTime desc')
->select();
if($goods){
$v['newTime'] = $goods['0']['saleTime'];
}else{
$v['newTime'] = date('Y-m-d');
}
$v['goods'] = $goods;
}
return $page;
}
}

228
hyhproject/app/model/Goods.php Executable file
View File

@ -0,0 +1,228 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Goods as CGoods;
use think\Db;
/**
* ============================================================================
* 商品类
*/
class Goods extends CGoods{
/**
* 获取列表
*/
public function pageQuery($goodsCatIds = [], $_where=[]){
//查询条件
$keyword = input('keyword');
$brandId = input('brandId/d');
$where = $where2 = [];
$where['goodsStatus'] = 1;
$where['g.dataFlag'] = 1;
$where['isSale'] = 1;
if($keyword!='')$where['goodsName'] = ['like','%'.$keyword.'%'];
if($brandId>0)$where['g.brandId'] = $brandId;
//排序条件
$orderBy = input('condition/d',0);
$orderBy = ($orderBy>=0 && $orderBy<=4)?$orderBy:0;
$order = (input('desc/d',0)==1)?1:0;
$pageBy = ['saleNum','shopPrice','visitNum','saleTime'];
$pageOrder = ['desc','asc'];
if(!empty($goodsCatIds))$where['goodsCatIdPath'] = ['like',implode('_',$goodsCatIds).'_%'];
$where = array_merge($where, $_where);
$list = Db::name('goods')->alias('g')->join("__SHOPS__ s","g.shopId = s.shopId")
->where($where)
->field('goodsId,goodsName,saleNum,shopPrice,marketPrice,isSpec,goodsImg,appraiseNum,visitNum,s.shopId,shopName,isSelf,isFreeShipping,gallery')
->order($pageBy[$orderBy]." ".$pageOrder[$order].",goodsId asc")
->paginate(input('pagesize/d'))->toArray();
return $list;
}
/**
* 获取指定商品销量
* @param [type] $goodsIds [description]
* @return [type] [description]
*/
public function getSales($goodsIds){
if(is_array($goodsIds)){
$where['og.goodsId'] = array('in',$goodsIds);
}else{
$where['og.goodsId'] = $goodsIds;
}
$where['o.isPay'] = 1;
return Db::name('orders')->alias('o')->join('__ORDER_GOODS__ og','o.orderId=og.orderId')->cache(true,3600)->where($where)->sum('goodsNum');
}
/**
* 获取店铺所有宝贝数量
* @param [type] $shopId [description]
* @return [type] [description]
*/
public function getGoodsCount($shopId=0){
$shopId=$shopId==0?(int)input('shopId'):$shopId;
$where['shopId'] = $shopId;
$where['isSale'] = 1;
$where['dataFlag'] = 1;
$where['goodsStatus'] = 1;
return $this->where($where)->cache(true,3600)->count('goodsId');
}
/**
* 获取店铺上新宝贝数量,一周内的
* @param [type] $shopId [description]
* @return [type] [description]
*/
public function getNewGoodsCount($shopId=0){
$shopId=$shopId==0?(int)input('shopId'):$shopId;
$where['shopId'] = $shopId;
$where['isSale'] = 1;
$where['dataFlag'] = 1;
$where['goodsStatus'] = 1;
return $this->where($where)->whereTime('saleTime','last week')->cache(true,3600)->count('goodsId');
}
/**
* 获取新品
* @param [type] $goodsIds [description]
* @return [type] [description]
*/
public function getNew($goodsIds){
if(is_array($goodsIds)){
$where['og.goodsId'] = array('in',$goodsIds);
}else{
$where['og.goodsId'] = $goodsIds;
}
$where['o.isPay'] = 1;
return Db::name('orders')->alias('o')->join('__ORDER_GOODS__ og','o.orderId=og.orderId')->cache(true,3600)->where($where)->sum('goodsNum');
}
/**
* 获取商品资料在前台展示
*/
public function getBySale($goodsId){
$key = input('key');
// 浏览量
$this->where('goodsId',$goodsId)->setInc('visitNum',1);
$rs = Db::name('goods')->where(['goodsId'=>$goodsId,'dataFlag'=>1])->find();
if(!empty($rs)){
$rs['read'] = false;
//判断是否可以公开查看
$viKey = WSTShopEncrypt($rs['shopId']);
if(($rs['isSale']==0 || $rs['goodsStatus']==0) && $viKey != $key)return [];
if($key!='')$rs['read'] = true;
//获取店铺信息
$rs['shop'] = model('shops')->getBriefShop((int)$rs['shopId']);
if(empty($rs['shop']))return [];
//获取商店的授权商店分类和商铺电话信息
// $goodsCats = Db::name('cat_shops')->alias('cs')->join('__GOODS_CATS__ gc','cs.catId=gc.catId and gc.dataFlag=1','left')->join('__SHOPS__ s','s.shopId = cs.shopId','left')
// ->where('cs.shopId',$rs['shopId'])->field('cs.shopId,s.shopTel,gc.catId,gc.catName')->select();
// $rs['shop']['catId'] = $goodsCats[0]['catId'];
// $rs['shop']['shopTel'] = $goodsCats[0]['shopTel'];
// $cat = [];
// foreach ($goodsCats as $v){
// $cat[] = $v['catName'];
// }
// $rs['shop']['cat'] = implode('',$cat);
// if(empty($rs['shop']))return [];
$gallery = [];
$gallery[] = $rs['goodsImg'];
if($rs['gallery']!=''){//有多个图片就把多个一维图片地址合成一个数组
$tmp = explode(',',$rs['gallery']);
$gallery = array_merge($gallery,$tmp);
}
$rs['gallery'] = $gallery;
//获取规格值
$specs = Db::name('spec_cats')->alias('gc')->join('__SPEC_ITEMS__ sit','gc.catId=sit.catId','inner')
->where(['sit.goodsId'=>$goodsId,'gc.isShow'=>1,'sit.dataFlag'=>1])
->field('gc.isAllowImg,gc.catName,sit.catId,sit.itemId,sit.itemName,sit.itemImg')
->order('gc.isAllowImg desc,gc.catSort asc,gc.catId asc')->select();
$rs['spec']=[];
//把属于同一个分类的规格整合到一块
foreach ($specs as $key =>$v){
$rs['spec'][$v['catId']]['name'] = $v['catName'];
$rs['spec'][$v['catId']]['list'][] = $v;
}
//dump($rs['spec']);die;
//获取销售规格,商品规格的具体属性
$sales = Db::name('goods_specs')->where(['goodsId'=>$goodsId,'dataFlag'=>1])->field('id,isDefault,productNo,specIds,marketPrice,specPrice,specStock,initNum,whslePrice')->select();
if(!empty($sales)){
//将规格ID格式如3:4:5:6:7设为数组键名,与$rs['spec']['catId']['list']['itemId'] 对应
/*实例
//$specs转换后$rs['spec']数据
[11] => array(2) {//11代表规格分类ID
["name"] => string(12) "机身颜色"//规格分类名称
["list"] => array(2) {//当前分类11下的数据
[0] => array(6) {
["isAllowImg"] => int(1)
["catName"] => string(12) "机身颜色"
["catId"] => int(11)
["itemId"] => int(5)//这个即代表数据的ID3:4:(5):6:7就是对应的这个
["itemName"] => string(6) "黄色"
["itemImg"] => string(44) "upload/goods/2017-11/5a0a7e2ee935c_thumb.jpg"
}
[1] => array(6) {
["isAllowImg"] => int(1)
["catName"] => string(12) "机身颜色"
["catId"] => int(11)
["itemId"] => int(10)
["itemName"] => string(6) "灰色"
["itemImg"] => string(44) "upload/goods/2017-11/5a0a7e3970fed_thumb.jpg"
}
}
}
//$sales原始数据
[0] => array(7) {
["id"] => int(3)
["isDefault"] => int(1)
["productNo"] => string(1) "3"
["specIds"] => string(9) "3:4:5:6:7"
["marketPrice"] => string(7) "1070.00"
["specPrice"] => string(7) "1002.00"
["specStock"] => int(0)
}
//$sales下面转换后数据
["3:4:5:6:7"] => array(6) {
["id"] => int(3)
["isDefault"] => int(1)
["productNo"] => string(1) "3"
["marketPrice"] => string(7) "1070.00"
["specPrice"] => string(7) "1002.00"
["specStock"] => int(0)
}*/
foreach ($sales as $key =>$v){
$str = explode(':',$v['specIds']);
sort($str);
unset($v['specIds']);
$rs['saleSpec'][implode(':',$str)] = $v;
}
}
//获取商品属性
$rs['attrs'] = Db::name('attributes')->alias('a')->join('goods_attributes ga','a.attrId=ga.attrId','inner')
->where(['a.isShow'=>1,'dataFlag'=>1,'goodsId'=>$goodsId])->field('a.attrName,ga.attrVal')
->order('attrSort asc')->select();
//获取商品评分
$rs['scores'] = Db::name('goods_scores')->where('goodsId',$goodsId)->field('totalScore,totalUsers')->find();
$rs['scores']['totalScores'] = ($rs['scores']['totalScore']==0)?5:WSTScore($rs['scores']['totalScore'],$rs['scores']['totalUsers'],5,0,3);
WSTUnset($rs, 'totalUsers');
//关注
$f = model('Favorites');
$rs['favShop'] = $f->checkFavorite($rs['shopId'],1);
$rs['favGood'] = $f->checkFavorite($goodsId,0);
//$rs['isEct'] = (int)Db::name('goods_pay')->where('goodsId',$goodsId)->value('ectPay');
}
//dump($rs);die;
return $rs;
}
public function historyQuery(){
$ids = cookie("wx_history_goods");
if(empty($ids))return [];
$where = [];
$where['isSale'] = 1;
$where['goodsStatus'] = 1;
$where['dataFlag'] = 1;
$where['goodsId'] = ['in',$ids];
$orderBy = "field(`goodsId`,".implode(',',$ids).")";
return Db::name('goods')
->where($where)->field('goodsId,goodsName,goodsImg,saleNum,shopPrice')
->order($orderBy)
->paginate((int)input('pagesize'))->toArray();
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\GoodsAppraises as CGoodsAppraises;
use think\Db;
/**
* ============================================================================
* 评价类
*/
class GoodsAppraises extends CGoodsAppraises{
/**
* 获取评论
*/
public function getAppr(){
$oId = (int)input('oId');
$uId = (int)session('WST_USER.userId');
$gId = (int)input('gId');
$specId = (int)input('sId');
$orderGoodsId = (int)input('orderGoodsId');
$rs = $this->where(['orderId'=>$oId,'userId'=>$uId,'goodsId'=>$gId,'goodsSpecId'=>$specId,'orderGoodsId'=>$orderGoodsId])->find();
if($rs!==false){
$rs = !empty($rs)?$rs:['goodsScore'=>'','timeScore'=>'','serviceScore'=>'','content'=>''];
return jsonReturn('',1,$rs);
}
return jsonReturn('获取出错',-1);
}
/**
* 根据商品id取一试图评论
*/
public function getOneAppraises($goodsId){
$goodsId=$goodsId==0?(int)input('goodsId'):$goodsId;
// 处理匿名
$anonymous = 1;
$where = ['ga.goodsId'=>$goodsId,
'ga.dataFlag'=>1,
'ga.isShow'=>1];
$rs = $this->alias('ga')
->field('DISTINCT(ga.id),ga.content,ga.images,ga.shopReply,ga.replyTime,ga.createTime,ga.goodsScore,ga.serviceScore,ga.timeScore,ga.shopId,u.userPhoto,u.loginName,u.userPhone,og.goodsSpecNames')
->join('__USERS__ u','ga.userId=u.userId','left')
->join('__ORDER_GOODS__ og','og.orderId=ga.orderId and og.goodsId=ga.goodsId','inner')
->where($where)
->order('id desc')
->find();
if($rs){
// 格式化时间
//$rs['createTime'] = date('Y-m-d',strtotime($rs['createTime']));
$rs['goodsSpecNames'] = str_replace('@@_@@','',$rs['goodsSpecNames']);
// 总评分
//$rs['avgScore'] = ceil(($rs['goodsScore'] + $rs['serviceScore'] + $rs['timeScore'])/3);
if($anonymous){
$start = floor((strlen($rs['userPhone'])/2))-1;
$rs['userPhone'] = substr_replace($rs['userPhone'],'***',$start,3);
$rs['loginName'] = $rs['userPhone'];
}
}else{
$rs = [];
}
return $rs;
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace wstmart\app\model;
use think\Cache;
/**
* ============================================================================
* 商品分类类
*/
class GoodsCats extends Base{
/**
* 列表
*/
public function getGoodsCats(){
$list = cache('WST_CACHE_GOODS_CAT_MOB');
if(!$list){
//查询一级分类
$trs1s = $this->where(["dataFlag"=>1,"isShow"=>1,"parentId"=>0])->field('catId,parentId,catName')->order('catSort asc')->select();
$trs1 = array();
$list = array();
$rs2 = array();
$maprs = array();
$ids = array();
foreach ($trs1s as $key =>$v){
$trs1[$key]['catId'] = $v['catId'];
$trs1[$key]['parentId'] = $v['parentId'];
$trs1[$key]['catName'] = $v['catName'];
$ids[] = $v['catId'];
}
$ids[] = -1;
//查询二级分类
$trs2s = $this->where("dataFlag=1 and isShow=1 and parentId in(".implode(',',$ids).")")->field('catId,parentId,catName')->order('catSort asc')->select();
$trs2 = array();
$ids = array();
foreach ($trs2s as $key =>$v){
$trs2[$key]['catId'] = $v['catId'];
$trs2[$key]['parentId'] = $v['parentId'];
$trs2[$key]['catName'] = $v['catName'];
}
foreach ($trs2 as $v2){
$ids[] = $v2['catId'];
$maprs[$v2['parentId']][] = $v2;
}
$ids[] = -1;
//查询三级分类
$trs3s = $this->where("dataFlag=1 and isShow=1 and parentId in(".implode(',',$ids).")")->field('catId,parentId,catName,catImg')->order('catSort asc')->select();
$trs3 = array();
$ids = array();
foreach ($trs3s as $key =>$v){
$trs3[$key]['catId'] = $v['catId'];
$trs3[$key]['parentId'] = $v['parentId'];
$trs3[$key]['catName'] = $v['catName'];
$trs3[$key]['catImg'] = strval($v['catImg']);
}
foreach ($trs3 as $v2){
$maprs[$v2['parentId']][] = $v2;
}
//倒序建立樹形
foreach ($trs2 as $v2){
$v2['childList'] = [];
if(isset($maprs[$v2['catId']]))$v2['childList'] = $maprs[$v2['catId']];
$rs2[] = $v2;
}
foreach ($trs1 as $v2){
foreach ($rs2 as $vv2){
if($vv2['parentId']==$v2['catId']){
$v2['childList'][] = $vv2;
}
}
$list[] = $v2;
}
Cache::set('WST_CACHE_GOODS_CAT_MOB',$list);
}
return $list;
}
/**
* 获取分类名
* @return [type] [description]
*/
public function getCatName(){
$catId = (int)input('post.catId');
$rs = $this->where(['catId'=>$catId])->field('catName')->find();
return $rs;
}
/**
* 获取分类信息
* @param integer $parentId [description]
* @return [type] [description]
*/
public function getGoodsCat($parentId=0){
$parentId=$parentId==0?(int)input('parentId'):$parentId;
$field = 'catId,parentId,catName,catImg';
// if($parentId > 0){//不是父级分类要加小图片
// $field .= ',catImg';
// }
return $this->where(["dataFlag"=>1,"isShow"=>1,"parentId"=>$parentId])->field($field)->order('catSort asc')->cache(true,864000)->select();
}
}

227
hyhproject/app/model/Index.php Executable file
View File

@ -0,0 +1,227 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Tags as T;
use think\Db;
/**
* ============================================================================
* 默认类
*/
class Index extends Base{
/**
* 楼层
*/
public function pageQuery(){
$limit = (int)input('post.currPage');//楼层页码
if($limit>9)return;
$cacheData = cache('MO_CATS_ADS'.$limit);
if($cacheData)return $cacheData;
$rs = Db::name('goods_cats')->where(['dataFlag'=>1,'isShow'=>1,'parentId'=>0,'isFloor'=>1])->field('catId,catName')->order('catSort asc')->limit($limit,1)->select();//按设定排序获取分类名称,异步下拉加载,传输楼层的层楼
if($rs){
$rs= $rs[0];//用select就选第一个其实可以改成find
$t = new T();
$rs['ads'] = $t->listAds('mo-ads-'.$limit,'1');//获取手机版楼层页面的广告图
$rs['goods'] = Db::name('goods')->alias('g')->join('__RECOMMENDS__ r','g.goodsId=r.dataId')
->where(['r.goodsCatId'=>$rs['catId'],'g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'r.dataSrc'=>0,'r.dataType'=>1])
->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')->order('r.dataSort asc')->limit(6)->select();
if(empty($rs['goods'])){
$rs['goods'] = Db::name('goods')->alias('g')
->where(['g.goodsCatIdPath'=>['like',$rs['catId'].'_%'],'g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'g.isHot'=>1])
->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')
->order('saleNum desc,goodsId asc')->limit(6)->select();
}
$rs['currPage'] = $limit;
}
cache('MO_CATS_ADS'.$limit,$rs,86400);
return $rs;
}
/**
* 猜你喜欢
*/
public function guess_like(){
$userId=(int)session('WST_USER.userId');
//$userId=50;
$page = (int)input('post.page/d');
$cacheData = cache('APP_CATS_LIKE_'.$page.'_'.$userId);
if($cacheData)return $cacheData;
$pagesize = input('pagesize/d');
$childId=[];
$parentId=[];
//$goods_result["Rows"]= '';//Db::name('goods')->alias('g')->join('__RECOMMENDS__ r','g.goodsId=r.dataId')
//->where(['g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'r.dataSrc'=>0,'r.dataType'=>1])
//->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')->order('rand()')->paginate($pagesize)->toArray();
//用户登录状态
// if($userId){
// //查找登录账号浏览过的记录
// $goods_ids=db('page_view')->where('userId',$userId)->field('count(goodsId)num,goodsId')
// ->group('goodsId')->order('num desc')->limit('18')->select();
// if($goods_ids){
// foreach($goods_ids as $key=>$value){
// $childId[]=$value['goodsId'];
// }
// //根据查找到的商品分类,寻找最顶级商品分类
// $goods_parents=$this->getParentIs($childId);
// foreach($goods_parents as $k=>$v){
// $parentId[]=$v;
// }
// }
// }
//用户未登录或顶级商品分类过少时进行全表查询
if(!$userId || count($parentId)<3){
$goods_ids=db('page_view')->where('1=1')->field('count(goodsId)num,goodsId')
->group('goodsId')->order('num desc,id desc')->limit('18')->select();
foreach($goods_ids as $key=>$value){
$childId[]=$value['goodsId'];
}
////根据查找到的商品分类,寻找最顶级商品分类
$goods_parents=$this->getParentIs($childId);
foreach($goods_parents as $k=>$v){
$parentId[]=$v;
}
}
//根据父级分类查找所有子级商品
$goods_child=$this->getChild('',$parentId);
$pagesize = input('pagesize/d');
//展现顶级分类下所有子级分类的商品
$goods_result=db('goods')->whereIn('goodsCatId',$goods_child)->order('visitNum desc')
->where(['isSale'=>1,'dataFlag'=>1,'goodsStatus'=>1,'isHot'=>1])
->field('goodsId,goodsName,goodsImg,shopPrice,saleNum')
->paginate($pagesize)->toArray();
// if(empty($goods_result["Rows"])){
// $goods_result = Db::name('goods')->alias('g')
// ->where(['g.isSale'=>1,'g.dataFlag'=>1,'g.goodsStatus'=>1,'g.isHot'=>1])
// ->field('g.goodsId,g.goodsName,g.goodsImg,g.shopPrice,g.saleNum')
// ->order('rand()')->paginate($pagesize)->toArray();
// }
cache('APP_CATS_LIKE_'.$page.'_'.$userId,$goods_result,3600);
return $goods_result;
}
/**
* 热卖推荐
*/
public function getHotGoods(){
$page = (int)input('page',1);
$cacheData = cache('QLG_HOT_GOODS_'.$page);
if($cacheData)return $cacheData;
$rs = Db::name('goods')
->where(['isSale'=>1,'dataFlag'=>1,'goodsStatus'=>1])
->field('goodsId,goodsName,goodsImg,shopPrice,saleNum,discountRate')
->order('discountRate DESC,goodsId DESC')
->paginate(input('pageSize/d',10))->toArray();
cache('QLG_HOT_GOODS_'.$page,$rs,3600);
return $rs;
}
/**
* 迭代获取下级
* 获取一个分类下的所有子级分类id
*/
public function getChild($data,$pid){
if(!$pid){
return;
}
$childId = db('goods_cats')->where("dataFlag=1")->whereIn('parentId',$pid)->field('catId,parentId')->select();
//获取该分类id下的所有子级分类id
foreach($childId as $key=>$value){
$child[]=$value['catId'];
}
static $ids = array();
foreach($childId as $k=>$v){
//dump($childId);
$ids[] = $v['catId'];//将找到的下级分类id放入静态数组
//再找下当前id是否还存在下级id
$this->getChild($childId, $v['catId']);
}
return $ids;
}
/**
* 根据子分类获取其父级分类
*/
public function getParentIs($id,$data = array()){
$data[] = $id;
$parentId = db('goods_cats')->where("dataFlag=1")->whereIn('catId',$id)->field('parentId')->select();
foreach($parentId as $key=>$value){
$parent[]=$value['parentId'];
}
if(!isset($parent)){
krsort($data);
//判断是否有值为0的数组元素
foreach ($data as $k => $v) {
foreach ($v as $key => $value) {
if(!$value){
unset($v[$key]);
}
}
if(!$v){
unset($data[$k]);
}
}
$da=array_unique(current($data));
return $da;
}else{
return $this->getParentIs($parent,$data);
}
}
//获取所有小广告位
public function getIndexAds(){
$cacheData = cache('APP_CATS_ADS');
if($cacheData)return $cacheData;
$where['positionCode'] = ['LIKE','%mo-ads-index-%'];
$where['positionType'] = 3;
$where['dataFlag'] = 1;
$positions_list = Db::name('ad_positions')->where($where)->field('positionId,positionName')->cache(true,86400)->select();
unset($where['positionCode'] );
$date = date('Y-m-d');
$where['adStartDate'] = ['<=',$date];
$where['adEndDate'] = ['>=',$date];
$list=[];
foreach($positions_list as &$v){
$where['adPositionId'] = $v['positionId'];
$list[$v['positionId']]['name'] = $v['positionName'];
$ads_list = Db::name('ads')->where($where)->field('adFile,adURL,targetType')->cache(true,86400)->select();
$list[$v['positionId']]['list'] = $ads_list;
}
cache('APP_CATS_ADS',$list,86400);
return $list;
}
//获取首页轮播图
public function getIndexTopImg(){
$cacheData = cache('APP_TOP_IMG');
if($cacheData)return $cacheData;
$ads_list=[];
$ads_list = listAds('mo-ads-index',9,86400);
cache('APP_TOP_IMG',$ads_list,86400);
return $ads_list;
}
//获取首页横图
public function getIndexCrossImg(){
$cacheData = cache('APP_CROSS_IMG');
if($cacheData)return $cacheData;
$ads_list=[];
$ads_list['cross_top'] = listAds('mo-index-cross-top',6,86400);
$ads_list['cross_bottom'] = listAds('mo-index-cross-down',6,86400);
cache('APP_CROSS_IMG',$ads_list,86400);
return $ads_list;
}
/**
* 获取系统消息
*/
function getSysMsg($msg='',$order=''){
$data = [];
$userId = (int)session('WST_USER.userId');
if($msg!=''){
$data['message']['num'] = Db::name('messages')->where(['receiveUserId'=>$userId,'msgStatus'=>0,'dataFlag'=>1])->count();
}
if($order!=''){
$data['order']['waitPay'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>-2,'dataFlag'=>1])->count();
$data['order']['waitSend'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>0,'dataFlag'=>1])->count();
$data['order']['waitReceive'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>1,'dataFlag'=>1])->count();
$data['order']['waitAppraise'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>2,'isAppraise'=>0,'dataFlag'=>1])->count();
$data['order']['cancelNum'] = 0;//Db::name('orders')->where('userId='.$userId.' AND (orderStatus=-1 OR orderStatus=-3)')->count();
}
return $data;
}
}

106
hyhproject/app/model/Messages.php Executable file
View File

@ -0,0 +1,106 @@
<?php
namespace wstmart\app\model;
use think\Db;
use wstmart\common\model\Messages as CMessages;
/**
* ============================================================================
* 商城消息
*/
class Messages extends CMessages{
/**
* 获取列表
*/
public function pageQuery(){
$from = input('from/d');
$userId = (int)session('WST_USER.userId');
$where['receiveUserId'] = (int)$userId;
$where['dataFlag'] = 1;
if(isset($from)){
$where['from'] = $from;
}
$page = $this->where($where)->order('msgStatus asc,id desc')->cache(true,30)->paginate(input('pagesize/d'))->toArray();
// foreach ($page['Rows'] as $key => $v){
// $page['Rows'][$key]['msgContent'] = WSTMSubstr(strip_tags(htmlspecialchars_decode($v['msgContent'])),0,140);
// }
foreach ($page['Rows'] as &$v){
if($v['from'] == 1){
$msgJson = json_decode($v['msgJson']);
//dump($msgJson);die;
$shopId = Db::name('orders')->where(['orderId'=>$msgJson->dataId])->cache(true,86400)->value('shopId');
$shopImg = Db::name('shops')->where(['shopId'=>$shopId])->cache(true,86400)->value('shopImg');
// Db::name('order o')
// ->join('__SHOPS s','o.shopId=s.shopId','inner join')
// ->field('shopId,shopImg')
// ->where(['o.orderId'=>$msgJson['dataId']])
// ->cache(true,86400)
// ->find();
$v['img'] = WSTImg($shopImg,3);
}else{
$v['img'] = '';
}
}
return $page;
}
/**
* 获取某一条消息详情
*/
public function getById(){
$userId = (int)session('WST_USER.userId');
$id = (int)input('msgId');
$data = $this->get(['id'=>$id,'receiveUserId'=>$userId]);
if(!empty($data)){
//$data['msgContent'] = htmlspecialchars_decode($data['msgContent']);
if($data['msgStatus']==0)
model('Messages')->where('id',$id)->setField('msgStatus',1);
}
return $data;
}
/**
* 删除
*/
public function del(){
$userId = (int)session('WST_USER.userId');
$id = input('id/d');
$data = [];
$data['dataFlag'] = -1;
$result = $this->update($data,['id'=>$id,'receiveUserId'=>$userId]);
if(false !== $result){
return WSTReturn("删除成功", 1);
}else{
return WSTReturn($this->getError(),-1);
}
}
/**
* 批量删除
*/
public function batchDel(){
$userId = (int)session('WST_USER.userId');
$ids = input('ids/a');
$data = [];
$data['dataFlag'] = -1;
$result = $this->update($data,['id'=>['in',$ids],'receiveUserId'=>$userId]);
if(false !== $result){
return WSTReturn("删除成功", 1);
}else{
return WSTReturn($this->getError(),-1);
}
}
/**
* 标记为已读
*/
public function batchRead(){
$userId = (int)session('WST_USER.userId');
$ids = input('ids/a');
$data = [];
$data['msgStatus'] = 1;
$result = $this->update($data,['id'=>['in',$ids],'receiveUserId'=>$userId]);
if(false !== $result){
return WSTReturn("操作成功", 1);
}else{
return WSTReturn($this->getError(),-1);
}
}
}

13
hyhproject/app/model/Orders.php Executable file
View File

@ -0,0 +1,13 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Orders as COrders;
use think\Db;
/**
* ============================================================================
* 订单类
*/
class Orders extends COrders{
function getOrderByOrderNo($orderNo,$field='*'){
return $this->where(['dataFlag'=>1,'orderNo|orderunique'=>$orderNo])->field($field)->find();
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Payments as CPayments;
/**
* ============================================================================
* 支付管理业务处理
*/
class Payments extends CPayments{
}

291
hyhproject/app/model/Shops.php Executable file
View File

@ -0,0 +1,291 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Shops as CShops;
use think\Db;
/**
* ============================================================================
* 门店类
*/
class Shops extends CShops{
public function getShopIndex(){
$shopId = (int)input('shopId');
$shopInfo = $this->where(['shopId'=>$shopId,'status'=>1,'shopStatus'=>1,'dataFlag'=>1])->field('shopImg,shopName,lat,lng,userName,phone')->find();
if(!$shopInfo) return WSTReturn('未找到此店铺');
$shopInfo['shopAds'] = (string)Db::name('shop_configs')->where(['shopId'=>$shopId])->value('shopAds');
return WSTReturn('',1,$shopInfo);
}
/**
* 店铺街列表
*/
public function pageQuery($pagesize){
$catId = (int)input("id");
$keyword = input("keyword");
$condition = input("condition");
$desc = input("desc");
$datas = array('sort'=>array('1'=>'ss.totalScore/ss.totalUsers'),'desc'=>array('desc','asc'));
$rs = $this->alias('s');
$where = [];
$where['s.dataFlag'] = 1;
$where['s.shopStatus'] = 1;
$where['s.status'] = 1;
if($keyword!='')$where['s.shopName'] = ['like','%'.$keyword.'%'];
if($catId>0){
$rs->join('__CAT_SHOPS__ cs','cs.shopId = s.shopId','left');
$where['cs.catId'] = $catId;
}
$order = ['s.shopId'=>'asc'];
if($condition>0){
$order = [$datas['sort'][$condition]=>$datas['desc'][$desc]];
}
$page = $rs->join('__SHOP_SCORES__ ss','ss.shopId = s.shopId','left')
->where($where)->order($order)
->field('s.shopId,s.shopImg,s.shopName,s.shopCompany,ss.totalScore,ss.totalUsers,ss.goodsScore,ss.goodsUsers,ss.serviceScore,ss.serviceUsers,ss.timeScore,ss.timeUsers,s.areaIdPath')
->paginate($pagesize)->toArray();
foreach ($page['Rows'] as $key =>$v){
//商品列表
$goods = db('goods')->where(['dataFlag'=> 1,'isSale'=>1,'goodsStatus'=> 1,'shopId'=> $v["shopId"]])->field('goodsId,goodsName,shopPrice,goodsImg')
->order('saleTime desc')->limit(3)->select();
$page['Rows'][$key]['goods'] = $goods;
}
if(empty($page['Rows']))return $page;
$shopIds = [];
$areaIds = [];
foreach ($page['Rows'] as $key =>$v){
$shopIds[] = $v['shopId'];
// $tmp = explode('_',$v['areaIdPath']);
// $areaIds[] = $tmp[1];
//$page['Rows'][$key]['areaId'] = $tmp[1];
//总评分
$page['Rows'][$key]['totalScore'] = WSTScore($v["totalScore"]/3, $v["totalUsers"]);
$page['Rows'][$key]['goodsScore'] = WSTScore($v['goodsScore'],$v['goodsUsers']);
$page['Rows'][$key]['serviceScore'] = WSTScore($v['serviceScore'],$v['serviceUsers']);
$page['Rows'][$key]['timeScore'] = WSTScore($v['timeScore'],$v['timeUsers']);
}
$rccredMap = [];
$goodsCatMap = [];
$areaMap = [];
//认证、地址、分类
if(!empty($shopIds)){
$rccreds = Db::name('shop_accreds')->alias('sac')->join('__ACCREDS__ a','a.accredId=sac.accredId and a.dataFlag=1','left')
->where('shopId','in',$shopIds)->field('sac.shopId,accredName,accredImg')->select();
foreach ($rccreds as $v){
$rccredMap[$v['shopId']][] = $v;
}
$goodsCats = Db::name('cat_shops')->alias('cs')->join('__GOODS_CATS__ gc','cs.catId=gc.catId and gc.dataFlag=1','left')
->where('shopId','in',$shopIds)->field('cs.shopId,gc.catName')->select();
foreach ($goodsCats as $v){
$goodsCatMap[$v['shopId']][] = $v['catName'];
}
$areas = Db::name('areas')->alias('a')->join('__AREAS__ a1','a1.areaId=a.parentId','left')
->where('a.areaId','in',$areaIds)->field('a.areaId,a.areaName areaName2,a1.areaName areaName1')->select();
foreach ($areas as $v){
$areaMap[$v['areaId']] = $v;
}
}
foreach ($page['Rows'] as $key =>$v){
$page['Rows'][$key]['accreds'] = (isset($rccredMap[$v['shopId']]))?$rccredMap[$v['shopId']]:[];
$page['Rows'][$key]['catshops'] = (isset($goodsCatMap[$v['shopId']]))?implode(',',$goodsCatMap[$v['shopId']]):'';
//$page['Rows'][$key]['areas']['areaName1'] = (isset($areaMap[$v['areaId']]['areaName1']))?$areaMap[$v['areaId']]['areaName1']:'';
//$page['Rows'][$key]['areas']['areaName2'] = (isset($areaMap[$v['areaId']]['areaName2']))?$areaMap[$v['areaId']]['areaName2']:'';
}
return $page;
}
/**
* 获取卖家中心信息
*/
public function getShopSummary(){
$shopId = (int)input('shopId',1);
$shop = $this->alias('s')->join('__SHOP_SCORES__ cs','cs.shopId = s.shopId','left')
->where(['s.shopId'=>$shopId,'dataFlag'=>1])
->field('s.shopId,shopImg,shopName,shopkeeper,shopAddress,shopQQ,shopTel,serviceStartTime,serviceEndTime,isInvoice,invoiceRemarks,cs.*')
->find();
//评分
$scores['totalScore'] = WSTScore($shop['totalScore'],$shop['totalUsers']);
$scores['goodsScore'] = WSTScore($shop['goodsScore'],$shop['goodsUsers']);
$scores['serviceScore'] = WSTScore($shop['serviceScore'],$shop['serviceUsers']);
$scores['timeScore'] = WSTScore($shop['timeScore'],$shop['timeUsers']);
WSTUnset($shop, 'totalUsers,goodsUsers,serviceUsers,timeUsers');
$shop['scores'] = $scores;
//认证
$accreds = $this->shopAccreds($shopId);
$shop['accreds'] = $accreds;
return ['shop'=>$shop];
}
/**
* 自营店铺楼层
*/
public function getFloorData(){
$limit = (int)input('post.currPage');
$cacheData = cache('WX_SHOP_FLOOR'.$limit);
if($cacheData)return $cacheData;
$rs = Db::name('shop_cats')->where(['dataFlag'=>1,'isShow'=>1,'parentId'=>0,'shopId'=>1])->field('catId,catName')->order('catSort asc')->limit($limit,1)->select();
if($rs){
$rs= $rs[0];
$goods = Db::name('goods')->where('shopCatId1','=',$rs['catId'])->where(['dataFlag'=>1,'goodsStatus'=>1])->field('goodsId,goodsName,goodsImg,shopPrice,saleNum')->order('isHot desc')->limit(4)->select();
$rs['goods'] = $goods;
$rs['currPage'] = $limit;
}
cache('WX_SHOP_FLOOR'.$limit,$rs,86400);
return $rs;
}
/**
* 根据订单id 获取店铺名称
*/
public function getShopName($oId){
return $this->alias('s')
->join('__ORDERS__ o',"s.shopId=o.shopId",'inner')
->where("o.orderId=$oId")
->value('s.shopName');
}
/**
* 添加查看记数
* @param [type] $rewardId [description]
* @param [type] $userId [description]
*/
public function setRewardVisit($rewardId,$userId){
$reward_num = Db::name('reward_num');
$where['rewardId'] = $rewardId;
$where['userId'] = $userId;
if($reward_num->where($where)->find()){
$reward_num->where($where)->setField('isVisit',1);
}else{
$data['rewardId'] = $rewardId;
$data['userId'] = $userId;
$data['isVisit'] = 1;
$reward_num->insert($data);
}
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('visitNum');
}
/**
* 点赞记数
* @param [type] $rewardId [description]
* @param [type] $userId [description]
*/
public function setRewardLike($rewardId,$userId,$isLike){
$reward_num = Db::name('reward_num');
$where['rewardId'] = $rewardId;
$where['userId'] = $userId;
$dbIsLike = $reward_num->where($where)->value('isLike');
if(isset($dbIsLike)){
if($dbIsLike != $isLike){
$reward_num->where($where)->setField('isLike',$isLike);
if($isLike == 1){
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('likeNum');
}else{
Db::name('rewards')->where(['rewardId'=>$rewardId])->setDec('likeNum');
}
}
}else{
$data['rewardId'] = $rewardId;
$data['userId'] = $userId;
$data['isLike'] = $isLike;
$reward_num->insert($data);
if($isLike == 1){
Db::name('rewards')->where(['rewardId'=>$rewardId])->setInc('likeNum');
}
}
}
/**
* mark 20180518 by zl
*获取商店特产省份
*@param $shopId 商店id
*
*/
public function getProv($shopId=1){
$where['shopId'] = $shopId;
$where['dataFlag'] = 1;
$where['provId'] = ['>','0'];
$prov = Db::name('shop_cats')->distinct(true)->field('provId,provName')->where($where)->order('provId asc')->select();
return $prov;
}
/**
*获取商店特产省份
*@param $shopId 商店id
*@param $provId 省份id
*/
public function getShopCats($shopId=1,$provId=0){
$where['shopId'] = $shopId;
if($provId)$where['provId'] = $provId;
$where['parentId'] = 0;
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$cats = Db::name('shop_cats')->where($where)
->field('catId,catName,shopId,provId,provName,catImg')
->order("catId asc")->select();
return $cats;
}
/**
*根据商店分类获取商品列表
*@param $shopId 商店id
*@param $shopCatId1 商店一级分类
*/
public function getGoodsByShopCats($shopId=1,$shopCatId1,$page=1){
$cacheData = cache('APP_GOODS_BY_SHOPCAT_'.$shopId.'_'.$shopCatId1.'_'.$page);
if($cacheData)return $cacheData;
$where['shopId'] = $shopId;
$where['shopCatId1'] = $shopCatId1;
$where['dataFlag'] = 1;
$where['isSale'] = 1;
$where['goodsStatus'] = 1;
$pagesize = 8;
$offset = ($page-1)*$pagesize;
$limit = "{$offset},{$pagesize}";
$goods = Db::name('goods')->where($where)->limit($limit)->order("saleNum desc")->select();
$list['goods'] = $goods;
$list['page'] = $page;
// $list = Db::name('goods')->where($where)->paginate($pagesize)->toArray();
cache('APP_GOODS_BY_SHOPCAT_'.$shopId.'_'.$shopCatId1.'_'.$page,$list,600);
return $list;
}
/**
*获取首页热门特产榜单
*
*/
public function getHotList($shopId=1){
$where['shopId'] = $shopId;
$where['dataFlag'] = 1;
$where['isShow'] = 1;
$cat1 = cache('APP_HOT_LIST');
if(!empty($cat1))return $cat1;
//获取一级分类
$cat1 = Db::name('shop_cats')->field('catId,catName')->where($where)->where(['isHot'=>1,'parentId'=>0])->order('catSort asc')->select();
if(count($cat1)>0){
foreach($cat1 as $k=>$v){
//获取二级分类
$cat2 = Db::name('shop_cats')->field('catId,catName')->where($where)->where(['parentId'=>$v['catId']])->select();
if(count($cat2)>0){
foreach($cat2 as $kk=>$vv){
//获取二级分类下的商品
$vv['goods'] = $this->getGoodsByCats($shopId,$v['catId'],$vv['catId']);
if(isset($vv['goods'])){
foreach ($vv['goods'] as $key => $value) {
$vv['goods'][$key]['goodsImg'] = WSTImg($value['goodsImg'],2);
}
}
$cat1[$k]['cat2'][] = $vv;
}
}
}
}
cache('APP_HOT_LIST',$cat1,600);
return $cat1;
}
//根据分类获取商品数据
public function getGoodsByCats($shopId=1,$catId1,$catId2){
$where['dataFlag'] = 1;
$where['goodsStatus'] = 1;
$where['isSale'] = 1;
$where['shopId'] = $shopId;
$where['shopCatId1'] = $catId1;
$where['shopCatId2'] = $catId2;
$goods = Db::name('goods')->field('goodsId,goodsName,goodsImg,shopPrice')->where($where)->order('visitNum desc')->limit(2)->select();
return $goods;
}
/**
* end
*/
}

83
hyhproject/app/model/Tags.php Executable file
View File

@ -0,0 +1,83 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Tags as CTags;
use think\Db;
/**
* 标签业务处理类
*/
class Tags extends CTags{
/**
* 获取最新文章
*/
public function newArticle(){
// $rs = Db::name('articles')->alias('a')->field('a.articleId,a.articleTitle,a.coverImg,a.createTime')->join('article_cats ac','a.catId=ac.catId','inner')
// ->where('ac.catType=0 and ac.parentId=8 and a.dataFlag=1 and ac.isShow=1')->order('a.createTime','desc')->cache(true,86400)->paginate(input('pagesize/d'))->toArray();
//return $rs;
$page = input('page');
$cacheData = cache('TAG_NEW_ARTICLES'.$page);
if($cacheData)return $cacheData;
$rs = Db::name('articles')->alias('a')->field('a.articleId,a.articleTitle,a.coverImg,a.createTime')->join('article_cats ac','a.catId=ac.catId','inner')
->where('ac.catType=0 and ac.parentId<>7 and a.dataFlag=1 and ac.isShow=1 and a.isShow=1 and ac.dataFlag=1')->order('a.createTime','desc')->paginate(input('pagesize/d'))->toArray();
cache('TAG_NEW_ARTICLES'.$page,$rs,86400);
return $rs;
}
//添加显示会员快报 make cheng 20180227
public function showArticle(){
$articleId = input('articleId/d');
$article = Db::name('articles')->where('articleId', $articleId)->field('articleTitle,articleContent,createTime')->find();
$article['articleContent']=htmlspecialchars_decode($article['articleContent']);
return WSTReturn('', 1, $article);
}
/**
* 桔子头条分类
*/
public function orangeType(){
//$catName= '商城快讯';
$orange = [];
//$catId =(int)Db::name('article_cats')->where(['catName'=>$catName,'dataFlag'=>1])->value('catId');
$catId = 8;
if($catId){
$orange = Db::name('article_cats')->where(['parentId'=>$catId,'dataFlag'=>1])->select();
}
return $orange;
// dump($frontPage);die;
}
/**
* @param $catName
* @return array
* 桔子头条文章
*/
public function clog($catId){
// $catId = input('catId');
// echo $catId;die;
$pageSize = (int)input('pageSize/d',10);
$where = array();
$where['isShow'] = 1;
$where['dataFlag'] = 1;
$where['catId'] = $catId;
// var_dump($where);die;
$clog = Db::name('articles')->where($where)->paginate($pageSize)->toArray();
foreach($clog['Rows'] as &$v){
$v['coverImg'] = WSTImg($v['coverImg'],3);
$v['articleContent']=htmlspecialchars($v['articleContent']);
}
return $clog;
}
/**
* 桔子头条文章详情
*/
public function detail($articleId){
$detail = Db::name('articles')->where('articleId',$articleId)->find();
// foreach($detail as &$v){
// $v['coverImg'] = WSTImg($v['coverImg'],2);
// }
$detail['articleContent']=htmlspecialchars_decode($detail['articleContent']);
return $detail;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Users as CUsers;
use Think\Db;
/**
* ============================================================================
* 用户类
*/
class Users extends CUsers{
/**
* 验证用户支付密码
*/
function checkPayPwd(){
$payPwd = input('payPwd');
$decrypt_data = WSTRSA($payPwd);
if($decrypt_data['status']==1){
$payPwd = $decrypt_data['data'];
}else{
return jsonReturn('验证失败');
}
$userId = (int)session('WST_USER.userId');
$rs = $this->field('payPwd,loginSecret')->find($userId);
if($rs['payPwd']==md5($payPwd.$rs['loginSecret'])){
return jsonReturn('',1);
}
return jsonReturn('支付密码错误',-1);
}
/**
* 获取首页数据
* @param [type] $userId [description]
* @return [type] [description]
*/
function getIndex($userId){
}
function getUserInfo($userId,$field){
return $this->where(['userId'=>$userId])->field($field)->find();
}
function appLogOut($userId){
$this->where(['userId'=>$userId])->setField('token','');
session('WST_USER',null);
//setcookie("loginPwd", null);
session('WST_MO_WlADDRESS',null);
}
}

48
hyhproject/app/model/Users.php Executable file
View File

@ -0,0 +1,48 @@
<?php
namespace wstmart\app\model;
use wstmart\common\model\Users as CUsers;
use Think\Db;
/**
* ============================================================================
* 用户类
*/
class Users extends CUsers{
/**
* 验证用户支付密码
*/
function checkPayPwd(){
$payPwd = input('payPwd');
$decrypt_data = WSTRSA($payPwd);
if($decrypt_data['status']==1){
$payPwd = $decrypt_data['data'];
}else{
return jsonReturn('验证失败');
}
$userId = (int)session('WST_USER.userId');
$rs = $this->field('payPwd,loginSecret')->find($userId);
if($rs['payPwd']==md5($payPwd.$rs['loginSecret'])){
return jsonReturn('',1);
}
return jsonReturn('支付密码错误',-1);
}
/**
* 获取首页数据
* @param [type] $userId [description]
* @return [type] [description]
*/
function getIndex($userId){
}
function getUserInfo($userId,$field){
return $this->where(['userId'=>$userId])->field($field)->find();
}
function appLogOut($userId){
$this->where(['userId'=>$userId])->setField('token','');
session('WST_USER',null);
//setcookie("loginPwd", null);
session('WST_MO_WlADDRESS',null);
}
}