625 lines
22 KiB
PHP
625 lines
22 KiB
PHP
<?php
|
|
/**
|
|
* 易优CMS
|
|
* ============================================================================
|
|
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
|
|
* 网站地址: http://www.eyoucms.com
|
|
* ----------------------------------------------------------------------------
|
|
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
|
|
* ============================================================================
|
|
* Author: 陈风任 <491085389@qq.com>
|
|
* Date: 2019-2-12
|
|
*/
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Page;
|
|
use think\Db;
|
|
use think\Config;
|
|
use app\admin\logic\MemberLogic;
|
|
|
|
class Project extends Base {
|
|
|
|
public $userConfig = [];
|
|
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->language_access(); // 多语言功能操作权限
|
|
/*会员中心数据表*/
|
|
$this->project_db = Db::name('project'); //
|
|
$this->service_db = Db::name('service'); //
|
|
$this->projectQueryPasswordDb = Db::name('query_password'); // 查询密码表
|
|
|
|
// 是否开启支付功能设置
|
|
$this->userConfig = getUsersConfigData('all');
|
|
$this->assign('userConfig',$this->userConfig);
|
|
|
|
// 模型是否开启
|
|
$channeltype_row = \think\Cache::get('extra_global_channeltype');
|
|
$this->assign('channeltype_row',$channeltype_row);
|
|
}
|
|
|
|
|
|
// 会员列表
|
|
public function users_index()
|
|
{
|
|
$list = array();
|
|
|
|
$param = input('param.');
|
|
$condition = array();
|
|
// 应用搜索条件
|
|
foreach (['keywords','origin_type'] as $key) {
|
|
if (isset($param[$key]) && $param[$key] !== '') {
|
|
if ($key == 'keywords') {
|
|
$condition['a.enterprise|a.name'] = array('LIKE', "%{$param[$key]}%");
|
|
} else {
|
|
$condition['a.'.$key] = array('eq', $param[$key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// $condition['a.is_del'] = 0;
|
|
// 多语言
|
|
//$condition['a.lang'] = array('eq', $this->admin_lang);
|
|
|
|
/**
|
|
* 数据查询
|
|
*/
|
|
$count = $this->project_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
|
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
|
$list = $this->project_db->field('a.*')
|
|
->alias('a')
|
|
// ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
|
|
->where($condition)
|
|
->order('a.id desc')
|
|
->limit($Page->firstRow.','.$Page->listRows)
|
|
->select();
|
|
|
|
$show = $Page->show();// 分页显示输出
|
|
$this->assign('page',$show);// 赋值分页输出
|
|
$this->assign('list',$list);// 赋值数据集
|
|
$this->assign('pager',$Page);// 赋值分页集
|
|
|
|
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
//新增项目
|
|
public function add()
|
|
{
|
|
//防止php超时
|
|
function_exists('set_time_limit') && set_time_limit(0);
|
|
$id = input('id',0);
|
|
if($id){
|
|
$item = $this->project_db->where([
|
|
'id' => $id
|
|
])->find();
|
|
$this->assign('item',$item);
|
|
}
|
|
$this->assign('id',$id);
|
|
if (IS_POST) {
|
|
$post = input('post.');
|
|
|
|
// 添加表信息
|
|
$data = array(
|
|
'name' => $post['name'],
|
|
'enterprise' => $post['enterprise'],
|
|
'filing' => $post['filing'],
|
|
'sid' =>$post['sid'],
|
|
'limitationdate' => $post['limitationdate'],
|
|
);
|
|
if($id >0){
|
|
$this->project_db->where(array('id'=>$id))->update($data);
|
|
$insertID = $id;
|
|
}else{
|
|
$data['createtime'] = getTime();
|
|
$insertID = M('project')->insertGetId($data);
|
|
}
|
|
$data['id'] = $insertID;
|
|
$datas['qrcode'] = $this->book($data);
|
|
$this->project_db->where(array('id'=>$insertID))->update($datas);
|
|
|
|
if (!empty($insertID)) {
|
|
// adminLog('新增项目:'.$post['name']);
|
|
$this->success("操作成功", url('Project/users_index'));
|
|
} else {
|
|
$this->error("操作失败", url('Project/users_index'));
|
|
}
|
|
}
|
|
|
|
return $this->fetch();
|
|
}
|
|
//新增服务商
|
|
public function edit()
|
|
{
|
|
//防止php超时
|
|
function_exists('set_time_limit') && set_time_limit(0);
|
|
$id = input('id',0);
|
|
if($id){
|
|
$item = $this->service_db->where([
|
|
'id' => $id
|
|
])->find();
|
|
$this->assign('item',$item);
|
|
}
|
|
$this->assign('id',$id);
|
|
if (IS_POST) {
|
|
$post = input('post.');
|
|
|
|
// 添加表信息
|
|
$data = array(
|
|
'name' => $post['name'],
|
|
'centre' => $post['centre']
|
|
);
|
|
|
|
if($id >0){
|
|
$this->service_db->where(array('id'=>$id))->update($data);
|
|
$insertID = $id;
|
|
}else{
|
|
$data['createtime'] = getTime();
|
|
$insertID = M('service')->insertGetId($data);
|
|
}
|
|
$data['id'] = $insertID;
|
|
$datas['qrcode'] = $this->service($data);
|
|
$this->service_db->where(array('id'=>$insertID))->update($datas);
|
|
if (!empty($insertID)) {
|
|
// adminLog('新增项目:'.$post['name']);
|
|
$this->success("操作成功", url('Project/users_index'));
|
|
} else {
|
|
$this->error("操作失败", url('Project/users_index'));
|
|
}
|
|
}
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
|
|
// 项目删除
|
|
public function users_del()
|
|
{
|
|
$users_id = input('del_id/a');
|
|
$users_id = eyIntval($users_id);
|
|
if (IS_AJAX_POST && !empty($users_id)) {
|
|
// 删除统一条件
|
|
$Where = [
|
|
'id' => ['IN', $users_id],
|
|
];
|
|
|
|
$result = $this->project_db->field('name')->where($Where)->select();
|
|
$username_list = get_arr_column($result, 'name');
|
|
|
|
$return = $this->project_db->where($Where)->delete();
|
|
if (false !== $return) {
|
|
$this->success('删除成功');
|
|
}else{
|
|
$this->error('删除失败');
|
|
}
|
|
}
|
|
$this->error('参数有误');
|
|
}
|
|
|
|
// 级别列表
|
|
public function level_index()
|
|
{
|
|
|
|
$list = array();
|
|
|
|
$param = input('param.');
|
|
$condition = array();
|
|
// 应用搜索条件
|
|
foreach (['keywords','origin_type'] as $key) {
|
|
if (isset($param[$key]) && $param[$key] !== '') {
|
|
if ($key == 'keywords') {
|
|
$condition['a.name|a.centre'] = array('LIKE', "%{$param[$key]}%");
|
|
} else {
|
|
$condition['a.'.$key] = array('eq', $param[$key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// $condition['a.is_del'] = 0;
|
|
// 多语言
|
|
//$condition['a.lang'] = array('eq', $this->admin_lang);
|
|
|
|
/**
|
|
* 数据查询
|
|
*/
|
|
$count = $this->service_db->alias('a')->where($condition)->count();// 查询满足要求的总记录数
|
|
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
|
$list = $this->service_db->field('a.*')
|
|
->alias('a')
|
|
// ->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
|
|
->where($condition)
|
|
->order('a.id desc')
|
|
->limit($Page->firstRow.','.$Page->listRows)
|
|
->select();
|
|
|
|
$show = $Page->show();// 分页显示输出
|
|
$this->assign('page',$show);// 赋值分页输出
|
|
$this->assign('list',$list);// 赋值数据集
|
|
$this->assign('pager',$Page);// 赋值分页集
|
|
|
|
|
|
|
|
return $this->fetch();
|
|
}
|
|
|
|
// 服务商删除
|
|
public function del()
|
|
{
|
|
$users_id = input('del_id/a');
|
|
$users_id = eyIntval($users_id);
|
|
if (IS_AJAX_POST && !empty($users_id)) {
|
|
// 删除统一条件
|
|
$Where = [
|
|
'id' => ['IN', $users_id],
|
|
];
|
|
|
|
$result = $this->service_db->field('name')->where($Where)->select();
|
|
$username_list = get_arr_column($result, 'name');
|
|
|
|
$return = $this->service_db->where($Where)->delete();
|
|
if (false !== $return) {
|
|
$this->success('删除成功');
|
|
}else{
|
|
$this->error('删除失败');
|
|
}
|
|
}
|
|
$this->error('参数有误');
|
|
}
|
|
|
|
/**
|
|
* 项目
|
|
* @return string
|
|
*/
|
|
public function book($data)
|
|
{
|
|
// $data = array(
|
|
// 'title'=>'防爆电器',
|
|
// 'enterprise'=>'新黎明科技股份有限公司',
|
|
// 'filing'=>'G-20230525',
|
|
// 'sid'=>'91320500582331116Y',
|
|
// 'limitationdate'=>'2023-05-25',
|
|
// );
|
|
$path = "uploads/imgs/";
|
|
// file_put_contents(__DIR__ . '/debug.txt', var_export($data,true));
|
|
$file = $data['id'].'.jpg';
|
|
$font = "uploads/msyh.ttf";
|
|
$target = imagecreatetruecolor(1657, 1105);
|
|
$bc = imagecolorallocate($target, 0, 0, 0);
|
|
$cc = imagecolorallocate($target, 255, 51, 0);
|
|
$wc = imagecolorallocate($target, 255, 255, 255);
|
|
$yc = imagecolorallocate($target, 255, 255, 0);
|
|
//背景
|
|
$bg = imagecreatefromjpeg("uploads/imgs/b.jpg");
|
|
imagecopy($target, $bg, 0, 0, 0, 0, 1657, 1105);
|
|
imagedestroy($bg);
|
|
|
|
//名称
|
|
imagettftext($target, 23, 0, 600, 589, $bc, $font, $data['name']);
|
|
//个人/企业
|
|
imagettftext($target, 23, 0, 600, 652, $bc, $font, $data['enterprise']);
|
|
//备案号
|
|
imagettftext($target, 23, 0, 600, 718, $bc, $font, $data['filing']);
|
|
//证件号码
|
|
imagettftext($target, 23, 0, 600, 786, $bc, $font, $data['sid']);
|
|
//有效期
|
|
imagettftext($target, 23, 0, 600, 850, $bc, $font, $data['limitationdate']);
|
|
imagejpeg($target, $path . $file);
|
|
imagedestroy($target);
|
|
// echo '<img src="../../uploads/imgs/'.$data['id'].'.jpg">';
|
|
return '/uploads/imgs/'.$data['id'].'.jpg';
|
|
}
|
|
|
|
/**
|
|
* 服务商
|
|
* @return string
|
|
*/
|
|
public function service($data)
|
|
{
|
|
|
|
// $id = 1;
|
|
/* $data = array(
|
|
'name'=>'上 海 聚 上 网 络 科 技 有 限 公 司',
|
|
'centre'=>'华 东 服 务 中 心',
|
|
);*/
|
|
$path = "uploads/imgs/";
|
|
$me =array();
|
|
$file = $data['id'].'.jpg';
|
|
$font = "uploads/msyh.ttf";
|
|
$target = imagecreatetruecolor(800, 1111);
|
|
$bc = imagecolorallocate($target, 0, 0, 0);
|
|
$cc = imagecolorallocate($target, 255, 51, 0);
|
|
// $wc = imagecolorallocate($target, 255, 255, 255);
|
|
// $yc = imagecolorallocate($target, 255, 255, 0);
|
|
//背景
|
|
$bg = imagecreatefromjpeg("uploads/imgs/a.jpg");
|
|
|
|
imagecopy($target, $bg, 0, 0, 0, 0, 800, 1111);
|
|
imagedestroy($bg);
|
|
|
|
imagettftext($target, 23, 0, 160, 625, $bc, $font, $data['name']);
|
|
imagettftext($target, 21, 0, 300, 690, $cc, $font, $data['centre']);
|
|
imagejpeg($target, $path . $file);
|
|
imagedestroy($target);
|
|
// echo '<img src="../../uploads/imgs/'.$id.'.jpg">';
|
|
return '/uploads/imgs/'.$data['id'].'.jpg';
|
|
}
|
|
|
|
|
|
/**
|
|
* 导入Excel文件
|
|
* @return json
|
|
*/
|
|
public function import_excel()
|
|
{
|
|
if (IS_POST) {
|
|
$file = request()->file('excel_file');
|
|
if (!$file) {
|
|
$this->error('请选择要导入的文件');
|
|
}
|
|
|
|
// 验证文件类型
|
|
$ext = strtolower(pathinfo($file->getInfo('name'), PATHINFO_EXTENSION));
|
|
if (!in_array($ext, ['xls', 'xlsx'])) {
|
|
$this->error('只支持Excel格式文件(.xls, .xlsx)');
|
|
}
|
|
|
|
// 移动文件到临时目录
|
|
$info = $file->move(ROOT_PATH . 'data' . DS . 'runtime', '');
|
|
if (!$info) {
|
|
$this->error('文件上传失败: ' . $file->getError());
|
|
}
|
|
|
|
$filename = ROOT_PATH . 'data' . DS . 'runtime' . DS . $info->getSaveName();
|
|
|
|
// 解析Excel文件
|
|
$data = [];
|
|
try {
|
|
// 引入PHPExcel库
|
|
vendor('phpoffice.phpexcel.Classes.PHPExcel');
|
|
|
|
// 判断文件类型
|
|
if ($ext == 'xls') {
|
|
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
|
|
} else {
|
|
$objReader = \PHPExcel_IOFactory::createReader('Excel2007');
|
|
}
|
|
|
|
$objPHPExcel = $objReader->load($filename);
|
|
$sheet = $objPHPExcel->getSheet(0);
|
|
$highestRow = $sheet->getHighestRow();
|
|
$highestColumn = $sheet->getHighestColumn();
|
|
|
|
// 跳过第一行标题
|
|
for ($row = 2; $row <= $highestRow; $row++) {
|
|
// 获取一行数据
|
|
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE)[0];
|
|
|
|
// 确保行数据完整
|
|
if (count($rowData) >= 5) {
|
|
// 验证必要字段不为空
|
|
if (empty(trim($rowData[0]))) {
|
|
continue; // 跳过必填字段为空的行
|
|
}
|
|
|
|
$data[] = [
|
|
'name' => trim($rowData[0]),
|
|
'enterprise' => trim($rowData[1]),
|
|
'filing' => trim($rowData[2]),
|
|
'sid' => trim($rowData[3]),
|
|
'limitationdate' => trim($rowData[4]),
|
|
'createtime' => getTime()
|
|
];
|
|
}
|
|
}
|
|
|
|
// 删除临时文件
|
|
unlink($filename);
|
|
|
|
// 批量插入数据
|
|
if (!empty($data)) {
|
|
$result = Db::name('project')->insertAll($data);
|
|
if ($result) {
|
|
$this->success('成功导入 ' . count($data) . ' 条记录');
|
|
} else {
|
|
$this->error('导入失败');
|
|
}
|
|
} else {
|
|
$this->error('文件中没有有效数据');
|
|
}
|
|
} catch (\Exception $e) {
|
|
// 删除临时文件
|
|
if (file_exists($filename)) {
|
|
unlink($filename);
|
|
}
|
|
$this->error('文件解析失败: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
$this->error('非法请求');
|
|
}
|
|
|
|
/**
|
|
* 测试
|
|
* @return string
|
|
*/
|
|
public function createShopImage()
|
|
{
|
|
$data = array(
|
|
'title'=>'防爆电器',
|
|
'enterprise'=>'新黎明科技股份有限公司',
|
|
'filing'=>'G-20230525',
|
|
'sid'=>'91320500582331116Y',
|
|
'limitationdate'=>'2023-05-25',
|
|
);
|
|
$id = 1;
|
|
$path = "uploads/imgs/";
|
|
$mid = 1;
|
|
$me =array();
|
|
$file = $id.'.jpg';
|
|
$font = "uploads/msyh.ttf";
|
|
$target = imagecreatetruecolor(1657, 1105);
|
|
$bc = imagecolorallocate($target, 0, 0, 0);
|
|
$cc = imagecolorallocate($target, 255, 51, 0);
|
|
$wc = imagecolorallocate($target, 255, 255, 255);
|
|
$yc = imagecolorallocate($target, 255, 255, 0);
|
|
//背景
|
|
$bg = imagecreatefromjpeg("uploads/imgs/b.jpg");
|
|
imagecopy($target, $bg, 0, 0, 0, 0, 1657, 1105);
|
|
imagedestroy($bg);
|
|
|
|
//名称
|
|
imagettftext($target, 23, 0, 600, 589, $bc, $font, $data['title']);
|
|
//个人/企业
|
|
imagettftext($target, 23, 0, 600, 652, $bc, $font, $data['enterprise']);
|
|
//备案号
|
|
imagettftext($target, 23, 0, 600, 718, $bc, $font, $data['filing']);
|
|
//证件号码
|
|
imagettftext($target, 23, 0, 600, 786, $bc, $font, $data['sid']);
|
|
//有效期
|
|
imagettftext($target, 23, 0, 600, 850, $bc, $font, $data['limitationdate']);
|
|
imagejpeg($target, $path . $file);
|
|
imagedestroy($target);
|
|
echo '<img src="../../uploads/imgs/'.$id.'.jpg">';
|
|
}
|
|
|
|
// 查询密码列表
|
|
public function password_index()
|
|
{
|
|
$list = array();
|
|
|
|
$param = input('param.');
|
|
$condition = array();
|
|
// 应用搜索条件
|
|
foreach (['keywords'] as $key) {
|
|
if (isset($param[$key]) && $param[$key] !== '') {
|
|
if ($key == 'keywords') {
|
|
$condition['password'] = array('LIKE', "%{$param[$key]}%");
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 数据查询
|
|
*/
|
|
$count = $this->projectQueryPasswordDb->where($condition)->count();// 查询满足要求的总记录数
|
|
$Page = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
|
|
$list = $this->projectQueryPasswordDb
|
|
->where($condition)
|
|
->order('id desc')
|
|
->limit($Page->firstRow.','.$Page->listRows)
|
|
->select();
|
|
|
|
$show = $Page->show();// 分页显示输出
|
|
$this->assign('page',$show);// 赋值分页输出
|
|
$this->assign('list',$list);// 赋值数据集
|
|
$this->assign('pager',$Page);// 赋值分页集
|
|
|
|
return $this->fetch('password_index');
|
|
}
|
|
|
|
// 新增/编辑查询密码
|
|
public function password_add()
|
|
{
|
|
$id = input('id/d', 0);
|
|
|
|
if ($id > 0) {
|
|
$info = $this->projectQueryPasswordDb->where(['id' => $id])->find();
|
|
if (empty($info)) {
|
|
$this->error('数据不存在');
|
|
}
|
|
$this->assign('info', $info);
|
|
}
|
|
|
|
if (IS_POST) {
|
|
$post = input('post.');
|
|
|
|
// 验证数据
|
|
if (empty($post['password'])) {
|
|
$this->error('查询密码不能为空');
|
|
}
|
|
|
|
// 准备数据
|
|
$data = [
|
|
'password' => trim($post['password']),
|
|
'allow_keywords' => trim($post['allow_keywords']),
|
|
'deny_keywords' => trim($post['deny_keywords']),
|
|
'allow_servicer_keywords' => trim($post['allow_servicer_keywords']),
|
|
'deny_servicer_keywords' => trim($post['deny_servicer_keywords']),
|
|
'status' => !empty($post['status']) ? 1 : 0,
|
|
'updatetime' => time()
|
|
];
|
|
|
|
if (empty($info)) {
|
|
// 新增
|
|
$data['createtime'] = time();
|
|
$result = $this->projectQueryPasswordDb->insert($data);
|
|
$msg = '新增';
|
|
} else {
|
|
// 编辑
|
|
$result = $this->projectQueryPasswordDb->where(['id' => $id])->update($data);
|
|
$msg = '编辑';
|
|
}
|
|
|
|
if ($result !== false) {
|
|
$this->success($msg . "成功", url('Project/password_index'));
|
|
} else {
|
|
$this->error($msg . "失败");
|
|
}
|
|
}
|
|
|
|
$this->assign('id', $id);
|
|
return $this->fetch('password_add');
|
|
}
|
|
|
|
// 删除查询密码
|
|
public function password_del()
|
|
{
|
|
$id = input('del_id/d', 0);
|
|
if (IS_AJAX_POST && !empty($id)) {
|
|
$result = $this->projectQueryPasswordDb->where(['id' => $id])->delete();
|
|
if ($result) {
|
|
$this->success('删除成功');
|
|
} else {
|
|
$this->error('删除失败');
|
|
}
|
|
}
|
|
$this->error('参数有误');
|
|
}
|
|
|
|
// 批量删除查询密码
|
|
public function password_batch_del()
|
|
{
|
|
$ids = input('del_id/a');
|
|
if (IS_AJAX_POST && !empty($ids)) {
|
|
$result = $this->projectQueryPasswordDb->where(['id' => ['IN', $ids]])->delete();
|
|
if ($result) {
|
|
$this->success('批量删除成功');
|
|
} else {
|
|
$this->error('批量删除失败');
|
|
}
|
|
}
|
|
$this->error('参数有误');
|
|
}
|
|
|
|
// 修改状态
|
|
public function password_change_status()
|
|
{
|
|
$id = input('id/d', 0);
|
|
$status = input('status/d', 0);
|
|
|
|
if (IS_AJAX_POST && !empty($id)) {
|
|
$result = $this->projectQueryPasswordDb->where(['id' => $id])->update(['status' => $status, 'updatetime' => time()]);
|
|
if ($result) {
|
|
$this->success('状态修改成功');
|
|
} else {
|
|
$this->error('状态修改失败');
|
|
}
|
|
}
|
|
$this->error('参数有误');
|
|
}
|
|
} |