from() public method

Sets the collection to be selected from.
public from ( $collection )
Exemplo n.º 1
0
 public function actionGetList()
 {
     $currentPage = Yii::$app->request->get("currentPage", 1);
     $pageSize = Yii::$app->request->get("pageSize", 10);
     $offset = ($currentPage - 1) * $pageSize;
     $sortName = "_id";
     $sortDesc = Yii::$app->request->get('sortDesc', 'ASC');
     $sort = $sortName . ' ' . $sortDesc;
     $keyword = Yii::$app->request->get("keyword", '');
     $query = new Query();
     $accountId = $this->getAccountId();
     if ($keyword == '') {
         $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     } else {
         $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     }
     for ($i = 0; $i < count($records); $i++) {
         $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null);
         $records[$i]['_id'] = (string) $records[$i]['_id'];
     }
     $query = new Query();
     if ($keyword == '') {
         $totalPageCount = $query->from('uhkklpOrder')->where(['accountId' => $accountId])->count();
     } else {
         $totalPageCount = $query->from('uhkklpOrder')->where(['accountId' => $accountId])->andWhere(['like', 'name', $keyword])->count();
     }
     // LogUtil::error(date('Y-m-d h:i:s') . ' $totalPageCount: ' . $totalPageCount);
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'list' => $records, 'totalPageCount' => $totalPageCount];
 }
 public function perform()
 {
     $args = $this->args;
     if (empty($args['key']) || empty($args['header']) || empty($args['accountId'])) {
         ResqueUtil::log(['status' => 'fail to export registration record', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     $keyword = $args['keyword'];
     $header = $args['header'];
     $fileName = $args['key'];
     $accountId = unserialize($args['accountId']);
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $query = new Query();
     if ($keyword == '') {
         $records = $query->from('uhkklpRegistration')->select(['name', 'mobile', 'restaurantName', 'zipCode', 'city', 'address'])->where(['accountId' => $accountId])->all();
     } else {
         $records = $query->from('uhkklpRegistration')->select(['name', 'mobile', 'restaurantName', 'zipCode', 'city', 'address'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->all();
     }
     $rows = $records;
     ExcelUtil::exportCsv($header, $rows, $filePath, 1);
     $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName);
     if ($hashKey) {
         //notice frontend the job is finished
         Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL]);
         return true;
     } else {
         ResqueUtil::log(['status' => 'fail to export registration', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]);
         return false;
     }
 }
Exemplo n.º 3
0
 private function _savePushMessages($messageId, $phoneNums)
 {
     $pushUsers = [];
     if (empty($phoneNums)) {
         $query = new Query();
         $result = $query->from(PushUser::collectionName())->select(['token', 'deviceType', 'mobile'])->where(['accountId' => $this->getAccountId()])->all();
         $pushUsers = array_merge($pushUsers, $result);
     } else {
         foreach ($phoneNums as $phone) {
             $query = new Query();
             $result = $query->from(PushUser::collectionName())->select(['token', 'deviceType', 'mobile'])->where(['mobile' => $phone, 'accountId' => $this->getAccountId()])->all();
             $pushUsers = array_merge($pushUsers, $result);
         }
     }
     $pushUsers = $this->_uniquePushUsers($pushUsers);
     foreach ($pushUsers as $pushUser) {
         $pushMessage = new PushMessage();
         if (!empty($pushUser['mobile'])) {
             $pushMessage->mobile = $pushUser['mobile'];
         }
         $pushMessage->token = $pushUser['token'];
         $pushMessage->deviceType = $pushUser['deviceType'];
         $pushMessage->messageId = $messageId;
         if (!empty($this->getAccountId())) {
             $pushMessage->accountId = $this->getAccountId();
         }
         $pushMessage->insert();
     }
 }
Exemplo n.º 4
0
 public function getList($condition = [])
 {
     $sort = ['begin' => SORT_DESC];
     $query = new Query();
     $data = $query->from(self::collectionName())->select($this->attributes())->where($condition)->orderBy($sort)->all();
     return $data;
 }
Exemplo n.º 5
0
 public function actionRegister()
 {
     //get request
     $postData = file_get_contents('php://input', true);
     $data = json_decode($postData, true);
     $mobile = $data['data']['phone'];
     Yii::getLogger()->log($data['data'], 2, "webhook");
     //send sms
     if ($mobile != null && $mobile != '') {
         $reminder = new Reminder();
         $createDate = time();
         $reminder->mobile = $mobile;
         $reminder->createDate = $createDate;
         $reminder->updated = false;
         $reminder->origin = 'webhook';
         $reminder->save();
         $rid = $reminder->_id . '';
         $reminder->url = $this->replaceHttp(Yii::$app->request->hostInfo) . "/user/reset_password/" . $rid;
         Yii::getLogger()->log($reminder->url, 2, "webhookUrl");
         $reminder->save();
         $name = null;
         $qry = new Query();
         $qry->from('reward');
         $list = $qry->all();
         if ($list != null && count($list) > 0) {
             $name = $list[0]['name'];
         }
         if ($name == null) {
             $name = "\$25聖安娜蛋糕禮券";
         }
         $content = "恭喜您參加家樂牌「儲分有賞」活動。您的帳戶已建立,立即按連結重設密碼並登入,即可查詢分數並有機會獲得" . $name . "!\n" . $reminder->url;
         Yii::getLogger()->log($content, 2, "content");
         Yii::$app->sms->sendSms($reminder->mobile, $content);
     }
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function get()
 {
     $query = new Query();
     $rows = $query->from($this->collection)->all();
     $values = [];
     foreach ($rows as $row) {
         $values[$row['id']] = $row['value'];
     }
     return $values;
 }
Exemplo n.º 7
0
 public static function findList($currentPage = 1, $pageSize = 10, $condition = [])
 {
     $offset = ($currentPage - 1) * $pageSize;
     $query = new Query();
     $users = $query->from('uhkklpActivityUser')->select(['_id', 'deviceId', 'prizeContent', 'mobile', 'createdAt'])->where($condition)->orderBy(['createdAt' => SORT_DESC])->offset($offset)->limit($pageSize)->all();
     for ($i = 0; $i < count($users); $i++) {
         $users[$i]['createdAt'] = MongodbUtil::MongoDate2String($users[$i]['createdAt'], 'Y-m-d H:i:s', null);
     }
     return $users;
 }
 public function testQuery()
 {
     $query = new Query();
     $query->from('customer');
     $provider = new ActiveDataProvider(['query' => $query, 'db' => $this->getConnection()]);
     $models = $provider->getModels();
     $this->assertEquals(10, count($models));
     $provider = new ActiveDataProvider(['query' => $query, 'db' => $this->getConnection(), 'pagination' => ['pageSize' => 5]]);
     $models = $provider->getModels();
     $this->assertEquals(5, count($models));
 }
Exemplo n.º 9
0
 public static function findList($currentPage = 1, $pageSize = 10, $condition = [])
 {
     $offset = ($currentPage - 1) * $pageSize;
     $query = new Query();
     $records = $query->from('uhkklpLuckyDrawRecord')->select(['_id', 'createdAt', 'remark'])->where($condition)->orderBy(['createdAt' => SORT_DESC])->offset($offset)->limit($pageSize)->all();
     for ($i = 0; $i < count($records); $i++) {
         $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null);
         $records[$i]['_id'] = (string) $records[$i]['_id'];
     }
     return $records;
 }
Exemplo n.º 10
0
 public function testFrom()
 {
     $query = new Query();
     $from = 'customer';
     $query->from($from);
     $this->assertEquals($from, $query->from);
     $query = new Query();
     $from = ['', 'customer'];
     $query->from($from);
     $this->assertEquals($from, $query->from);
 }
Exemplo n.º 11
0
 public function perform()
 {
     $args = $this->args;
     if (empty($args['key']) || empty($args['header']) || empty($args['accountId'])) {
         ResqueUtil::log(['status' => 'fail to export goods record', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     $keyword = $args['keyword'];
     $header = $args['header'];
     $fileName = $args['key'];
     $accountId = unserialize($args['accountId']);
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $query = new Query();
     if ($keyword == '') {
         $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->all();
     } else {
         $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->all();
     }
     for ($i = 0; $i < count($records); $i++) {
         $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null);
         $records[$i]['_id'] = (string) $records[$i]['_id'];
         $pro = "";
         for ($j = 0; $j < count($records[$i]['product']); $j++) {
             $pro .= "  " . $records[$i]['product'][$j];
         }
         $records[$i]['product'] = $pro;
     }
     $rows = $records;
     ExcelUtil::exportCsv($header, $rows, $filePath, 1);
     $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName);
     if ($hashKey) {
         //notice frontend the job is finished
         Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL]);
         return true;
     } else {
         ResqueUtil::log(['status' => 'fail to export order', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]);
         return false;
     }
 }
Exemplo n.º 12
0
 public static function getSampleRecordExcelDate($cookbookId, $accountId)
 {
     $query = new Query();
     $query->from('uhkklpSamplerecord')->select(['mobile', 'cookbookTitle', 'sampleId', 'sampleName', 'username', 'city', 'address', 'createdDate', 'quantity', 'sent'])->where(['cookbookId' => $cookbookId])->andWhere(['accountId' => $accountId]);
     $list = $query->all();
     $rows = [];
     for ($i = 0; $i < count($list); $i++) {
         $row = ['mobile' => $list[$i]['mobile'], 'sampleName' => $list[$i]['sampleName'], 'username' => $list[$i]['username'], 'city' => $list[$i]['city'], 'address' => $list[$i]['address'], 'quantity' => $list[$i]['quantity']];
         $rows[] = $row;
         unset($row);
     }
     return $rows;
 }
 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.º 14
0
 public static function getResults($messageId)
 {
     $query1 = new Query();
     $data = $query1->from(self::collectionName())->select(['messageId', 'results'])->where(['messageId' => $messageId])->all();
     if (empty($data)) {
         return [];
     }
     $data = $data[0];
     $query2 = new Query();
     $messageContent = $query2->from(Message::collectionName())->select(['content'])->where(['_id' => new \MongoId($messageId)])->all()[0]['content'];
     $results = [];
     foreach ($data['results'] as $key => $value) {
         if (empty($value['mobile'])) {
             $value['mobile'] = '';
         }
         if ($value['type'] == 'iOS') {
             if (empty($value['res']) || $value['res'] != 200) {
                 $value['res'] = '失敗';
             } else {
                 $value['res'] = '成功';
             }
         } else {
             if (!empty($value['res'])) {
                 $jsonObj = json_decode($value['res']);
                 if ($jsonObj->success != null && $jsonObj->success > 0) {
                     $value['res'] = '成功';
                 } else {
                     $value['res'] = '失敗';
                 }
             }
         }
         // $query3 = new Query();
         // $mobile = $query3->from(PushUser::collectionName())
         //     ->select(['mobile'])
         //     ->where(['token' => $value['token']])
         //     ->all();
         // if (empty($mobile)) {
         //     $mobile = '';
         // } else {
         //     $mobile = $mobile[0]['mobile'];
         // }
         $results[] = ['messageId' => $messageId, 'messageContent' => $messageContent, 'mobile' => $value['mobile'] . ' ', 'deviceType' => $value['type'], 'deviceId' => $value['token'], 'result' => $value['res']];
     }
     return $results;
 }
Exemplo n.º 15
0
 public static function getList($currentPage = 1, $pageSize = 10, $sort = [], $condition = [])
 {
     if (empty($sort)) {
         $sort = ['_id' => SORT_DESC];
     } else {
         foreach ($sort as $key => $value) {
             if ($value) {
                 $sort = [$key => SORT_DESC];
             } else {
                 $sort = [$key => SORT_ASC];
             }
         }
     }
     $offset = ($currentPage - 1) * $pageSize;
     $query = new Query();
     $datas = $query->from(self::collectionName())->select(self::attributes())->where(['accountId' => Token::getAccountId()])->andWhere($condition)->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     return $datas;
 }
Exemplo n.º 16
0
 public function getList($currentPage = 1, $pageSize = 10, $sort, $condition = [])
 {
     if (empty($sort)) {
         $sort = ['_id' => SORT_DESC];
     } else {
         foreach ($sort as $key => $value) {
             if ($value) {
                 $sort = [$key => SORT_DESC];
             } else {
                 $sort = [$key => SORT_ASC];
             }
         }
     }
     $offset = ($currentPage - 1) * $pageSize;
     $condition['isDeleted'] = false;
     $query = new Query();
     $datas = $query->from(self::collectionName())->select($this->attributes())->where($condition)->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     return $datas;
 }
Exemplo n.º 17
0
 public function testLike()
 {
     $connection = $this->getConnection();
     $query = new Query();
     $rows = $query->from('customer')->where(['LIKE', 'name', '/me1/'])->all($connection);
     $this->assertEquals(2, count($rows));
     $this->assertEquals('name1', $rows[0]['name']);
     $this->assertEquals('name10', $rows[1]['name']);
 }
Exemplo n.º 18
0
 public function actionLogin()
 {
     $mobile = Yii::$app->request->post("mobile");
     $password = Yii::$app->request->post("password");
     if ($mobile != null && $password != null) {
         $url = QUN_CRM_API . '/members/' . $mobile . '?access_token=' . QUN_CRM_ACCESS_TOKEN;
         $response = Yii::$app->curl->get($url);
         $member = json_decode($response, true);
         if (isset($member["custom_properties"])) {
             $properties = $member["custom_properties"];
             $i = 0;
             $firstChoiceDealer = null;
             $passwordNotFound = true;
             for (; $i < count($properties); $i++) {
                 $property = $properties[$i];
                 //property_id value
                 if (isset($property["property_id"]) && isset($property["value"]) && $property["property_id"] == "firstChoiceDealer") {
                     $firstChoiceDealer = $property["value"];
                 }
                 if (isset($property["property_id"]) && isset($property["value"]) && $property["property_id"] == "pwd") {
                     $passwordNotFound = false;
                     if ($property["value"] == $password) {
                         // tag app user
                         $origin = Yii::$app->request->post("origin");
                         if (!empty($origin) && ($origin == 'app:android' || $origin == 'app:ios')) {
                             $url = QUN_CRM_API . '/members/tags?access_token=' . QUN_CRM_ACCESS_TOKEN;
                             $body = ['member_ids' => [$member['id']], 'tags' => [TAG_APP_USER]];
                             $tagResp = Yii::$app->curl->postJson($url, json_encode($body));
                         }
                         // operations
                         $url = QUN_CRM_API . '/members/' . $mobile . '/operations?access_token=' . QUN_CRM_ACCESS_TOKEN;
                         $body = ['operation' => 'login'];
                         Yii::$app->curl->postJson($url, json_encode($body));
                         // update loginAt
                         $this->update(['phone' => $mobile, 'id' => $member['id'], 'custom_properties' => [['property_id' => 'loginAt', 'value' => date('c')]]]);
                     } else {
                         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
                         return ['code' => 405];
                     }
                 }
             }
             if ($passwordNotFound) {
                 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
                 return ['code' => 405];
             }
             //get voucher by mobile
             $voucher = null;
             $query = new Query();
             $query->from('voucher')->where(['mobile' => $mobile]);
             $list = $query->all();
             //if voucher is existent
             if ($list != null && count($list) > 0 && $firstChoiceDealer == null) {
                 $voucher = $list[0];
                 //answerd is false
                 if (!$voucher['answered']) {
                     $voucherId = $voucher['_id'];
                     $member['voucherId'] = $voucherId;
                 }
             } else {
                 //create voucher
                 $voucher = new Voucher();
                 $voucher->mobile = $mobile;
                 $voucher->createdDate = time();
                 $voucher->voucherGuid = null;
                 $voucher->voucherNo = null;
                 $voucher->answered = false;
                 $voucher->finished = false;
                 $voucher->requestGuid = $this->getGUID();
                 //if he has answered the questions.
                 if ($firstChoiceDealer != null) {
                     $voucher->answered = true;
                     $voucher->save();
                 } else {
                     $voucher->save();
                     $member['voucherId'] = $voucher->_id;
                 }
             }
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return $member;
         }
     }
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 406];
 }
Exemplo n.º 19
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;
 }
Exemplo n.º 20
0
 public static function pushMessage($messageId, $time)
 {
     $time = (int) $time;
     $logFileName = 'pushmessage';
     $logMsg = 'Message (' . $messageId . ') started to push at ' . date('Y-m-d H:i:s', time());
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $queryMessage = new Query();
     $logMsg = '---Find message by id...';
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $message = $queryMessage->from('uhkklpMessage')->select(['content', 'linkType', 'newsId', 'pushTime'])->where(['_id' => new \MongoId($messageId)])->all();
     if (empty($message)) {
         $logMsg = 'Push canseled, message was deleted in database';
         LogUtil::error('uhkklp-push-message:  ' . $logMsg);
         return;
     }
     $message = $message[0];
     if ($message['pushTime']->sec != $time) {
         $logMsg = 'Push canseled, pushTime was changed in database';
         LogUtil::error('uhkklp-push-message:  ' . $logMsg);
         return;
     }
     $logMsg = '---done';
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $logMsg = '---Find tokens...';
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $queryUser = new Query();
     $users = $queryUser->from('uhkklpPushMessage')->select(['mobile', 'token', 'deviceType', 'accountId'])->where(['messageId' => new \MongoId($messageId)])->all();
     $logMsg = '---done';
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $gcmUtil = new GCMUtil();
     $apmUtil = new APMUtil();
     $logMsg = '---Pushing...';
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $msg['content'] = $message['content'];
     $msg['linkType'] = $message['linkType'];
     $msg['newsId'] = $message['newsId'];
     $log = new PushMessageLog();
     $log->messageId = $messageId;
     $log->startTime = date('Y-m-d H:i:s', time());
     $log->save();
     $results = [];
     foreach ($users as $user) {
         if ($user['deviceType'] == PushUser::DEVICE_ANDROID) {
             $response = $gcmUtil->pushMessageByToken($user['token'], $msg, $user['accountId']);
             LogUtil::error('GCMUtil:  ' . $user['token'] . '  ' . $response);
         } else {
             $response = $apmUtil->pushMsg($user['token'], $msg, $user['accountId']);
             LogUtil::error('APMUtil:  ' . $user['token'] . '  ' . $response);
         }
         $result['type'] = $user['deviceType'];
         $result['token'] = $user['token'];
         if (!empty($user['mobile'])) {
             $result['mobile'] = $user['mobile'];
         }
         $result['res'] = $response;
         $results[] = $result;
         $log->results = $results;
         $log->save();
         unset($result);
     }
     $apmUtil->closeFp();
     $logMsg = 'Push finished at ' . date('Y-m-d H:i:s', time());
     LogUtil::error('uhkklp-push-message:  ' . $logMsg);
     $log->endTime = date('Y-m-d H:i:s', time());
     $log->accountId = $user['accountId'];
     $log->save();
     $uhkklpMessage = Message::findOne([$messageId]);
     $uhkklpMessage->isPushed = true;
     $uhkklpMessage->update();
     return $results;
 }
Exemplo n.º 21
0
 /**
  * @see https://github.com/yiisoft/yii2/issues/7010
  */
 public function testSelect()
 {
     $connection = $this->getConnection();
     $query = new Query();
     $rows = $query->from('customer')->select(['name' => true, '_id' => false])->limit(1)->all($connection);
     $row = array_pop($rows);
     $this->assertArrayHasKey('name', $row);
     $this->assertArrayNotHasKey('address', $row);
     $this->assertArrayNotHasKey('_id', $row);
 }
Exemplo n.º 22
0
 public function actionShowAnsweredTwo()
 {
     $query = new Query();
     $query->from('popular_voter')->where(['sample' => ['$ne' => null], 'hasPrize' => ['$ne' => 1]]);
     //第二批已答题人数
     $list = $query->all();
     $answeredTwo = count($list);
     $query->from('popular_voter')->where(['hasPrize' => ['$ne' => 1]]);
     $list = $query->all();
     $userAllTwo = count($list);
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['answeredTwo' => $answeredTwo, 'userAllTwo' => $userAllTwo];
 }
 public static function findByAttributes(array $attributes)
 {
     $query = new Query();
     $class_name = get_called_class();
     $instance = new $class_name();
     $table_name = $instance->getTableName();
     if ($result = $query->from($table_name)->where($attributes)->one()) {
         $obj = new $class_name($result);
         return $obj;
     }
     return false;
 }
Exemplo n.º 24
0
 /**
  * @return array applied migration entries
  */
 protected function getMigrationHistory()
 {
     $query = new Query();
     return $query->from('migration')->all();
 }
Exemplo n.º 25
0
 /**
  * @see https://github.com/yiisoft/yii2/issues/4879
  *
  * @depends testInCondition
  */
 public function testInConditionIgnoreKeys()
 {
     $connection = $this->getConnection();
     $query = new Query();
     $rows = $query->from('customer')->where(['in', 'name', [10 => 'name1', 15 => 'name5']])->all($connection);
     $this->assertEquals(2, count($rows));
     $this->assertEquals('name1', $rows[0]['name']);
     $this->assertEquals('name5', $rows[1]['name']);
 }
Exemplo n.º 26
0
 public function getItem($condition = [])
 {
     $query = new Query();
     $data = $query->from(self::collectionName())->select($this->attributes())->where($condition)->one();
     return $data;
 }
Exemplo n.º 27
0
 public function actionGetResultList()
 {
     $currentPage = Yii::$app->request->get("currentPage", 1);
     $pageSize = Yii::$app->request->get("pageSize", 10);
     $offset = ($currentPage - 1) * $pageSize;
     $sortName = "_id";
     $sortDesc = Yii::$app->request->get('sortDesc', 'ASC');
     $sort = $sortName . ' ' . $sortDesc;
     $query = new Query();
     $records = $query->from('uhkklpSmsRecordModel')->select(['_id', 'modelContent', 'createdAt', 'totalRecord', 'successRecord', 'failureRecord'])->where(['accountId' => (string) $this->getAccountId()])->orderBy($sort)->offset($offset)->limit($pageSize)->all();
     for ($i = 0; $i < count($records); $i++) {
         $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null);
         $records[$i]['_id'] = (string) $records[$i]['_id'];
     }
     $totalPageCount = $query->from('uhkklpSmsRecordModel')->where(['accountId' => (string) $this->getAccountId()])->count();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'list' => $records, 'totalPageCount' => $totalPageCount];
 }
Exemplo n.º 28
0
 private function checkExist($accountId, $name)
 {
     $queryCookingtype = new Query();
     $queryCookingtype->from('uhkklpCookingtype')->where(['accountId' => $accountId]);
     $cookingTypes = $queryCookingtype->all();
     for ($i = 0; $i < count($cookingTypes); $i++) {
         if ($cookingTypes[$i]['name'] == $name) {
             break;
         }
     }
     if ($i >= count($cookingTypes)) {
         return true;
     }
     return false;
 }
Exemplo n.º 29
0
 public function actionGetTags()
 {
     $accountId = $this->getAccountId();
     $query = new Query();
     $query->from('uhkklpCookingtype')->where(['isDeleted' => false])->andWhere(['accountId' => $accountId]);
     $list = $query->all();
     $tags = [];
     for ($i = 0; $i < count($list); $i++) {
         if ($list[$i]['category'] == '大類') {
             for ($j = 0; $j < count($tags); $j++) {
                 if ($tags[$j]['name'] == $list[$i]['name']) {
                     if (isset($list[$i]['radio'])) {
                         if ($list[$i]['radio'] == 'true') {
                             $tags[$j]['isRadio'] = 'Y';
                         } else {
                             $tags[$j]['isRadio'] = 'N';
                         }
                     } else {
                         $tags[$j]['isRadio'] = 'Y';
                     }
                     break;
                 }
             }
             if ($j >= count($tags)) {
                 $tag = [];
                 $tag['name'] = $list[$i]['name'];
                 $tag['items'] = [];
                 if (isset($list[$i]['radio'])) {
                     if ($list[$i]['radio'] == 'true') {
                         $tag['isRadio'] = 'Y';
                     } else {
                         $tag['isRadio'] = 'N';
                     }
                 } else {
                     $tag['isRadio'] = 'Y';
                 }
                 array_push($tags, $tag);
             }
         }
         if ($list[$i]['category'] != '大類' && $list[$i]['category'] != '固定分類') {
             for ($j = 0; $j < count($tags); $j++) {
                 if ($tags[$j]['name'] == $list[$i]['category']) {
                     array_push($tags[$j]['items'], $list[$i]['name']);
                     break;
                 }
             }
             if ($j >= count($tags)) {
                 $tag = [];
                 $tag['name'] = $list[$i]['category'];
                 $tag['items'] = [];
                 array_push($tag['items'], $list[$i]['name']);
                 $tag['isRadio'] = 'Y';
                 array_push($tags, $tag);
             }
         }
     }
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $tags];
 }
Exemplo n.º 30
0
 public function actionListAll()
 {
     $accountId = $this->getAccountId();
     $query = new Query();
     $query->from('uhkklpSample')->where(['isDeleted' => false])->andWhere(['accountId' => $accountId])->orderBy('createdAt DESC');
     $list = $query->all();
     $list = $this->formatSampleList($list);
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $list];
 }