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); } } }