71 lines
3.0 KiB
PHP
71 lines
3.0 KiB
PHP
|
<?php
|
||
|
namespace app\models\common;
|
||
|
use Yii;
|
||
|
use yii\db\ActiveRecord;
|
||
|
class Category extends ActiveRecord{
|
||
|
public function getCategoryList($uniacid,$storeId,$type,$page,$id=0){
|
||
|
$item=6;
|
||
|
if($type==2){
|
||
|
$item=9;
|
||
|
}
|
||
|
if($id){
|
||
|
$re=(new \yii\db\Query())
|
||
|
->select('id, customName,describe,sort,name,pid,icon,display,startTime,endTime,weekStr,isRequire,timeType')
|
||
|
->from('{{%ybwm_core_category}}')->where(['id'=>$id])->one();
|
||
|
$re['weekStr']=json_decode($re['weekStr'],true);
|
||
|
$count=1;
|
||
|
}else{
|
||
|
$query=(new \yii\db\Query())
|
||
|
->select('id, customName,describe,sort,name,pid,icon,display,startTime,endTime,weekStr,isRequire,timeType')
|
||
|
->from('{{%ybwm_core_category}}')
|
||
|
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'storeId'=>$storeId,'item'=>$item,'pid'=>0]);
|
||
|
if($page){
|
||
|
$num=($page-1)*10;
|
||
|
$limit=10;
|
||
|
$re=$query->offset($num)->limit($limit)->orderBy('sort asc,id asc')->all();
|
||
|
}else{
|
||
|
$re=$query->orderBy('sort asc,id asc')->all();
|
||
|
}
|
||
|
// $re=$this->getTree($re,0);
|
||
|
|
||
|
$count=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_core_category}}')
|
||
|
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'storeId'=>$storeId,'item'=>$item,'pid'=>0])
|
||
|
->count();
|
||
|
foreach ($re as $k=>$v){
|
||
|
$re[$k]['children']=(new \yii\db\Query())
|
||
|
->select('id, describe,sort,name,pid,icon,display,startTime,endTime,weekStr,isRequire,timeType')
|
||
|
->from('{{%ybwm_core_category}}')
|
||
|
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'storeId'=>$storeId,'item'=>$item,'pid'=>$v['id']])
|
||
|
->orderBy('sort asc,id asc')
|
||
|
->all();
|
||
|
$re[$k]['weekStr']=json_decode($v['weekStr'],true);
|
||
|
$re[$k]['customName']=$re[$k]['customName']?:'';
|
||
|
if(!$re[$k]['isRequire']){
|
||
|
$re[$k]['isRequire']=2;
|
||
|
}
|
||
|
$key=0;
|
||
|
if($re[$k]['children']){
|
||
|
foreach ($re[$k]['children'] as $ko=>$vo){
|
||
|
$re[$k]['children'][$ko]['weekStr']=json_decode($vo['weekStr'],true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//判断平台设置店内是否开启
|
||
|
$isInStore=1;
|
||
|
$instore=Config::getSystemSet('sysTopImage', $uniacid)['instore'];
|
||
|
if($instore!=='1'){
|
||
|
//判断总设置店内是否开启
|
||
|
$instore=Config::getSystemSet('superPower', 0)['instore'];
|
||
|
if($instore!=='1'){
|
||
|
$isInStore=2;
|
||
|
}
|
||
|
}
|
||
|
echo json_encode(['code'=>1,'msg'=>'成功','data'=>$re,'count'=>intval($count),'isInStore'=>$isInStore]);die;
|
||
|
//return $this->result(1,'成功',$re,$count);
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|