count() public method

Returns the number of records.
public count ( string $q = '*', Connection $db = null ) : integer
$q string kept to match [[QueryInterface]], its value is ignored.
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
return integer number of records
 public function actionCountList()
 {
     $accountId = $this->getAccountId();
     $keyword = $request = Yii::$app->request->get("keyword", '');
     if ($keyword == "undefined") {
         $keyword = '';
     }
     $query = new Query();
     $query->from('uhkklpCookingtype')->where(['isDeleted' => false])->andWhere(['accountId' => $accountId])->andWhere(['or', ['category' => '大類']])->andWhere(['like', 'name', $keyword]);
     $count = $query->count();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $count];
 }
 public function actionInit()
 {
     $blackList = ['0978085158', '0927965300', '0919068348', '0917256888', '0935293966', '0926231395', '0922376121', '0918762006', '0920220502', '0937041116', '0976556382', '0926163196', '0989563597', '0933170602', '0982100057', '0926988398', '0986265939', '0910254314', '0937189314', '0972113501', '0912210412', '0987906236', '0937005340', '0916206650', '0918789015', '0985979734', '0910619168', '0912866012', '0930002577', '0937006276', '0982066318', '0909111302', '0911031494', '0912600810', '0981365018', '0919096112', '0911091053', '0923319780', '0989173848', '0952655000', '0979767968', '0905630508', '0963260389', '0958917419', '0929190959', '0939068141', '0925338020', '0912764270', '0913177063', '0921530245', '0911078461', '0982919062', '0960000277'];
     $query = new Query();
     $query->from('voucher_black');
     $count = $query->count();
     if ($count == 0) {
         foreach ($blackList as $mobile) {
             $item = new VoucherBlack();
             $item->mobile = $mobile;
             $item->enable = true;
             $item->save();
         }
     }
 }
Exemplo n.º 3
0
 private function formatCookbookForAPI($cookbook)
 {
     //averageScore
     if (!isset($cookbook['averageScore'])) {
         $cookbook['averageScore'] = 0.0;
     }
     //isNewest
     for ($i = 0; $i < count($cookbook['type']); $i++) {
         if ($cookbook['type'][$i] == '最新食譜') {
             $cookbook['isNewest'] = 'Y';
         } else {
             $cookbook['isNewest'] = 'N';
         }
     }
     //collection number
     $cookbookId = $cookbook['cookbookId'];
     $query = new Query();
     $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId])->andWhere(['collection' => 'Y']);
     $collectionNumber = $query->count();
     $cookbook['collectionNumber'] = $collectionNumber;
     //score number
     $cookbookId = $cookbook['cookbookId'];
     $query = new Query();
     $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId]);
     $scorerNumber = $query->count();
     $cookbook['scorerNumber'] = $scorerNumber;
     //sample
     $sample = $cookbook['sample'];
     for ($j = 0; $j < count($sample); $j++) {
         $querySample = new Query();
         $querySample->from('uhkklpSample')->where(['_id' => $sample[$j]['id']]);
         $sampleDate = $querySample->one();
         $cookbook['sample'][$j]['imgUrl'] = $sampleDate['imgUrl'];
         $cookbook['sample'][$j]['explain'] = $sampleDate['quantity'];
         unset($cookbook['sample'][$j]['quantity']);
     }
     return $cookbook;
 }