文件
mashangyoujiu/Application/Admin/Controller/UploadController.class.php

224 行
8.3 KiB
PHP
可执行文件

<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Model\RetailStoreModel;
use Common\Model\UploadImageClassModel;
//[1.5.84]
class UploadController extends Controller
{
public function _initialize()
{
$user = session('jurisdiction_user');
if (empty($user)) {
$this->ajaxReturn(array('status' => 0, 'msg' => '请登录后再操作'));
}
}
public function uploadFilesForUEditor()
{
if ($_FILES) {
$user = session('jurisdiction_user');
$time = time();
$item = array(
'localUrl' => 'Uploads/UEditor',
'add_time' => $time,
'source_type' => 2,
'user_type' => $user['login_type'],
'user_id' => $user['id'],
);
$uploads = uploadFiles($item);
$file = array();
foreach ($uploads as $val) {
$file = $val;
}
if ($uploads) {
$res = array(
'original' => $file['name'],
'size' => $file['size'],
'title' => $file['saveName'],
'type' => '.' . $file['ext'],
'url' => $file['savePath'],
'state' => 'SUCCESS'
);
} else {
$res['state'] = 'SUCCESS';
$res['errorHandler'] = '上传失败';
}
} else if (I('get.action') == 'config') {
$res = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("./Public/UEditor/php/config.json")), true);
} else {
$res['state'] = 'SUCCESS';
$res['errorHandler'] = '上传失败';
}
$this->ajaxReturn($res);
}
/**
* 获取图片可选择的下拉框数据
*/
public function getSelectClass()
{
$user = session('jurisdiction_user');
$store_id = session('storeid');
$from_class = array();
$merchant_class = array();
$store_class = array();
$UICModel = new UploadImageClassModel();
switch ($user['login_type']) {
case '1':
//合伙人、或者合伙人下面的角色
$from_class = $UICModel->getSelect(array('type' => 2, 'p_id' => 1));
array_unshift($from_class, array('id' => 0, 'name' => '所有合伙人', 'type' => 2, 'p_id' => 1));
break;
case '2':
//代理商
$from_class = $UICModel->getSelect(array('type' => 2, 'p_id' => 2));
array_unshift($from_class, array('id' => 0, 'name' => '所有', 'type' => 2, 'p_id' => 1));
break;
case '3':
//商户+门店
$StoreModel = new RetailStoreModel();
$from_class = $StoreModel->getSelect(array('merchantid' => $user['merchant_id'], 'state' => 0), 'id,storetag as name');
array_unshift($from_class, array('id' => -1, 'name' => '商户'));
array_unshift($from_class, array('id' => 0, 'name' => '所有'));
$merchantClass = $UICModel->getSelect(array('p_id' => 3));//商户
array_unshift($merchantClass, array('id' => 0, 'name' => '所有'));
$storeClass = $UICModel->getSelect(array('p_id' => 4));//门店
array_unshift($storeClass, array('id' => 0, 'name' => '所有'));
break;
case '4':
//门店
$auth = M('retail_store_jurisdiction')->where(array('storeid' => $store_id))->find();
$from_class = $UICModel->getSelect(array('type' => 2, 'p_id' => 4));
//是否有查看商户图片权限
if ($auth['merchant_img_use'] == 1) {
array_unshift($from_class, array('id' => -1, 'name' => '商户图片', 'type' => 4, 'p_id' => 4));
}
array_unshift($from_class, array('id' => 0, 'name' => '所有', 'type' => 4, 'p_id' => 4));
break;
}
$res['from_class'] = $from_class;
$res['merchant_class'] = $merchant_class;
$res['store_class'] = $store_class;
$res['status'] = 1;
$res['msg'] = '获取成功';
$this->ajaxReturn($res);
}
/**
* 获取图库图片
*/
public function getGalleryImages()
{
$user = session('jurisdiction_user');
$store_id = session('storeid');
$page = I('post.page');
$limit = I('post.limit');
$selectTypeC = I('post.selectTypeC');
$selectTypeD = I('post.selectTypeD');
$key = I('post.key');
$fileType = I('post.fileType');
if (!empty($key)) {
$where['name|original_name'] = array('like', "%{$key}%");
}
if (!empty($fileType)) {
$where['type'] = $fileType;
}
$ImageGalleryModel = D('ImageGallery');
switch ($user['login_type']) {
case '1':
//合伙人
if (!empty($selectTypeC)) {
$where['from_type_id'] = $selectTypeC;
}
break;
case '2':
//代理商
$where['user_type'] = 3;
if (!empty($selectTypeC)) {
$where['from_type_id'] = $selectTypeC;
} else {
$ids = $ImageGalleryModel->getFindField(array('type' => 2, 'p_id' => 2), 'id', true);
if (!empty($ids)) {
$where['from_type_id'] = array('in', $ids);
}
}
$where['agent_id'] = $user['agent_id'];
break;
case '3':
//商户
if ($selectTypeC == -1) {
$where['merchant_id'] = $user['merchant_id'];
$where['user_type'] = 3;
if ($selectTypeD != '' && $selectTypeD != 0) {
$where['from_type_id'] = $selectTypeD;
} else {
$ids = $ImageGalleryModel->getFindField(array('type' => 3, 'p_id' => 3), 'id', true);
if (!empty($ids)) {
$where['from_type_id'] = array('in', $ids);
}
}
} else if ($selectTypeC == 0) {
//所有
$where['merchant_id'] = $user['merchant_id'];
} else {
//门店
$where['store_id'] = $selectTypeC;
$where['user_type'] = 4;
if ($selectTypeD != '' && $selectTypeD != 0) {
$where['from_type_id'] = $selectTypeD;
}
}
break;
case '4':
//门店
$where['user_type'] = 4;
if ($selectTypeC == -1) {
//商户图片
$where['merchant_id'] = $user['merchant_id'];
$where['user_type'] = 3;
} else if ($selectTypeC == 0) {
//所有图片
$where['merchant_id'] = $user['merchant_id'];
} else {
//门店图片
$where['store_id'] = $store_id;
$where['from_type_id'] = $selectTypeC;
}
break;
case '5':
//导购员
$where['user_type'] = 5;
$where['guide_id'] = $user['system_user_id'];
break;
}
$images = D('ImageGallery')->getSelect($where, 'id,path,name,original_name,size,type', 'id desc', $page, $limit);
if ($images) {
foreach ($images as &$val) {
if ($val['add_time']) {
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
}
if ($val['size']) {
$val['size'] = getFileSize($val['size']);
}
$val['checked'] = false;
}
$res['list'] = $images;
$res['status'] = 1;
$res['msg'] = '获取成功';
} else {
$res['list'] = array();
$res['status'] = 1;
$res['msg'] = '暂无数据';
}
$this->ajaxReturn($res);
}
}