コード例 #1
0
 /**
  * 查询用户当前做到哪种题型的第几题
  * @param $user
  * @param $testTypeId
  * @return mixed
  */
 public static function findCurrentNumber($user, $testTypeId)
 {
     $current = CurrentTestLibrary::findByUserAndTestType($user['userId'], $testTypeId);
     if (!$current) {
         return 0;
     }
     $table = TestLibrary::tableName();
     if ($testTypeId == -1) {
         $subQuery = (new Query())->select('testLibraryId')->from($table)->where(['provinceId' => $user['provinceId'], 'majorJobId' => $user['majorJobId']]);
     } else {
         $subQuery = (new Query())->select('testLibraryId')->from($table)->where(['provinceId' => $user['provinceId'], 'majorJobId' => $user['majorJobId'], 'testTypeId' => $testTypeId]);
     }
     $query = (new Query())->select('count(*)')->from([$subQuery])->where(['<=', 'testLibraryId', $current['testLibraryId']]);
     $result = $query->one();
     return $result['count(*)'];
 }