...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use function fast\e;
|
|
|
use think\Cache;
|
|
|
use think\Db;
|
|
|
use think\Session;
|
...
|
...
|
@@ -26,7 +27,7 @@ use think\exception\PDOException; |
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
protected $noNeedLogin = ['*'];
|
|
|
protected $noNeedLogin = ['video_list'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -35,6 +36,8 @@ class User extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/index)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
...
|
...
|
@@ -54,17 +57,16 @@ class User extends Api |
|
|
public function index()
|
|
|
{
|
|
|
$qiniu = get_addon_config('qiniu')['cdnurl'];
|
|
|
$user_id = Session::get('user_id');
|
|
|
if(empty($user_id)){
|
|
|
$this->error('请先登录');
|
|
|
}
|
|
|
$data = Db::name('third')->where('id',$user_id)->find();
|
|
|
$user_id = $this->auth->id;
|
|
|
$data = Db::name('user')->where('id',$user_id)->find();
|
|
|
if(empty($data['nickname'])){
|
|
|
$data['nickname'] = '';
|
|
|
}
|
|
|
if(empty($data['image'])){
|
|
|
$data['image'] = '';
|
|
|
$data['yuan_image'] = '';
|
|
|
}else{
|
|
|
$data['yuan_image'] = $data['image'];
|
|
|
$data['image'] = $qiniu.$data['image'];
|
|
|
}
|
|
|
if(empty($data['card'])){
|
...
|
...
|
@@ -85,7 +87,7 @@ class User extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/edit_info)
|
|
|
*
|
|
|
* @ApiParams (name="user_id", type="int", required=true, description="用户ID")
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="nickname", type="string", required=true, description="姓名")
|
|
|
* @ApiParams (name="sex", type="int", required=true, description="性别1男0女")
|
|
|
* @ApiParams (name="card", type="string", required=true, description="身份证号")
|
...
|
...
|
@@ -104,7 +106,7 @@ class User extends Api |
|
|
*/
|
|
|
public function edit_info()
|
|
|
{
|
|
|
$user_id = $this->request->param('user_id');
|
|
|
$user_id = $this->auth->id;
|
|
|
$nickname = $this->request->param('nickname');
|
|
|
$sex = $this->request->param('sex');
|
|
|
$card = $this->request->param('card');
|
...
|
...
|
@@ -121,14 +123,19 @@ class User extends Api |
|
|
$this->error('验证码错误');
|
|
|
}
|
|
|
}
|
|
|
$data = Db::name('third')
|
|
|
->where('id',$user_id)
|
|
|
->update(['nickname'=>$nickname,'sex'=>$sex,'card'=>$card,'work_address'=>$work_address,'phone'=>$phone,'image'=>$image]);
|
|
|
if(!empty($data)){
|
|
|
$this->success('success');
|
|
|
$data = Db::name('user')->where('id',$user_id)->find();
|
|
|
if(empty($data['image'])){
|
|
|
Db::name('user')
|
|
|
->where('id',$user_id)
|
|
|
->update(['nickname'=>$nickname,'sex'=>$sex,'card'=>$card,'work_address'=>$work_address,'phone'=>$phone,'image'=>$image]);
|
|
|
}else{
|
|
|
$this->error('error');
|
|
|
Db::name('user')
|
|
|
->where('id',$user_id)
|
|
|
->update(['nickname'=>$nickname,'sex'=>$sex,'card'=>$card,'work_address'=>$work_address,'phone'=>$phone]);
|
|
|
}
|
|
|
|
|
|
|
|
|
$this->success('success');
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -143,21 +150,25 @@ class User extends Api |
|
|
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
"id"://ID
|
|
|
"study_id"://学习系统id
|
|
|
"is_major"://1主修2选修
|
|
|
"tag"://标签
|
|
|
"name"://课程名称
|
|
|
"video_file"://视频地址
|
|
|
"video_image"://视频首帧图
|
|
|
"duration"://总时长/秒
|
|
|
"class_hour"://学时
|
|
|
"content"://内容详情
|
|
|
"teacher"://讲师
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
"total_num"://总时长
|
|
|
"info":[
|
|
|
"id"://ID
|
|
|
"study_id"://学习系统id
|
|
|
"is_major"://1主修2选修
|
|
|
"tag"://标签
|
|
|
"name"://课程名称
|
|
|
"video_file"://视频地址
|
|
|
"video_image"://视频首帧图
|
|
|
"duration"://总时长/秒
|
|
|
"class_hour"://学时
|
|
|
"content"://内容详情
|
|
|
"teacher"://讲师
|
|
|
]
|
|
|
|
|
|
}
|
|
|
})
|
|
|
*/
|
...
|
...
|
@@ -180,16 +191,19 @@ class User extends Api |
|
|
}
|
|
|
$where['study_id'] = $id;
|
|
|
$qiniu = get_addon_config('qiniu')['cdnurl'];
|
|
|
$data = Db::name('classes')
|
|
|
$data['total_num'] = Db::name('classes')
|
|
|
->where($where)
|
|
|
->count();
|
|
|
$data['info'] = Db::name('classes')
|
|
|
->field('createtime,updatetime',true)
|
|
|
->where($where)
|
|
|
->page($page,$pageNum)
|
|
|
->order('id desc')
|
|
|
->select();
|
|
|
foreach ($data as &$v){
|
|
|
foreach ($data['info'] as &$v){
|
|
|
$v['video_file'] = $qiniu.$v['video_file'];
|
|
|
$video_info = json_decode(file_get_contents($v['video_file'] . '?avinfo'), true);
|
|
|
$v['video_image'] = $this->get_video_first_image( $v['video_file'], $video_info);
|
|
|
// $video_info = json_decode(file_get_contents($v['video_file'] . '?avinfo'), true);
|
|
|
$v['video_image'] = $qiniu.$v['video_image'];
|
|
|
}
|
|
|
$this->success('success',$data);
|
|
|
}
|
...
|
...
|
@@ -200,6 +214,7 @@ class User extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/video_detail)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="培训课程id")
|
|
|
*
|
|
|
* @ApiReturn({
|
...
|
...
|
@@ -221,16 +236,23 @@ class User extends Api |
|
|
"teacher"://讲师
|
|
|
"expirationtime"://截止日期
|
|
|
"is_join"://是否已经加入学习计划1未加入2已加入
|
|
|
"bofangtime"://播放时长/秒
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function video_detail()
|
|
|
{
|
|
|
$user_id = Session::get('user_id');
|
|
|
$user_id = $this->auth->id;
|
|
|
$id = $this->request->param('id');
|
|
|
if(empty($id)){
|
|
|
$this->error('缺少必要参数');
|
|
|
}
|
|
|
|
|
|
$user_info = Db::name('user')->where('id',$user_id)->find();
|
|
|
if(empty($user_info['image']) || empty($user_info['phone'])){
|
|
|
$this->error('请先完善个人信息');
|
|
|
}
|
|
|
|
|
|
$qiniu = get_addon_config('qiniu')['cdnurl'];
|
|
|
$data = Db::name('classes')
|
|
|
->alias('a')
|
...
|
...
|
@@ -239,6 +261,24 @@ class User extends Api |
|
|
->field('a.*,b.expirationtime')
|
|
|
->find();
|
|
|
|
|
|
//查看播放秒数
|
|
|
$class_detail = Db::name('class_detail')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('class_id',$id)
|
|
|
->find();
|
|
|
if(empty($class_detail)){
|
|
|
$res['user_id'] = $user_id;
|
|
|
$res['class_id'] = $id;
|
|
|
$res['duration'] = 0;
|
|
|
$res['createtime'] = time();
|
|
|
Db::name('class_detail')->insert($res);
|
|
|
$data['bofangtime'] = 0;
|
|
|
$data['is_end'] = 2;
|
|
|
}else{
|
|
|
$data['bofangtime'] = $class_detail['duration'];
|
|
|
$data['is_end'] = $class_detail['is_end'];
|
|
|
}
|
|
|
|
|
|
|
|
|
$info = Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
...
|
...
|
@@ -252,21 +292,97 @@ class User extends Api |
|
|
}
|
|
|
//视频地址以及首帧图
|
|
|
$data['video_file'] = $qiniu.$data['video_file'];
|
|
|
$video_info = json_decode(file_get_contents($data['video_file'] . '?avinfo'), true);
|
|
|
$data['video_image'] = $this->get_video_first_image($data['video_file'], $video_info);
|
|
|
// $video_info = json_decode(file_get_contents($data['video_file'] . '?avinfo'), true);
|
|
|
$data['video_image'] = $qiniu.$data['video_image'];
|
|
|
$data['expirationtime'] = date('Y-m-d H:i:s',$data['expirationtime']);
|
|
|
$data['min'] = ceil($data['duration']/60);
|
|
|
$this->success('success',$data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (记录播放时间)
|
|
|
* @ApiSummary (记录播放时间)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/bofang)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="培训课程id")
|
|
|
* @ApiParams (name="duration", type="int", required=true, description="播放时间")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function bofang()
|
|
|
{
|
|
|
$user_id = $this->auth->id;
|
|
|
$id = $this->request->param('id');
|
|
|
$duration = $this->request->param('duration');
|
|
|
if(empty($id) || empty($duration)){
|
|
|
$this->error('缺少必要参数');
|
|
|
}
|
|
|
|
|
|
$class = Db::name('classes')
|
|
|
->where('id',$id)
|
|
|
->field('id,duration,study_id')
|
|
|
->find();
|
|
|
|
|
|
|
|
|
|
|
|
if($duration >= $class['duration']){
|
|
|
$is_end = 1;
|
|
|
|
|
|
$study_class = Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
|
|
->where('study_id',$class['study_id'])
|
|
|
->where('class_id',$id)
|
|
|
->find();
|
|
|
if(!empty($study_class)){
|
|
|
Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
|
|
->where('study_id',$class['study_id'])
|
|
|
->where('class_id',$id)
|
|
|
->update(['status'=>2,'playtime'=>$duration]);
|
|
|
}
|
|
|
}else{
|
|
|
$is_end = 2;
|
|
|
$study_class = Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
|
|
->where('study_id',$class['study_id'])
|
|
|
->where('class_id',$id)
|
|
|
->find();
|
|
|
if(!empty($study_class)){
|
|
|
Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
|
|
->where('study_id',$class['study_id'])
|
|
|
->where('class_id',$id)
|
|
|
->update(['playtime'=>$duration]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$data = Db::name('class_detail')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('class_id',$id)
|
|
|
->update(['duration'=>$duration,'is_end'=>$is_end]);
|
|
|
if(empty($data)){
|
|
|
$this->error('失败');
|
|
|
}else{
|
|
|
$this->success('成功');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (加入学习计划)
|
|
|
* @ApiSummary (加入学习计划)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/join)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="培训课程id")
|
|
|
* @ApiParams (name="playtime", type="int", required=true, description="播放秒数")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
...
|
...
|
@@ -278,33 +394,34 @@ class User extends Api |
|
|
*/
|
|
|
public function join()
|
|
|
{
|
|
|
$info['third_id'] = Session::get('user_id');
|
|
|
if(empty($info['third_id'])){
|
|
|
$this->error('请先登录');
|
|
|
}
|
|
|
$info['third_id'] = $this->auth->id;
|
|
|
$info['class_id'] = $this->request->param('id');
|
|
|
if(empty($info['class_id'])){
|
|
|
$this->error('缺少必要参数');
|
|
|
}
|
|
|
$data = Db::name('classes')
|
|
|
->where('id',$info['class_id'])
|
|
|
->value('study_id');
|
|
|
$info['study_id'] = $data;
|
|
|
$playtime = $this->request->param('playtime');
|
|
|
if($playtime != 0){
|
|
|
$classes = Db::name('classes')
|
|
|
->where('id',$info['class_id'])
|
|
|
->find();
|
|
|
if($classes['duration'] <= $playtime){
|
|
|
$info['status'] = 2;
|
|
|
$info['playtime'] = $playtime;
|
|
|
->field('study_id,duration')
|
|
|
->find();
|
|
|
$info['study_id'] = $data['study_id'];
|
|
|
|
|
|
|
|
|
//查询用户是否已经播放完毕该视频
|
|
|
$video = Db::name('class_detail')
|
|
|
->where('user_id',$info['third_id'])
|
|
|
->where('class_id',$info['class_id'])
|
|
|
->find();
|
|
|
if(empty($video)){
|
|
|
$info['playtime'] = 0;
|
|
|
}else{
|
|
|
if($video['is_end'] == 2){
|
|
|
$info['playtime'] = $video['duration'];
|
|
|
}else{
|
|
|
$info['status'] = 1;
|
|
|
$info['playtime'] = $playtime;
|
|
|
$info['playtime'] = $data['duration'];
|
|
|
$info['status'] = 2;
|
|
|
}
|
|
|
}else{
|
|
|
$info['playtime'] = 0;
|
|
|
}
|
|
|
|
|
|
$info['createtime'] = time();
|
|
|
$is_have = Db::name('study_class')
|
|
|
->where('third_id',$info['third_id'])
|
...
|
...
|
@@ -329,6 +446,7 @@ class User extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/del_join)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="培训课程id")
|
|
|
*
|
|
|
* @ApiReturn({
|
...
|
...
|
@@ -341,7 +459,7 @@ class User extends Api |
|
|
*/
|
|
|
public function del_join()
|
|
|
{
|
|
|
$user_id = Session::get('user_id');
|
|
|
$user_id = $this->auth->id;
|
|
|
$id = $this->request->param('id');
|
|
|
if(empty($id)){
|
|
|
$this->error('缺少必要参数');
|
...
|
...
|
@@ -362,16 +480,14 @@ class User extends Api |
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (我的考试)
|
|
|
* @ApiSummary (我的考试)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/myexam)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="学习系统id")
|
|
|
*
|
|
|
* @ApiReturn({
|
...
|
...
|
@@ -387,6 +503,7 @@ class User extends Api |
|
|
"image"://图片
|
|
|
"proportion"://比例
|
|
|
"expirationtime"://截止日期
|
|
|
"is_xian"://是否显示1显示2不显示
|
|
|
],
|
|
|
"info": [
|
|
|
{
|
...
|
...
|
@@ -405,7 +522,7 @@ class User extends Api |
|
|
public function myexam()
|
|
|
{
|
|
|
$qiniu = get_addon_config('qiniu')['cdnurl'];
|
|
|
$user_id = Session::get('user_id');
|
|
|
$user_id = $this->auth->id;
|
|
|
$id = $this->request->param('id');
|
|
|
if(empty($id)){
|
|
|
$this->error('缺少必要参数');
|
...
|
...
|
@@ -414,14 +531,13 @@ class User extends Api |
|
|
->where('id',$id)
|
|
|
->find();
|
|
|
|
|
|
$data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']);
|
|
|
$data['exam']['image'] = $qiniu.$data['exam']['image'];
|
|
|
|
|
|
$finish_hour = Db::name('study_class')
|
|
|
->alias('a')
|
|
|
->join('classes b','a.class_id = b.id')
|
|
|
->where('a.third_id',$user_id)
|
|
|
->where('a.study_id',$id)
|
|
|
->where('b.is_major',1)
|
|
|
->where('a.status',2)
|
|
|
->field('sum(b.class_hour) as finish_hour')
|
|
|
->find();
|
...
|
...
|
@@ -431,19 +547,54 @@ class User extends Api |
|
|
}else{
|
|
|
$data['exam']['finish_hour'] = $finish_hour['finish_hour'];
|
|
|
}
|
|
|
|
|
|
//查询出所有该科目的必修课
|
|
|
$class_ids = Db::name('classes')->where('study_id',$id)->where('is_major',1)->column('id');
|
|
|
$is_end = Db::name('study_class')
|
|
|
->where('third_id',$user_id)
|
|
|
->where('study_id',$id)
|
|
|
->whereIn('class_id',$class_ids)
|
|
|
->where('status',1)
|
|
|
->find();
|
|
|
|
|
|
//查看用户该科目是否已经考过3次了
|
|
|
$third_exam = Db::name('third_exam')
|
|
|
->where('user_id',$user_id)
|
|
|
->where('study_id',$id)
|
|
|
->order('exam_num desc')
|
|
|
->find();
|
|
|
|
|
|
//该用户绑定该科目的有效期
|
|
|
$third_study = Db::name('third_study')->where('third_id',$user_id)->where('study_id',$id)->find();
|
|
|
|
|
|
if($third_study['periodtime'] < time() || $data['exam']['expirationtime']<time() || $data['exam']['finish_hour'] < $data['exam']['class_hour'] || !empty($is_end) || $third_exam['exam_num'] == 3){
|
|
|
$data['exam']['is_xian'] = 2;
|
|
|
}else{
|
|
|
$data['exam']['is_xian'] = 1;
|
|
|
}
|
|
|
$data['exam']['expirationtime'] = date('Y-m-d H:i:s',$data['exam']['expirationtime']);
|
|
|
|
|
|
unset($data['exam']['updatetime']);
|
|
|
unset($data['exam']['createtime']);
|
|
|
$data['exam']['proportion'] = round($data['exam']['finish_hour']/$data['exam']['class_hour']*100,0).'%';
|
|
|
$a = round($data['exam']['finish_hour']/$data['exam']['class_hour']*100,0);
|
|
|
if($a > 100){
|
|
|
$a = 100;
|
|
|
}
|
|
|
$data['exam']['proportion'] = $a.'%';
|
|
|
|
|
|
$data['info'] = Db::name('study_class')
|
|
|
->alias('a')
|
|
|
->join('classes b','a.class_id = b.id')
|
|
|
->where('a.third_id',$user_id)
|
|
|
->where('a.study_id',$id)
|
|
|
->field('a.id,b.name,b.class_hour,b.is_major,b.duration,a.status,a.playtime')
|
|
|
->field('b.id,a.id as study_class_id,b.name,b.class_hour,b.is_major,b.duration,a.status,a.playtime')
|
|
|
->select();
|
|
|
foreach ($data['info'] as &$v){
|
|
|
$v['proportion'] = round($v['playtime']/$v['duration']*100,0).'%';
|
|
|
if($v['status'] == 1){
|
|
|
$v['proportion'] = round($v['playtime']/$v['duration']*100,0).'%';
|
|
|
}else{
|
|
|
$v['proportion'] = '100%';
|
|
|
}
|
|
|
$v['duration'] = ceil($v['duration']/60);
|
|
|
}
|
|
|
$this->success('success',$data);
|
...
|
...
|
@@ -456,6 +607,7 @@ class User extends Api |
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/user/certificate)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="int", required=true, description="考试记录id")
|
|
|
*
|
|
|
* @ApiReturn({
|
...
|
...
|
@@ -463,15 +615,14 @@ class User extends Api |
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
"qrcodeurl": //证书图片,
|
|
|
"score": //分数
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function certificate(){
|
|
|
$qiniu = get_addon_config('qiniu')['cdnurl'];
|
|
|
$user_id = Session::get('user_id');
|
|
|
if(empty($user_id)){
|
|
|
$this->error('请先登录');
|
|
|
}
|
|
|
$user_id = $this->auth->id;
|
|
|
$id = $this->request->param('id');
|
|
|
if(empty($id)){
|
|
|
$this->error('缺少必要参数');
|
...
|
...
|
@@ -481,90 +632,74 @@ class User extends Api |
|
|
$data = Db::name('third_exam')
|
|
|
->alias('a')
|
|
|
->join('study b','a.study_id = b.id')
|
|
|
->join('third c','a.user_id = c.id')
|
|
|
->join('user c','a.user_id = c.id')
|
|
|
->where('a.id',$id)
|
|
|
->field('a.id,a.user_id,a.study_id,a.createtime,b.examname,b.class_hour,c.image,c.card,c.nickname')
|
|
|
->field('a.id,a.score,a.user_id,a.study_id,a.createtime,b.yinimage,b.workname,c.studynum,b.class_hour,c.image,c.card,c.nickname')
|
|
|
->find();
|
|
|
$data['image'] = $qiniu.$data['image'];
|
|
|
//将图片下载到本地且转换为https
|
|
|
// $base_url = $data['image'];
|
|
|
// $qiniu_url = $qiniu.$data['image'];
|
|
|
// $a = file_get_contents($qiniu_url);
|
|
|
// $path = './uploads/'.explode('/',$base_url)[2].'/';
|
|
|
// if(!file_exists($path)) {
|
|
|
// mkdir($path,0777,true);
|
|
|
// }
|
|
|
// file_put_contents('.'.$base_url,$a);
|
|
|
// $data['water_url'] = request()->domain().$base_url;
|
|
|
|
|
|
$file_path = "qrcode/$id.png";
|
|
|
|
|
|
$image = \think\Image::open(ROOT_PATH."public/YUAN.png");
|
|
|
$path_ttf = ROOT_PATH.'public/assets/fonts/PingFang.ttf';
|
|
|
$data['createtime'] = date('Y年m月d日',$data['createtime']);
|
|
|
|
|
|
$text1 = '继续教育培训合格证书';
|
|
|
$year = date('Y');
|
|
|
$time = date('Ymd');
|
|
|
$text2 = $data['nickname'].'已完成'.$year.'年度'.$data['examname'].'继续教育培训,'.$data['class_hour'].'学时,经考核成绩合格。特发此证';
|
|
|
$text3 = '身份证号: '.$data['card'];
|
|
|
$text4 = '证书编号: TJAG'.$time;
|
|
|
|
|
|
$result = $image
|
|
|
->text($text1,$path_ttf,40,'#FFFFFF',[142,100]);
|
|
|
$image->save(ROOT_PATH . 'public' . DS . 'uploads' . DS . $file_path,'jpg',100);
|
|
|
|
|
|
$path = '/uploads/'.$file_path;
|
|
|
$upload = Config::get('upload');
|
|
|
$config = get_addon_config('qiniu');
|
|
|
$filePath = '.'.$path;
|
|
|
$suffix = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
|
|
|
$suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'file';
|
|
|
$replaceArr = [
|
|
|
'{year}' => date("Y"),
|
|
|
'{mon}' => date("m"),
|
|
|
'{day}' => date("d"),
|
|
|
'{hour}' => date("H"),
|
|
|
'{min}' => date("i"),
|
|
|
'{sec}' => date("s"),
|
|
|
'{random}' => Random::alnum(16),
|
|
|
'{random32}' => Random::alnum(32),
|
|
|
'{filename}' => $suffix ? substr(pathinfo($filePath)['basename'], 0, strripos(pathinfo($filePath)['basename'], '.')) : pathinfo($filePath)['basename'],
|
|
|
'{suffix}' => $suffix,
|
|
|
'{.suffix}' => $suffix ? '.' . $suffix : '',
|
|
|
'{filemd5}' => md5_file(realpath($filePath)),
|
|
|
];
|
|
|
$savekey = $upload['savekey'];
|
|
|
$savekey = str_replace(array_keys($replaceArr), array_values($replaceArr), $savekey);
|
|
|
$fileName = substr($savekey, strripos($savekey, '/') + 1);
|
|
|
$policy = array(
|
|
|
'saveKey' => ltrim($savekey, '/'),
|
|
|
);
|
|
|
$auth = new \addons\qiniu\library\Auth($config['app_key'], $config['secret_key']);
|
|
|
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
|
|
|
$multipart = [
|
|
|
['name' => 'token', 'contents' => $token],
|
|
|
[
|
|
|
'name' => 'file',
|
|
|
'contents' => fopen(realpath($filePath), 'r'),
|
|
|
'filename' => $fileName,
|
|
|
]
|
|
|
];
|
|
|
try {
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
$res = $client->request('POST', $config['uploadurl'], [
|
|
|
'multipart' => $multipart
|
|
|
]);
|
|
|
$code = $res->getStatusCode();
|
|
|
//成功不做任何操作
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
unlink($filePath);
|
|
|
$this->error("上传失败");
|
|
|
|
|
|
if(empty($data['image'])){
|
|
|
$this->error('请先上传用户头像');
|
|
|
}
|
|
|
unlink($filePath);
|
|
|
|
|
|
return '/uploads/'.date('Ymd').'/'.$fileName;
|
|
|
}
|
|
|
//将用户的头像保存到本地
|
|
|
$qiniu_url = $qiniu.$data['image'];
|
|
|
$image_name = $user_id.'.png';
|
|
|
$furl = ROOT_PATH . 'public' . DS . 'uploads/user/'.$image_name;
|
|
|
$a = file_get_contents($qiniu_url);
|
|
|
file_put_contents($furl,$a);
|
|
|
|
|
|
//将考试的印章图片保存到本地
|
|
|
$yinimage = $qiniu.$data['yinimage'];
|
|
|
$imagename = $data['study_id'].'.png';
|
|
|
$yinfurl = ROOT_PATH . 'public' . DS . 'uploads/qrcode/'.$imagename;
|
|
|
$b = file_get_contents($yinimage);
|
|
|
file_put_contents($yinfurl,$b);
|
|
|
|
|
|
|
|
|
//用户头像
|
|
|
$user_image = \think\Image::open(ROOT_PATH."public/uploads/user/$image_name");
|
|
|
$user_image->thumb(184,220,\think\Image::THUMB_CENTER)->save(ROOT_PATH."public/uploads/user/$image_name");
|
|
|
|
|
|
//印象头像
|
|
|
$yin_image = \think\Image::open(ROOT_PATH."public/uploads/qrcode/$imagename");
|
|
|
$yin_image->thumb(248,242,\think\Image::THUMB_CENTER)->save(ROOT_PATH."public/uploads/qrcode/$imagename");
|
|
|
|
|
|
|
|
|
|
|
|
$file_path = "$id.png";
|
|
|
$image = \think\Image::open(ROOT_PATH."public/uploads/yuan.png");
|
|
|
$path_ttf = ROOT_PATH.'public/assets/fonts/PingFang.ttf';
|
|
|
$year = date('Y');
|
|
|
//证书编号
|
|
|
$text = 'TJAG'.$year.$data['studynum'];
|
|
|
//培训单位盖章
|
|
|
$text1 = '培训单位盖章';
|
|
|
|
|
|
$image->water(ROOT_PATH."public/uploads/qrcode/$imagename",[1200,602],100);
|
|
|
$image->water(ROOT_PATH."public/uploads/user/$image_name",[300,430],100);
|
|
|
$image->text($data['card'],$path_ttf,25,'#000000',[300,778]);
|
|
|
$image->text($text,$path_ttf,25,'#000000',[300,868]);
|
|
|
$image->text($data['nickname'],$path_ttf,30,'#000000',[850,364]);
|
|
|
$image->text($data['nickname'],$path_ttf,30,'#000000',[851,364]);
|
|
|
$image->text($year,$path_ttf,30,'#000000',[1121,364]);
|
|
|
$image->text($year,$path_ttf,30,'#000000',[1122,364]);
|
|
|
$image->text($data['workname'],$path_ttf,30,'#000000',[1325,362]);
|
|
|
$image->text($data['workname'],$path_ttf,30,'#000000',[1326,362]);
|
|
|
$image->text($data['class_hour'],$path_ttf,30,'#000000',[1071,442]);
|
|
|
$image->text($data['class_hour'],$path_ttf,30,'#000000',[1072,442]);
|
|
|
$image->text($data['createtime'],$path_ttf,30,'#000000',[1121,832]);
|
|
|
$image->text($data['createtime'],$path_ttf,30,'#000000',[1122,832]);
|
|
|
$image->text($text1,$path_ttf,30,'#000000',[1187,772]);
|
|
|
$image->text($text1,$path_ttf,30,'#000000',[1188,772]);
|
|
|
$image->save(ROOT_PATH . 'public' . DS . 'uploads' . DS . $file_path,'png',100);
|
|
|
|
|
|
$answer['qrcodeurl'] = request()->domain().'/uploads/'.$id.'.png';
|
|
|
$answer['score'] = $data['score'];
|
|
|
$this->success('success',$answer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|