文件
mashangyoujiu/Application/Super/Controller/AppController.class.php

684 行
20 KiB
PHP
可执行文件

<?php
namespace Super\Controller;
use Think\Controller;
//[1.8.20]
/*
* 商户app管理模型-控制模型
*/
class AppController extends Controller
{
/* @var array $allowAllAction 登录验证白名单 无需检测身份类型 */
protected $allowAllAction = array(
'index',
'cons',
);
public function _initialize()
{
if (!in_array(ACTION_NAME, $this->allowAllAction)) {
$SubBase = new SubBaseController();
$SubBase->_initialize();
} else {
$jurisdiction_user = session('jurisdiction_user');
if (empty($jurisdiction_user)) {
if (IS_AJAX) {
$re['status'] = 0;
$re['state'] = 0;
$re['code'] = 0;
$re['count'] = 0;
$re['data'] = array();
$re['msg'] = '您无权操作';
$this->ajaxReturn($re);
} else {
session(null);
header('Location:' . U('Retail/Login/index'));
exit;
}
}
}
}
public function index()
{
$unite = M('unit')->select();
foreach ($unite as $k => &$vals) {
$info = M('down_plug')->where(array('plug_type' => $vals['id'], 'state' => 0))->select();
foreach ($info as &$val) {
switch ($val['type']) {
case '1':
$val['type_name'] = 'Windows';
break;
case '2':
case '6':
$val['type_name'] = '小程序';
break;
case '4':
case '5':
$val['type_name'] = 'Android';
break;
default:
$val['type_name'] = '未知';
}
if (!empty($val['changetime'])) {
$val['time'] = date('Y-m-d H:i:s', $val['changetime']);
} else {
$val['time'] = date('Y-m-d H:i:s', $val['addtime']);
}
}
$vals['info'] = $info;
}
$this->assign('unite', $unite);
$this->display();
}
public function cons()
{
$where['did'] = I('post.id');
$where['state'] = 0;
$list = M('down_plug_img')->where($where)->getField('imgurl', true);
if (!empty($list)) {
$data['status'] = 1;
$data['list'] = $list;
} else {
$data['status'] = 0;
}
$this->ajaxReturn($data);
}
/**********************************************************************************************/
/**
* 软件上传,映射页面
*/
public function applist()
{
// 权限
$arr = array(
'uploadSoftware' => '/index.php/Super/App/uploadSoftware',// 添加APP
'addToClass' => '/index.php/Super/App/addToClass', // 添加插件
'deleteSoftware' => '/index.php/Super/App/deleteSoftware',// 删除APP
'uploadPreviewImage' => '/index.php/Super/App/uploadPreviewImage',// 删除APP
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/**
* 获取软件
*/
public function getSoftware()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 查询已上传的软件
$field = array(
'id', 'name', 'plug_type', 'type', 'logo_url', 'down_url', 'experience_url', 'changetime', 'information', 'version'
);
$map = array(
'state' => 0
);
$order = 'addtime desc';
$software_list = M('down_plug')->field($field)->where($map)->order($order)->select();
$software_list = !empty($software_list) ? $software_list : array();
// 处理数据
$unit = M('unit');
foreach ($software_list as $key => &$val) {
$val['changetime'] = date('Y-m-d H:i:s', $val['changetime']);
$plug_name = $unit->where(array('id' => $val['plug_type']))->getField('uitname');
$val['plug_name'] = !empty($plug_name) ? $plug_name : '分类异常';
switch ($val['type']) {
case 1:
$val['type_name'] = 'PC收银';
break;
case 2:
$val['type_name'] = '线上商城';
break;
case 4:
$val['type_name'] = '安卓收银';
break;
case 5:
$val['type_name'] = '安卓助手';
break;
case 6:
$val['type_name'] = '小程序助手';
break;
default:
$val['type_name'] = '异常的服务端';
}
}
$res = array(
'status' => 1,
'software_list' => $software_list
);
$this->ajaxReturn($res);
}
/**
* 获取分类
*/
public function getClass()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 查询分类
$order = 'addtime desc';
$class_list = M('unit')->order($order)->select();
$class_list = !empty($class_list) ? $class_list : array();
// 处理数据
foreach ($class_list as $key => &$val) {
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
}
$res = array(
'status' => 1,
'class_list' => $class_list
);
$this->ajaxReturn($res);
}
/**
* 获取上传方式
*/
public function getStorageType()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
$res = $this->publicStorageType($admin_user['id']);
$this->ajaxReturn($res);
}
/**
* 公共方法 获取上传方式
*/
public function publicStorageType($admin_id)
{
$storage_type = M('Retail_admin')->where(array('id' => $admin_id))->getField('storage_type');
if (in_array($storage_type, array(2, 3, 4))) {
$res = array(
'status' => 1,
'storage_type' => $storage_type
);
} else {
$res = array(
'status' => 0,
'msg' => '请先配置外部储存'
);
}
return $res;
}
/**
* 新增或编辑软件
*/
public function uploadSoftware()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$this->ajaxReturn(callBack(statusCode()['error'], '登录超时,请重新登录'));
}
// 接受数据
$data = I('post.');
// 判断参数
if (empty($data['name']) || empty($data['version']) || empty($data['information'])
|| empty($data['plug_type']) || !in_array($data['type'], array(1, 2, 4, 5, 6))
|| in_array($data['type'], array(1, 4, 5)) && empty($data['down_url'])
|| in_array($data['type'], array(2, 6)) && empty($data['experience_url'])) {
$this->ajaxReturn(callBack(statusCode()['error'], '请完善表单后再提交'));
}
$item = array(
'name' => $data['name'],
'changetime' => time(),
'information' => $data['information'],
'version' => $data['version'],
'down_url' => $data['down_url'],
'logo_url' => $data['logo_url'],
'experience_url' => $data['experience_url'],
);
if (empty($data['id'])) {
// 添加
$item['plug_type'] = $data['plug_type'];
$item['type'] = $data['type'];
$item['state'] = 0;
$item['addtime'] = time();
$res = M('down_plug')->add($item);
} else {
// 更新
$res = M('down_plug')->where(['id' => $data['id']])->save($item);
}
if ($res) {
$this->ajaxReturn(callBack(statusCode()['success'], '保存成功'));
} else {
$this->ajaxReturn(callBack(statusCode()['error'], '保存失败'));
}
}
/**
* 公共方法 上传外部储存
*/
private function publicUpload($upload, $storage_type, $ext)
{
$local_url = 'Admin/apk';
$config = M('upload_config')->where(array('id' => 1))->find();
switch ($storage_type) {
case '2':
//七牛云
$res = toUploadQiNiuYun($upload['tmp_name'], $ext['extension'], $config, $local_url);
break;
case '3':
//腾讯云
$res = uploadFilesToTencent($upload['tmp_name'], $ext['extension'], $config, $local_url);
break;
case '4':
//阿里云
$res = uploadFilesToOSS($upload['tmp_name'], $ext['extension'], $config, $local_url);
break;
}
return $res;
}
/**
* 删除软件
*/
public function deleteSoftware()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 接受参数
$id = I('post.id');
// 判断
if (empty($id)) {
$res = array(
'status' => 0,
'msg' => '缺少必要的标识参数'
);
$this->ajaxReturn($res);
}
// 删除
$map = array(
'id' => $id,
'state' => 0
);
$up = array(
'state' => 1
);
$del = M('down_plug')->where($map)->save($up);
if (empty($del)) {
$res = array(
'status' => 0,
'msg' => '删除失败'
);
} else {
$res = array(
'status' => 1,
'msg' => '删除成功'
);
}
$this->ajaxReturn($res);
}
/**
* 获取预览图
*/
public function getPreviewImage()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 接受参数
$id = I('post.id');
// 判断
if (empty($id)) {
$res = array(
'status' => 0,
'msg' => '缺少必要的标识参数'
);
$this->ajaxReturn($res);
}
// 查询
$map = array(
'did' => $id,
'state' => 0
);
$field = array(
'id', 'did', 'imgurl',
);
$order = 'addtime desc';
$preview_image = M('down_plug_img')->field($field)->where($map)->order($order)->select();
if (empty($preview_image)) {
$res = array(
'status' => 0,
'msg' => '暂无预览图'
);
} else {
$res = array(
'status' => 1,
'preview_image' => $preview_image
);
}
$this->ajaxReturn($res);
}
/**
* 上传预览图
*/
public function uploadPreviewImage()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 获取上传方式
$result = $this->publicStorageType($admin_user['id']);
// 接受参数
if (I('post.id')) {
$id = I('post.id');
} else {
$id = I('get.id');
}
// 判断
if (empty($id)) {
$res = array(
'status' => 0,
'msg' => '缺少必要的标识参数'
);
$this->ajaxReturn($res);
}
$preview_image = $_FILES['preview_image'];
if ($preview_image['error'] != 0) {
$res = array(
'status' => 0,
'msg' => '上传失败'
);
$this->ajaxReturn($res);
}
$ext = pathinfo($preview_image['name']);
if (!in_array($ext['extension'], array('png', 'jpg', 'jpeg'))) {
$res = array(
'status' => 0,
'msg' => '请选择正确的图片类型'
);
$this->ajaxReturn($res);
}
if ($preview_image['size'] > 1024 * 1024) {
$res = array(
'status' => 0,
'msg' => '图片大小超过1M限制'
);
$this->ajaxReturn($res);
}
$preview_res = $this->publicUpload($preview_image, $result['storage_type'], $ext);
if (empty($preview_res)) {
$res = array(
'status' => 0,
'msg' => '图片上传失败'
);
$this->ajaxReturn($res);
}
// 添加数据
$cr = array(
'did' => $id,
'imgurl' => $preview_res['path'],
'state' => 0,
'addtime' => time()
);
$add = M('down_plug_img')->add($cr);
if (empty($add)) {
$res = array(
'status' => 0,
'msg' => '数据库异常'
);
} else {
$res = array(
'status' => 1,
'msg' => '上传成功'
);
}
$this->ajaxReturn($res);
}
/**
* 删除预览图
* @param int $id
* @return array
*/
public function deletePreviewImage()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 接收数据
$id = I('post.id');
if (empty($id)) {
$res = array(
'status' => 0,
'msg' => '系统异常,请刷新重试'
);
$this->ajaxReturn($res);
}
// 删除
$map = array(
'id' => $id,
'state' => 0
);
$up = array(
'state' => 1
);
$save = M('down_plug_img')->where($map)->save($up);
if (empty($save)) {
$res = array(
'status' => 0,
'msg' => '删除失败,请刷新后重试'
);
} else {
$res = array(
'status' => 1,
'msg' => '删除成功'
);
}
$this->ajaxReturn($res);
}
/**
* 添加编辑分类
* @param array $class_info
* @param string $class_name
* @return array
*/
public function addToClass()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 接受参数
$class_info = I('post.class_info');
$class_name = I('post.class_name');
// 判断参数
if (empty($class_name) || $class_name == '') {
$res = array(
'status' => 0,
'msg' => '请输入分类名称'
);
$this->ajaxReturn($res);
}
// 判断添加编辑
if (empty($class_info)) { // 添加
$add = array(
'uitname' => $class_name,
'addtime' => time()
);
$add_res = M('unit')->add($add);
if (empty($add_res)) {
$res = array(
'status' => 0,
'msg' => '添加失败'
);
} else {
$res = array(
'status' => 1,
'msg' => '添加成功'
);
}
} else { // 编辑
$map = array(
'id' => $class_info['id']
);
// 查询
$uitname = M('unit')->where($map)->getField('uitname');
// 判断是否有其他角色修改
if ($uitname != $class_info['uitname']) {
$res = array(
'status' => 0,
'msg' => '该分类已被其他角色编辑!如需编辑,请刷新后重新编辑'
);
$this->ajaxReturn($res);
}
// 判断修改
if ($uitname == $class_name) {
$res = array(
'status' => 0,
'msg' => '请先编辑再提交'
);
$this->ajaxReturn($res);
}
// 编辑
$up = array(
'uitname' => $class_name
);
$up_res = M('unit')->where($map)->save($up);
if (empty($up_res)) {
$res = array(
'status' => 0,
'msg' => '编辑失败'
);
} else {
$res = array(
'status' => 1,
'msg' => '编辑成功'
);
}
}
$this->ajaxReturn($res);
}
/**
* 删除分类
* @param int $id
* @return array
*/
public function deleteClass()
{
// 判断登录
$admin_user = I('session.admin_userinfo');
if (empty($admin_user)) {
$res = array(
'status' => 0,
'msg' => '登录超时,请重新登录'
);
$this->ajaxReturn($res);
}
// 接收数据
$id = I('post.id');
if (empty($id)) {
$res = array(
'status' => 0,
'msg' => '系统异常,请刷新重试'
);
$this->ajaxReturn($res);
}
// 查询判断分类
$software_field = array('id');
$software_map = array(
'state' => 0,
'plug_type' => $id
);
$find_software = M('down_plug')->field($software_field)->where($software_map)->find();
// 判断该分类有无上传软件
if (!empty($find_software)) {
$res = array(
'status' => 0,
'msg' => '请先移除该分类下的软件在执行此操作'
);
$this->ajaxReturn($res);
}
// 删除
$del_map = array(
'id' => $id
);
$del_res = M('unit')->where($del_map)->delete();
if (empty($del_res)) {
$res = array(
'status' => 0,
'msg' => '删除失败,请刷新后重试'
);
} else {
$res = array(
'status' => 1,
'msg' => '删除成功'
);
}
$this->ajaxReturn($res);
}
}