145 lines
5.4 KiB
PHP
145 lines
5.4 KiB
PHP
<?php
|
|
namespace app\controllers\admin;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use app\models\common\File;
|
|
use app\models\common\Config;
|
|
class FileController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
//图片上传
|
|
public function actionUpload() {
|
|
$config=Config::getSystemSet('storage',0);
|
|
if($config['type']==1){
|
|
$fname=File::qiniuUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}elseif($config['type']==2){
|
|
$fname=File::aliUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}elseif($config['type']==3){
|
|
$fname=File::txyUpload('file',$this->wqData['module'],$this->wqData['uniacid'],$config);
|
|
}else{
|
|
$fname=File::channelUploadImage('file','',$this->wqData['module'],$this->wqData['uniacid']);
|
|
}
|
|
$result=axios_request();
|
|
$data['categoryId'] = $result['category'] ?: 0;
|
|
$data['url'] = $fname;
|
|
$data['name'] = $_FILES['file']['name'];
|
|
$data['storeId'] = $result['storeId'] ?: 0;
|
|
$data['createdAt'] = time();
|
|
$data['deleteAt'] = 0;
|
|
$data['uniacid'] = $this->wqData['uniacid'];
|
|
$res=Yii::$app->db->createCommand()->insert('{{%ybwm_core_file}}', $data)->execute();
|
|
if ($res) {
|
|
return $this->result(1, '成功!',$res);
|
|
} else {
|
|
return $this->result(2, '失败!');
|
|
}
|
|
}
|
|
|
|
//获取拖拽图片分类
|
|
public function actionGetCategory() {
|
|
$storeId=Yii::$app->request->get('storeId');
|
|
$storeId = $storeId ?: 0;
|
|
$res=(new \yii\db\Query())
|
|
->select(['id', 'name','icon'])
|
|
->from('{{%ybwm_core_category}}')
|
|
->where('uniacid=:uniacid AND storeId=:storeId AND item=4 AND deleteAt=0',[':storeId'=>$storeId,':uniacid'=>$this->wqData['uniacid']])->all();
|
|
return $this->result(1, '操作成功!', $res);
|
|
}
|
|
|
|
//移动图片
|
|
public function actionMoveFile() {
|
|
$result=axios_request();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_file}}', ['categoryId'=>$result['typeId']], 'id=:id', ['id' =>$result['id']])->execute();
|
|
if($res){
|
|
return $this->result(1, '成功!');
|
|
}else{
|
|
return $this->result(2, '失败!');
|
|
}
|
|
}
|
|
|
|
//获取图片
|
|
public function actionGetPicture() {
|
|
$typeId=Yii::$app->request->get('category');
|
|
$keyWords=Yii::$app->request->get('keywords');
|
|
$page=Yii::$app->request->get('page')?:1;
|
|
$size=Yii::$app->request->get('size')?:30;
|
|
$storeId=Yii::$app->request->get('storeId')?:0;
|
|
$table=(new \yii\db\Query())
|
|
->select(['id', 'url','name'])
|
|
->from('{{%ybwm_core_file}}')
|
|
->where('uniacid=:uniacid AND deleteAt=0',[':uniacid'=>$this->wqData['uniacid']]);
|
|
if($storeId){
|
|
$table->andwhere('storeId=:storeId',[':storeId'=>$storeId]);
|
|
}
|
|
if($typeId){
|
|
$table->andwhere('categoryId=:categoryId',['categoryId'=>$typeId]);
|
|
}
|
|
if($keyWords){
|
|
$table->andwhere(['like', 'name', $keyWords]);
|
|
}
|
|
$count=$table->count();
|
|
$res=$table->offset(($page - 1) * $size)->limit($size)->orderby('id desc')->all();
|
|
return $this->result(1,'成功',$res,$count);
|
|
}
|
|
|
|
//删除图片分类
|
|
public function actionDelPictureCategory() {
|
|
$result=axios_request();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', ['deleteAt'=>time()], 'id=:id', ['id' =>$result['id']])->execute();
|
|
if ($res) {
|
|
return $this->result(1, '成功!');
|
|
} else {
|
|
return $this->result(2, '失败!');
|
|
}
|
|
}
|
|
//删除图片
|
|
public function actionDelPicture() {
|
|
$result=axios_request();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_file}}', ['deleteAt'=>time()], 'id=:id', ['id' =>$result['id']])->execute();
|
|
if ($res) {
|
|
return $this->result(1, '成功!');
|
|
} else {
|
|
return $this->result(2, '失败!');
|
|
}
|
|
}
|
|
//添加分组
|
|
public function actionSaveCategory() {
|
|
$post=axios_request();
|
|
$post['storeId']=$post['storeId']?:0;
|
|
if(!$post['name']){
|
|
return $this->result(2,'分类名称不能为空!');
|
|
}
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_category}}')
|
|
->where('uniacid=:uniacid AND storeId=:storeId AND item=4 AND deleteAt=0 AND name=:name',[':name'=>$post['name'],':storeId'=>$post['storeId'],':uniacid'=>$this->wqData['uniacid']])->one();
|
|
|
|
if($info){
|
|
return $this->result(2,'该名称已存在!');
|
|
}
|
|
$data['name']=$post['name'];
|
|
$data['storeId']=$post['storeId'];
|
|
$data['item']=4;
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['changeAt']=time();
|
|
if ($post['id']) {
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
} else {
|
|
$data['createdAt']=time();
|
|
$res=Yii::$app->db->createCommand()->insert('{{%ybwm_core_category}}', $data)->execute();
|
|
}
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |