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(); //wmc解析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']); $fileExtension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); if ($fileExtension != 'xlsx') { return 1; } // 将临时文件移动到目标位置 if (move_uploaded_file($tempName, $targetName)) { $f = public_path() . $targetName; $inputFileType = IOFactory::identify($f); $reader = IOFactory::createReader($inputFileType); $spreadSheet = $reader->load($f); //获取第几张数据表,默认从0开始 $sheet = $spreadSheet->getSheet(0); //获取最大行数 $rows = $sheet->getHighestRow(); //获取最大列数 $cols = $sheet->getHighestColumn(); //获取全量数据集,返回数组形式数据 $dataArr = $sheet->rangeToArray('A1:' . $cols . $rows); Db::startTrans(); $user = $request->user()->toArray()['uid']; $t = User::where('uid',$user)->find(); $school_id = $t['school_id']; $classid = $t['class_id']; foreach ($dataArr as $k => $v) { if ($k != 0) { $data2['account'] = $v[1]; $data2['pwd'] = md5((string)'qq111111'); $data2['phone'] = $v[1]; $data2['group_id'] = 4; $data2['school_id'] = $school_id; $data2['bind_user_id'] = 0; $data2['class_id'] = $classid; $data2['real_name'] = $v[0]; $data2['birthday'] = 0; $data2['card_id'] = ''; $data2['mark'] = ''; $data2['addres'] = ''; $data2['user_type'] = 'h5'; $data2['add_time'] = time(); $data2['add_ip'] = app('request')->ip(); $data2['last_time'] = time(); $data2['last_ip'] = app('request')->ip(); $data2['nickname'] = substr_replace($v[1], '****', 3, 4); $data2['avatar'] = sys_config('h5_avatar'); $data2['status'] = 1; $registerStatus = User::insert($data2); if (!$registerStatus) { Db::rollback(); return 1; } } } Db::commit(); return 2; } return 1; } //绑定亲属 if (!empty($data['type']) && $data['type'] == 2) { $c = User::where([ 'phone'=>$data['phone'], 'is_del'=>0 ])->find(); if($c){ return app('json')->fail('号码已被注册'); } $user = $request->user()->toArray()['uid']; $t = User::where('uid',$user)->find(); $school_id = $t['school_id']; $classid = $t['class_id']; $data2['account'] = $data['phone']; $data2['pwd'] = md5((string)'qq111111'); $data2['phone'] = $data['phone']; $data2['group_id'] = 3; $data2['school_id'] = $school_id; $data2['bind_user_id'] = 0; $data2['class_id'] = $classid; $data2['real_name'] = $t['nickname'].'的亲属'; $data2['birthday'] = 0; $data2['card_id'] = ''; $data2['mark'] = ''; $data2['addres'] = ''; $data2['user_type'] = 'h5'; $data2['add_time'] = time(); $data2['add_ip'] = app('request')->ip(); $data2['last_time'] = time(); $data2['last_ip'] = app('request')->ip(); $data2['nickname'] = substr_replace($data['phone'], '****', 3, 4); $data2['avatar'] = sys_config('h5_avatar'); $data2['status'] = 1; $registerStatus = User::insert($data2); if($registerStatus){ return app('json')->success('成功'); } 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); } }