You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.0 KiB
87 lines
3.0 KiB
<?php
|
|
|
|
|
|
namespace service;
|
|
|
|
use app\wap\model\wap\Clearance;
|
|
use app\wap\model\wap\ClearanceSubject;
|
|
use app\wap\model\wap\ClearanceSubjectChapter;
|
|
use app\wap\model\wap\UserClearance;
|
|
use app\wap\model\wap\UserClearanceDetail;
|
|
|
|
class ClearanceService
|
|
{
|
|
|
|
/**
|
|
* 用户打卡记录
|
|
* [clockIn description]
|
|
* @param [type] $user_id [description]
|
|
* @param [type] $type [description]
|
|
* @param [type] $clearance_id [description]
|
|
* @param integer $item_id [description]
|
|
* @param integer $chapter_id [description]
|
|
* @param integer $section_id [description]
|
|
* @param integer $score [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public static function clockIn($user_id, $cate_id, $type, $clearance_id, $item_id = 0, $chapter_id = 0, $section_id = 0, $score = 0, $accuracy = 0, $use_time = 0){
|
|
|
|
$date = date("Y-m-d");
|
|
//如果当前背诵过了
|
|
if ($type == 1) {
|
|
$detail = UserClearanceDetail::where('user_id',$user_id)
|
|
->where('cate_id', $cate_id)
|
|
->where('clearance_id', $clearance_id)
|
|
->where('item_id', $item_id)
|
|
->where('chapter_id', $chapter_id)
|
|
->where('section_id', $section_id)
|
|
->where('date',$date)->find();
|
|
if ($detail) {
|
|
return true;
|
|
}
|
|
}
|
|
//写入打卡记录
|
|
$clearance_data = [
|
|
'user_id' => $user_id,
|
|
'cate_id' => $cate_id,
|
|
'type' => $type,
|
|
'clearance_id' => $clearance_id,
|
|
'item_id' => $item_id,
|
|
'chapter_id' => $chapter_id,
|
|
'section_id' => $section_id,
|
|
'score' => $score,
|
|
'accuracy' => $accuracy,
|
|
'use_time' => $use_time,
|
|
'add_time' => time(),
|
|
'date' => $date,
|
|
];
|
|
UserClearanceDetail::create($clearance_data);
|
|
//判断是否写了总记录
|
|
$info = UserClearance::where('user_id',$user_id)->where('cate_id', $cate_id)->find();
|
|
if (!$info) {
|
|
$userClearance = [
|
|
'user_id' => $user_id,
|
|
'cate_id' => $cate_id,
|
|
'add_time' => time(),
|
|
'days' => 1,
|
|
'recite_num' => 1,
|
|
'accuracy' => $accuracy,
|
|
];
|
|
UserClearance::create($userClearance);
|
|
} else {
|
|
$detail = UserClearanceDetail::where('user_id',$user_id)->where('cate_id', $cate_id)->where('date',$date)->find();
|
|
//当前没打卡,天数+1
|
|
if (!$detail) {
|
|
$update_data['days'] = $info['days'] + 1;
|
|
}
|
|
//背诵
|
|
if ($type == 1) {
|
|
$update_data['recite_num'] = $info['recite_num'] + 1;
|
|
}
|
|
if ($type == 2) {
|
|
$update_data['accuracy'] = $accuracy;//round(($info['accuracy'] + $accuracy) / 2);
|
|
}
|
|
UserClearance::where('id', $info['id'])->update($update_data);
|
|
}
|
|
}
|
|
}
|
|
|