146 lines
5.7 KiB
PHP
146 lines
5.7 KiB
PHP
<?php
|
|
namespace app\controllers\merchant;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Category;
|
|
use app\models\common\Store;
|
|
class CategoryController extends CommonController{
|
|
public function actionGetCategoryList(){
|
|
$type=Yii::$app->request->get('type')?:1;
|
|
$id=Yii::$app->request->get('id')?:0;
|
|
Category::getCategoryList($this->wqData['uniacid'],$this->wqData['storeId'],$type,0,$id);
|
|
}
|
|
|
|
public function actionCategoryBasic(){
|
|
$request = Yii::$app->request;
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$this->wqData['storeId'];
|
|
if(Yii::$app->request->get('type')==1){
|
|
$item=6;
|
|
}else{
|
|
$item=9;
|
|
}
|
|
if ($request->isGet){
|
|
$page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$storeInfo=(new \yii\db\Query())->from('{{%ybwm_store}}')
|
|
->where(['uniacid'=>$uniacid,'isMain'=>1])
|
|
->one();
|
|
$storeRes=Store::getStoreInfo($uniacid,$storeId);
|
|
|
|
if($storeRes['isMain']==2&&$storeRes['goodsModel']<3){
|
|
$storeId=$storeInfo['id'];
|
|
}
|
|
$res=(new \yii\db\Query())
|
|
->select(['id','name','icon','pid','sort','describe','isRequire','timeType','weekStr','startTime','endTime'])
|
|
->from('{{%ybwm_core_category}}')
|
|
->where('uniacid=:uniacid and storeId=:storeId and item='.$item.' and display=1 and deleteAt=0',[':uniacid'=>$uniacid,':storeId'=>$storeId])
|
|
//->offset($num)
|
|
//->limit($limit)
|
|
->orderBy('sort asc,id desc')
|
|
->all();
|
|
|
|
$re=$this->getTree($res,0);
|
|
//dd($re);die;
|
|
$count=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_category}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$uniacid,'item'=>$item])
|
|
->count();
|
|
echo json_encode(
|
|
['code'=>1,'msg'=>'成功','data'=>$re,'count'=>$count]
|
|
);die;
|
|
}
|
|
|
|
}
|
|
|
|
//添加修改商品分类
|
|
public function actionCategorySave(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$uniacid=$this->wqData['uniacid'];
|
|
$storeId=$this->wqData['storeId'];
|
|
$result=axios_request();
|
|
$id=$result['id'];
|
|
if(!trim($result['name'])){
|
|
echo json_encode(['code'=>2,'msg'=>'请填写商品分类名称']);die;
|
|
}
|
|
if(!trim($result['icon'])){
|
|
echo json_encode(['code'=>2,'msg'=>'请上传商品分类图片']);die;
|
|
}
|
|
if($result['type']==1){
|
|
$item=6;
|
|
}else{
|
|
$item=9;
|
|
}
|
|
$array=array(
|
|
'sort'=>trim($result['sort']),
|
|
'name'=>trim($result['name']),//商品分类名称
|
|
'isRequire'=>$result['isRequire'],
|
|
'timeType'=>$result['timeType'],
|
|
'weekStr'=>json_encode($result['weekStr'],JSON_UNESCAPED_UNICODE),
|
|
'startTime'=>$result['startTime'],
|
|
'endTime'=>$result['endTime'],
|
|
'display'=>$result['display']?$result['display']:1,
|
|
'pid'=>$result['pid']?$result['pid']:0,
|
|
'describe'=>trim($result['describe']),
|
|
'uniacid'=>$uniacid,
|
|
'storeId'=>$storeId,
|
|
'icon'=>$result['icon'],
|
|
'customName'=>$result['customName'],
|
|
'item'=>$item
|
|
);
|
|
// if($result['icon']){
|
|
// if(substr($result['icon'],0,4)!=='/web'){
|
|
// $array['icon']=uploadImage($result['icon'],$result['icon']);//图片
|
|
// }
|
|
// }
|
|
if($id){
|
|
$array=filter_array($array);
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_category}}', $array,'id=:id', ['id' =>$result['id']])->execute();
|
|
echo json_encode(['code'=>1,'msg'=>'商品分类已修改']);die;
|
|
}else{
|
|
$array['createdAt']=time();
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_category}}', $array)->execute();
|
|
if($re){
|
|
echo json_encode(['code'=>1,'msg'=>'商品分类添加成功']);die;
|
|
}else{
|
|
echo json_encode(['code'=>2,'msg'=>'网络异常,请稍后再试']);die;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除商品分类
|
|
public function actionCategoryDel(){
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
$id=axios_request()['id'];
|
|
if(is_array($id)){
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_category}}', ['deleteAt'=>time(),'display'=>2], ['in','id',$id])->execute();
|
|
}else{
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_category}}', ['deleteAt'=>time(),'display'=>2], ['id'=>$id])->execute();
|
|
}
|
|
echo json_encode(['code'=>1,'msg'=>'商品分类已删除']);die;
|
|
}
|
|
|
|
}
|
|
public function actionChangeSwitch(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_category}}', ['display' =>$result['display']], 'id=:id', ['id' => $result['id']])->execute();
|
|
if($re!==false){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|