|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\api\controller\v1\complaint;
|
|
|
|
|
|
|
|
use app\Request;
|
|
|
|
|
|
|
|
use app\services\crud\UserComplaintServices;
|
|
|
|
use crmeb\services\SpreadsheetExcelService;
|
|
|
|
use mysql_xdevapi\Exception;
|
|
|
|
use think\exception\ValidateException;
|
|
|
|
use app\model\activity\advance\student;
|
|
|
|
|
|
|
|
class ComplaintController
|
|
|
|
{
|
|
|
|
protected $services = NUll;
|
|
|
|
|
|
|
|
public function __construct(UserComplaintServices $services)
|
|
|
|
{
|
|
|
|
$this->services = $services;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 投诉列表
|
|
|
|
*/
|
|
|
|
public function listComplaint(Request $request)
|
|
|
|
{
|
|
|
|
$uid = (int)$request->uid();
|
|
|
|
return app('json')->success($this->services->getCrudListIndex(['user_id', $uid]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 投诉详情
|
|
|
|
*/
|
|
|
|
public function detailsComplaint(Request $request)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加投诉 上传模板
|
|
|
|
*/
|
|
|
|
public function addComplaint(Request $request)
|
|
|
|
{
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
|
|
//解析excel
|
|
|
|
if (!empty($data['type']) && $data['type'] == 1) {
|
|
|
|
$uploadDir = 'uploadsFile/';
|
|
|
|
if (!is_dir($uploadDir)) {
|
|
|
|
mkdir($uploadDir, 0777, true);
|
|
|
|
}
|
|
|
|
$tempName = $_FILES['file']['tmp_name'];
|
|
|
|
$targetName = $uploadDir . basename($_FILES['file']['name']);
|
|
|
|
// 将临时文件移动到目标位置
|
|
|
|
if (move_uploaded_file($tempName, $targetName)) {
|
|
|
|
$ff = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $targetName;
|
|
|
|
$content = file_get_contents($ff);
|
|
|
|
$array = explode(PHP_EOL, $content);
|
|
|
|
$length = count($array);
|
|
|
|
foreach ($array as $k => $v) {
|
|
|
|
if ($k != 0 && $k != $length) {
|
|
|
|
if (preg_match('/(.*?)(\d+)(.*)/', $v, $matches)) {
|
|
|
|
$beforeNumber = $matches[1]; // 第一个数字之前的字符
|
|
|
|
$number = $matches[2]; // 第一个数字
|
|
|
|
//插入数据
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// $objPHPExcel = \PhpOffice\PhpSpreadsheet\IOFactory::load($ff);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return app('json')->fail('文件上传失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($data['content'])) {
|
|
|
|
return app('json')->fail(100100);
|
|
|
|
}
|
|
|
|
if (!empty($data['image'])) {
|
|
|
|
// 去除 base64 编码的前缀(如果有的话)
|
|
|
|
$decodedData = base64_decode($data['image']);
|
|
|
|
$imageName = uniqid() . '.png'; // 使用 uniqid 生成唯一的文件名
|
|
|
|
$savePath = 'uploads/' . $imageName; // 指定保存目录和文件名
|
|
|
|
// 将解码后的数据保存为文件
|
|
|
|
if (file_put_contents($savePath, $decodedData)) {
|
|
|
|
// 图片保存成功,获取图片地址
|
|
|
|
$imageUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/' . $imageName;
|
|
|
|
$data['image'] = $imageUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $request->user()->toArray();
|
|
|
|
|
|
|
|
$data['school_id'] = $user['school_id'];
|
|
|
|
$data['user_id'] = $user['uid'];
|
|
|
|
$data['user_name'] = $user['real_name'];
|
|
|
|
$data['school_name'] = $this->services->getSchoolData($user['school_id'])['school_name'];
|
|
|
|
$this->services->crudSave($data);
|
|
|
|
return app('json')->success(100017);
|
|
|
|
}
|
|
|
|
}
|