canyin-project/ybcy/controllers/channelApi/GoodController.php
2024-11-01 16:07:54 +08:00

551 lines
30 KiB
PHP

<?php
namespace app\controllers\channelApi;
use http\Params;
use Illuminate\Support\Facades\DB;
use Yii;
use app\models\common\Config;
use app\models\common\Order;
use app\models\common\Store;
use app\models\common\Power;
use app\models\common\Member;
use app\models\common\Good;
class GoodController extends CommonController{
//获取指定门店的商品
public function actionGetProductList(){
$request = Yii::$app->request;
$uniacid=$this->wqData['uniacid'];
$userId=$this->wqData['userId'];
$result=axios_request();
$goodsType=$result['goodsType']?:1;
if($request->isGet){
$power=Power::getPower($this->wqData['uniacid']);
$storeModel=$power['shopModel']?:2;
if($storeModel==1){
$store=(new \yii\db\Query())
->select('id')
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND deleteAt=0 AND isMain=1',[':uniacid'=>$this->wqData['uniacid']])->one();
$storeId=$store['id'];
}else{
$storeSet=Config::getSystemSet('storeSet',$this->wqData['uniacid']);
$enterStore=$storeSet['enterStore']?:1;
$user=(new \yii\db\Query())
->select(['browseStoreId'])
->from('{{%ybwm_member}}')
->where('id=:id AND uniacid='.$this->wqData['uniacid'],[':id'=>$this->wqData['userId']])->one();
if($result['storeId'] or ($enterStore==1 AND $user['browseStoreId'])){
$storeId=$result['storeId']?:$user['browseStoreId'];
}else{
$table=(new \yii\db\Query())
->select(['id'])
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND deleteAt=0 AND display=1',[':uniacid'=>$this->wqData['uniacid']]);
$store=$table->orderby(["SQRT(POWER(" . $result['lat'] . " - lat, 2) + POWER(" . $result['lng'] . " - lng,2))"=>SORT_ASC])->one();
$storeId=$store['id'];
}
}
Yii::$app->db->createCommand()->update('{{%ybwm_member}}', ['browseStoreId'=>$storeId],['id'=>$this->wqData['userId']])->execute();
// if($result['storeId']){
// $storeId=$result['storeId'];
// }else{
//
// $store=(new \yii\db\Query())
// ->select(['id'])
// ->from('{{%ybwm_store}}')
// ->where('uniacid=:uniacid AND deleteAt=0',[':uniacid'=>$uniacid])
// ->orderby(["SQRT(POWER(" . $result['lat'] . " - lat, 2) + POWER(" . $result['lng'] . " - lng,2))"=>SORT_ASC])->one();
// $storeId=$store['id'];
// }
$storeRe=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND id=:id',[':uniacid'=>$uniacid,':id'=>$storeId])
->one();
$res=Good::getGoodSData($uniacid,$storeId,$this->wqData['userId'],$goodsType);
//推荐商品
if($storeRe['isMain']==2&&$storeRe['goodsModel']<3) {
$recommend_good = (new \yii\db\Query())
->select('a.goodsId id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.isSpecs,b.isAttr,b.isMaterial')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.goodsType'=>$goodsType,'b.deleteAt' => 0, 'a.uniacid' => $uniacid, 'a.storeId' => $storeId, 'a.display' => 1, 'a.isRecommend' => 1])
->orderBy('sort asc,id desc')
->limit(10)
->all();
}else{
$recommend_good = (new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,isSpecs,isAttr,isMaterial')
->from('{{%ybwm_core_goods}}')
->where(['goodsType'=>$goodsType,'deleteAt' => 0, 'uniacid' => $uniacid, 'storeId' => $storeId, 'display' => 1, 'isRecommend' => 1])
->orderBy('sort asc,id desc')
->limit(10)
->all();
}
for($g=0;$g<count($recommend_good);$g++){
$activityGoodData=Good::getGoodActivity($uniacid,$result['storeId'],$recommend_good[$g]['price'],$recommend_good[$g]['id'],$goodsType);
$recommend_good[$g]['activityGoodData']=$activityGoodData;
$recommend_good[$g]['vipPrice']=Member::getDiscountByGood($userId,$recommend_good[$g]['id'],$recommend_good[$g]['price'])['money'];
if($activityGoodData['type']==1 || $activityGoodData['type']==2 || $activityGoodData['type']==3){
$recommend_good[$g]['vipPrice']=Member::getDiscountByGood($userId,$recommend_good[$g]['id'],$activityGoodData['activityMoney'])['money'];
}
// $recommend_good[$g]['vipPrice']=Member::getDiscountByGood($this->wqData['userId'],$recommend_good[$g]['id'],$recommend_good[$g]['price'])['money'];
}
$shopData=(new \yii\db\Query())
->select('id,name,icon,lat,lng,storeOpen,timeType,timeArr,judgeOpen,storeTel,address,perCapita,environment,mainDishes,introduction,foodRecords,license')
->addSelect(['ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(('.$result['lat'].' * PI() / 180 - lat * PI() / 180) / 2),2) + COS('.$result['lat'].' * PI() / 180) * COS(lat * PI() / 180) * POW(SIN(('.$result['lng'].' * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS distance'])
->from('{{%ybwm_store}}')
->where(['id'=>$storeId])
->one();
$shopData['license']=json_decode($shopData['license'],true);
$shopData['foodRecords']=json_decode($shopData['foodRecords'],true);
$shopData['environment']=json_decode($shopData['environment'],true);
$shopData['timeArr']=json_decode($shopData['timeArr'],true);
$shopData['storeOpen']=Store::getStoreOutBusiness($storeId,$goodsType);
$distribution=Order::getDeliveryMoney($result['lat'],$result['lng'],$storeId);
if($distribution){
$shopData['distribution']=$distribution;
}else{
$deliverySet=Config::getStoreSet('delivery',$storeId);
$shopData['distribution']=['startMoney' => '0','fullMoney' => '0','money' => '0'];
if($deliverySet['type']==1){
$shopData['distribution']=['startMoney' => $deliverySet['fixedStartMoney']?:0,'fullMoney' => '0','money' => $deliverySet['money']?:0];
}
if($deliverySet['type']==2){
$shopData['distribution']=['startMoney' => $deliverySet['startMoney']?:0,'fullMoney' => '0','money' => $deliverySet['distanceStartMoney']?:0];
}
if($deliverySet['type']==3){
$shopData['distribution']=['startMoney' => $deliverySet['areaArr'][0]['startMoney']?:0,'fullMoney' => '0','money' => $deliverySet['areaArr'][0]['money']?:0];
}
}
//var_dump($distribution);die;
$shopData['deliveryMode']=Config::getStoreSet('deliveryMode',$storeId)['first']?:1;//配送方式
$set=Power::getPower($this->wqData['uniacid'],'makeName');
$yunbeiName=Power::getPower($this->wqData['uniacid'],'yunbeiName');
switch ($shopData['deliveryMode']){
case 1;
$shopData['deliveryMode']='商户自配送';
break;
case 2;
$shopData['deliveryMode']='达达';
break;
case 3;
$shopData['deliveryMode']='点我达';
break;
case 4;
$shopData['deliveryMode']=$set['makeName']?:'码科';
break;
case 5;
$shopData['deliveryMode']='顺丰';
break;
case 6;
$shopData['deliveryMode']='蜂鸟';
break;
case 7;
$shopData['deliveryMode']='闪送';
break;
case 8;
$shopData['deliveryMode']='UU跑腿';
break;
case 9;
$shopData['deliveryMode']=$yunbeiName['yunbeiName']?:'云贝配送';
break;
}
$shopData['delivery']=Config::getStoreSet('delivery',$storeId)['range'];//配送范围
if($goodsType==1){
$moreSet=Config::getStoreSet('takeOutSet', $storeId);
$currency=Config::getSystemSet('currency',$uniacid);
$moreSet['auto']=$currency['first']?:1;
$moreSet['outName']=$currency['outName']?:'外卖';
$moreSet['selfName']=$currency['selfName']?:'自提';
$moreSet['confirmSwitch']=$currency['confirmSwitch']?:2;
}else{
$fastSet=Config::getStoreSet('fastSet', $storeId);
$moreSet=Config::getStoreSet('instoreSet', $storeId);
$moreSet['fastNotice']=$fastSet['notice']?:'门店暂无公告';
$moreSet['fastOrderNotice']=$fastSet['orderNotice']?:'门店暂无公告';
}
$showCategoryIcon=Config::getSystemSet('showCategoryIcon',$uniacid);
$moreSet['goodload']=$showCategoryIcon['goodload']?:1;
$advanceSet=Config::getStoreSet('advanceSet', $storeId);
$status=$advanceSet['restOpen']?:2;
if(!$advanceSet['open']){
$status=2;
}
if($status==1 AND $shopData['storeOpen']==2){
$moreSet['distributionSupport']=$advanceSet['open'];
}
$moreSet['status']=$status;
$display=Config::getSystemSet('showCategoryIcon',$uniacid)?:['display'=>2];
$collection=(new \yii\db\Query())
->from('{{%ybwm_user_collection}}')
->where('userId=:userId AND collectionId=:collectionId AND type=1 AND state=1',[':userId'=>$this->wqData['userId'],':collectionId'=>$storeId])->one();
if($collection){
$shopData['isCollection']=1;
}else{
$shopData['isCollection']=2;
}
$data=array(
'data'=>$res,
'shopData'=>$shopData,
'recommendData'=>$recommend_good,
'moreSet'=>$moreSet,
'categorySet'=>$display
);
$now=time();
$newReduction=(new \yii\db\Query())
->select('money')
->from('{{%ybwm_new_reduction}}')
->where('deleteAt=0 AND display=1 AND startTime<=:startTime AND endTime>:endTime',[':startTime'=>$now,':endTime'=>$now])
->andWhere(['storeId'=>$storeId])->one();
$data['discount']['newReduction']=$newReduction['money']?:0;
//满减
if($result['isKc']==1){
$reduceItem=3;
}else{
$reduceItem=$goodsType;
}
$reduce=(new \yii\db\Query())
->from('{{%ybwm_store_reduce}}')
->where('deleteAt=0 AND display=1 AND startTime<=:startTime AND endTime>:endTime',[':startTime'=>$now,':endTime'=>$now])
->andWhere(['like','week',date('w')])
->andWhere(['uniacid'=>$uniacid])
->andWhere(['like','useType',$reduceItem])
->andWhere(['or',['and',['storeId'=>$storeId,'storeType'=>1]],['and',['storeType'=>2],['uniacid'=>$uniacid]],['and',['storeType'=>3],['like','storeArr',$storeId]]])
->one();
$isNew=Order::isNew($storeId,$this->wqData['userId'],$reduceItem);
if($reduce['people']==1 || ($isNew==2 AND $reduce['people']==2) ){
$reduce['moneyArr']=json_decode($reduce['moneyArr'],true);
$data['discount']['reduce']=$reduce;
}else{
$data['discount']['reduce']=[];
}
$give=(new \yii\db\Query())
->from('{{%ybwm_give}}')
->where('deleteAt=0 AND display=1 AND startTime<=:startTime AND endTime>:endTime',[':startTime'=>$now,':endTime'=>$now])
->andWhere(['uniacid'=>$uniacid])
->andWhere(['like','week',date('w')])
->andWhere(['like','useType',1])
->andWhere(['or',['storeId'=>$storeId,'storeType'=>1],['storeType'=>2],['and',['storeType'=>3],['like','storeArr',$storeId]]])
->one();
if($give){
$give['moneyArr']=json_decode($give['moneyArr'],true);
$data['discount']['give']=$give;
}else{
$data['discount']['give']=[];
}
$grant=(new \yii\db\Query())
->select('name,orderMoney')
->from('{{%ybwm_order_grant_coupon}}')
->where('deleteAt=0 AND display=1 AND startTime<=:startTime AND endTime>:endTime',[':startTime'=>$now,':endTime'=>$now])
->andWhere(['uniacid'=>$uniacid])
->andWhere(['or',['storeId'=>$storeId,'storeType'=>1],['storeType'=>2],['and',['storeType'=>3],['like','storeArr',$storeId]]])
->one();
if($grant){
$data['discount']['grantCoupon']=$grant;
}else{
$data['discount']['grantCoupon']=[];
}
echo json_encode(['code'=>1,'msg'=>'成功','data'=>$data]);die;
//return $this->result(1,'成功',$re,$count);
}
}
public function actionGetGoodDetail(){
$result=axios_request();
$storeId=intval($result['storeId'])?:Store::getMainStore($this->wqData['uniacid'])['id'];
$userId=$this->wqData['userId'];
$uniacid=$this->wqData['uniacid'];
$storeRe=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND id=:id',[':uniacid'=>$uniacid,':id'=>$storeId])
->one();
$array=array(
'uniacid'=>$this->wqData['uniacid'],
'storeId'=>$storeId,
'goodsId'=>$result['goodsId'],
'createdAt'=>time(),
'ip'=>getIps(),
'userId'=>$this->wqData['userId'],
);
Yii::$app->db->createCommand()->insert('{{%ybwm_goods_visit}}', $array)->execute();
if($storeRe['isMain']==1||$storeRe['goodsModel']==3){
$data=(new \yii\db\Query())
->select('a.goodsType,a.media,a.unit,c.icon as storeIcon,a.storeId,a.id,a.name,a.icon,0 + CAST(price AS CHAR)price,(a.salesNum+a.virtualSales)salesNum,a.stock,a.minNum,a.maxNum,a.num,a.body,a.details,b.name labelName,b.color as labelColor,a.isSpecs,a.isAttr,a.isMaterial')
->from('{{%ybwm_core_goods}} as a')
->leftJoin('{{%ybwm_core_label}} b','a.goodLabel=b.id')
->leftJoin('{{%ybwm_store}} c','a.storeId=c.id')
->where(['a.id'=>$result['goodsId'],'a.storeId'=>$storeId])
->one();
}else{
$data=(new \yii\db\Query())
->select('d.goodsType,d.media,d.unit,c.icon as storeIcon,a.storeId,d.id,d.name,d.icon,0 + CAST(a.price AS CHAR)price,(a.salesNum+d.virtualSales)salesNum,a.stock,d.minNum,d.maxNum,d.num,d.body,d.details,b.name labelName,b.color as labelColor,d.isSpecs,d.isAttr,d.isMaterial')
->from('{{%ybwm_store_goods}} as a')
->leftJoin('{{%ybwm_store}} c','a.storeId=c.id')
->leftJoin('{{%ybwm_core_goods}} d','d.id=a.goodsId')
->leftJoin('{{%ybwm_core_label}} b','d.goodLabel=b.id')
->where(['d.id'=>$result['goodsId'],'a.storeId'=>$storeId])
->one();
}
if($data){
$data['media']=json_decode($data['media'],true);
}
$activityGoodData=Good::getGoodActivity($uniacid,$storeId,$data['price'],$data['id'],$data['goodsType']);
$data['activityGoodData']=$activityGoodData;
$data['vipPrice']=Member::getDiscountByGood($userId,$data['id'],$data['price'])['money'];
if($activityGoodData['type']==1 || $activityGoodData['type']==2 || $activityGoodData['type']==3){
$data['vipPrice']=Member::getDiscountByGood($userId,$data['id'],$activityGoodData['activityMoney'])['money'];
}
return $this->result(1,'成功',$data?:[]);
}
public function actionGetGoodOper(){
$request = Yii::$app->request;
if($request->isGet){
$result=axios_request();
$storeRe=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('uniacid=:uniacid AND id=:id',[':uniacid'=>$this->wqData['uniacid'],':id'=>$result['storeId']])
->one();
if($storeRe['isMain']==1||$storeRe['goodsModel']==3){
$specsData=(new \yii\db\Query())
->select('id,specsName,fillType,SalesPrice,SalesStock,crossedPrice,goodCode,costPrice,boxMoney')
->from('{{%ybwm_good_specs}}')
->where('goodId=:goodId',[':goodId'=>$result['id']])
->all();
}else{
$goodsInfo=(new \yii\db\Query())->from('{{%ybwm_store_goods}} a')
->select('b.name,a.stock,a.price,a.deleteAt,a.display,a.data')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['a.goodsId'=>$result['id'],'a.storeId'=>$result['storeId']])->one();
$specsData=json_decode($goodsInfo['data'],true)['specs'];
}
for($i=0;$i<count($specsData);$i++){
$specsData[$i]['vipPrice']=Member::getDiscountByGood($this->wqData['userId'],$result['id'],$specsData[$i]['SalesPrice'])['money'];
}
$attrData=(new \yii\db\Query())
->select('id,attrName,attrStr')
->from('{{%ybwm_good_attribute}}')
->where(['goodId'=>$result['id']])
->all();
$meterialData=(new \yii\db\Query())
->select('id,materialName,SalesPrice,SalesStock,fillType')
->from('{{%ybwm_good_materia}}')
->where('goodId=:goodId',[':goodId'=>$result['id']])
->all();
foreach ($attrData as $k=>$v){
$attrData[$k]['attrStr']=json_decode($v['attrStr']);
}
$data=array(
'specsData'=>$specsData?:[],
'attrData'=>$attrData?:[],
'meterialData'=>$meterialData?:[],
);
echo json_encode(['code'=>1,'msg'=>'成功','data'=>$data]);die;
}
}
public function actionGoodVisitSave(){
$request = Yii::$app->request;
if($request->isPost){
$result=axios_request();
$array=array(
'uniacid'=>$this->wqData['uniacid'],
'storeId'=>$result['storeId'],
'goodsId'=>$result['goodsId'],
'createdAt'=>time(),
'ip'=>getIps(),
'userId'=>$this->wqData['userId'],
);
$re= Yii::$app->db->createCommand()->insert('{{%ybwm_goods_visit}}', $array)->execute();
if($re){
return $this->result(1,'成功');
}else{
return $this->result(2,'失败');
}
}
}
//拖拽式多种方式获取商品
/*
* type 1,手动选择商品id获取商品 ids
* 2选择分类获取商品 一级分类 pid 二级分类 pid id 数量 num
* 3通过营销属性获取商品 ranktype 1新品商品 2热卖商品 3推荐商品 数量 num
* */
public function actionGoodRankType(){
$request = Yii::$app->request;
$userId=$this->wqData['userId'];
if($request->isPost){
$result=axios_request();
$uniacid = $this->wqData['uniacid'];
$shopInfo=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where(['id' => $result['storeId'], 'uniacid' => $uniacid])
->one();
if($result['type']==1){
$ids=explode(',',$result['ids']);
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_core_goods}}')
->where(['goodsType'=>1,'storeId' => $result['storeId'], 'uniacid' =>$uniacid,'display'=>1,'deleteAt'=>0])
->andWhere(['in','id',$ids])
->andWhere(['>','stock',0])->orderBy('sort asc,id asc')
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['in','a.goodsId',$ids])
->andWhere(['>','a.stock',0])->orderBy('b.sort asc,b.id asc')
->all();
}
}elseif($result['type']==2){
if($result['storeId']&&$result['id']){
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.goodsType'=>1,'a.storeId' => $result['storeId'], 'b.uniacid' => $uniacid,'b.typePid' => $result['pid'],'b.typeId' => $result['id'],'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])->orderBy('b.sort asc,b.id asc')
->limit($result['num'])
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'b.typePid' => $result['pid'],'b.typeId' => $result['id'],'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])->orderBy('b.sort asc,b.id asc')
->limit($result['num'])
->all();
}
}else{
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_core_goods}}')
->where(['goodsType'=>1,'storeId' => $result['storeId'], 'uniacid' => $uniacid,'typePid' => $result['pid'],'display'=>1,'deleteAt'=>0])
->andWhere(['>','stock',0])->orderBy('sort asc,id asc')
->limit($result['num'])
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'b.typePid' => $result['pid'],'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])->orderBy('b.sort asc,b.id asc')
->limit($result['num'])
->all();
}
}
}elseif($result['type']==3){
//获取商品特色分类
if($result['ranktype']==1){
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_core_goods}}')
->where(['specialType'=>$result['ranktype'],'goodsType'=>1,'storeId' => $result['storeId'], 'uniacid' => $uniacid,'display'=>1,'deleteAt'=>0])
->andWhere(['>','stock',0])
->orderBy('sort asc,id asc')
->limit($result['num'])
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.specialType'=>$result['ranktype'],'b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])
->orderBy('b.sort asc,b.id asc')
->limit($result['num'])
->all();
}
}elseif($result['ranktype']==2){
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_core_goods}}')
->where(['specialType'=>$result['ranktype'],'goodsType'=>1,'storeId' => $result['storeId'], 'uniacid' => $uniacid,'display'=>1,'deleteAt'=>0])
->andWhere(['>','stock',0])
->orderBy('sort asc,id asc')
->limit($result['num'])
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.specialType'=>$result['ranktype'],'b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])
->orderBy('sort asc,id asc')
->limit($result['num'])
->all();
}
}elseif($result['ranktype']==3){
if($shopInfo['isMain']==1||$shopInfo['goodsModel']==3){
$data=(new \yii\db\Query())
->select('id,name,icon,0 + CAST(price AS CHAR)price,num,body')
->from('{{%ybwm_core_goods}}')
->where(['specialType'=>$result['ranktype'],'goodsType'=>1,'storeId' => $result['storeId'], 'uniacid' => $uniacid,'hotsaleType'=>1,'display'=>1,'deleteAt'=>0])
->andWhere(['>','stock',0])
->orderBy('sort asc,id asc')
->limit($result['num'])
->all();
}else{
$data=(new \yii\db\Query())
->select('b.id,b.name,b.icon,0 + CAST(a.price AS CHAR)price,b.num,b.body')
->from('{{%ybwm_store_goods}} a')
->leftJoin('{{%ybwm_core_goods}} b','a.goodsId=b.id')
->where(['b.specialType'=>$result['ranktype'],'b.goodsType'=>1,'a.storeId' => $result['storeId'], 'a.uniacid' => $uniacid,'b.hotsaleType'=>1,'a.display'=>1,'b.deleteAt'=>0])
->andWhere(['>','a.stock',0])
->orderBy('b.sort asc,b.id asc')
->limit($result['num'])
->all();
}
}
}
for($g=0;$g<count($data);$g++){
$activityGoodData=Good::getGoodActivity($uniacid,$result['storeId'],$data[$g]['price'],$data[$g]['id']);
$data[$g]['activityGoodData']=$activityGoodData;
$data[$g]['vipPrice']=Member::getDiscountByGood($userId,$data[$g]['id'],$data[$g]['price'])['money'];
if($activityGoodData['type']==1 || $activityGoodData['type']==2 || $activityGoodData['type']==3){
$data[$g]['vipPrice']=Member::getDiscountByGood($userId,$data[$g]['id'],$activityGoodData['activityMoney'])['money'];
}
// $data[$g]['vipPrice']=Member::getDiscountByGood($this->wqData['userId'],$data[$g]['id'],$data[$g]['price'])['money'];
}
echo json_encode(['code'=>1,'msg'=>'成功','data'=>$data,'storeId'=>$result['storeId']]);die;
//return $this->result(1,'成功',$data);
}
}
public function actionSelectGood(){
$result=axios_request();
$storeId=$result['storeId'];
$keyword=$result['keyword']?:'';
$uniacid=$this->wqData['uniacid'];
$page=$result['page']?:1;
$size=$result['size']?:10;
$goodsType=$result['item']?:1;
$res=Good::getSelectGoods($uniacid,$storeId,$keyword,$page,$size,$this->wqData['userId'],$goodsType);
return $this->result(1,'成功',$res);
}
}