all() public method

Executes the query and returns all results as an array.
public all ( Connection $db = null ) : array
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
return array the query results. If the query results in nothing, an empty array will be returned.
Exemplo n.º 1
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.º 2
0
 public function actionIndex()
 {
     $query = new Query();
     $query->select(["username", "password"])->from("admin_user");
     $re = $query->all();
     //print_r($re);die;
     return $this->renderPartial('index', ["data" => $re]);
 }
Exemplo n.º 3
0
 public function actionCheck_login()
 {
     $username = $_POST['username'];
     $pwd = $_POST['pwd'];
     $query = new Query();
     $query->select(['name', 'status', 'password'])->from('admin')->where(['name' => $username]);
     $arr = $query->one();
     if ($arr) {
         if ($arr['password'] == md5($pwd)) {
             $_SESSION['user_id'] = $arr['_id'];
             $_SESSION['user_name'] = $arr['name'];
             if ($arr['name'] != "admin") {
                 $userid = $arr['_id'];
                 //根据用户id查找用户的角色ID
                 $query->select(['role_id'])->from('user_role')->where(['user_id' => "{$userid}"]);
                 $res = $query->one();
                 $role_id = $res['role_id'];
                 //根据角色ID查询所有权限ID,将其ID存入字符串中
                 $q = new Query();
                 $q->select(['node_id'])->from('role_node')->where(['role_id' => $role_id]);
                 $ar = $q->all();
                 $que = new Query();
                 foreach ($ar as $key => $v) {
                     // $node[$key] = $v['node_id'];
                     $idd = $v['node_id'];
                     $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$idd}"])->andwhere(['n_level' => "1"]);
                     $quan[$key] = $que->all();
                 }
                 $yi_quan = array_filter($quan);
                 $_SESSION['yi_quan'] = $yi_quan;
                 $quee = new Query();
                 foreach ($ar as $kk => $vv) {
                     // $node[$key] = $v['node_id'];
                     $iddd = $vv['node_id'];
                     $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$iddd}"])->andwhere(['n_level' => "2"]);
                     $quanx[$kk] = $quee->all();
                 }
                 $er_quan = array_filter($quanx);
                 $_SESSION['er_quan'] = $er_quan;
             } else {
                 $que = new Query();
                 $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "1"]);
                 $yi_quan = $que->all();
                 $_SESSION['yi_q'] = $yi_quan;
                 $quee = new Query();
                 $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "2"]);
                 $er_quan = $quee->all();
                 $_SESSION['er_q'] = $er_quan;
             }
             echo "<script>location.href='index.php?r=site/index'</script>";
         } else {
             echo "<script>alert('密码错误');location.href='index.php?r=public/login'</script>";
         }
     } else {
         echo "<script>alert('用户名或密码错误');location.href='index.php?r=public/login'</script>";
     }
 }
Exemplo n.º 4
0
 static function GetForms()
 {
     $query = new Query();
     // compose the query
     $query->select([])->from('forms');
     // execute the query
     $rows = $query->all();
     return $rows;
 }
Exemplo n.º 5
0
 public function actionEdit()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['_id' => $id]);
     $data['rows'] = $query->one();
     $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['p_id' => '0']);
     $data['arr'] = $query->all();
     return $this->renderPartial("edit", $data);
 }
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function getHistory($chatId, $limit = 10)
 {
     $query = new Query();
     $query->select(['user_id', 'username', 'message', 'timestamp', 'avatar_16', 'avatar_32'])->from(self::collectionName())->where(['chat_id' => $chatId]);
     $query->orderBy(['timestamp' => SORT_DESC]);
     if ($limit) {
         $query->limit($limit);
     }
     return $query->all();
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $dsn = "mongodb://192.168.1.164";
     $connection = new \yii\mongodb\Connection(['dsn' => $dsn]);
     $connection->open();
     //var_dump($connection);die;
     $database = $connection->getDatabase('niuke');
     /*
     		$collection = $database->getCollection('user');
     		//var_dump($collection);die;	
     */
     $query = new Query();
     // compose the query
     $query->select(['niukename', 'password'])->from('user')->limit(10);
     // execute the query
     $rows = $query->all();
     var_dump($rows);
     /*
             //return $this->render('index');*/
 }
Exemplo n.º 9
0
 public function actionCheck_login()
 {
     //print_r($_POST);
     $username = $_POST['username'];
     $arr = array('username' => $username);
     $query = new Query();
     $query->select(['username', 'password'])->from('admin_user')->where($arr);
     $rows = $query->all();
     //echo $rows[0]['password'];die;
     if ($rows) {
         if ($rows[0]['password'] == md5($_POST['password'])) {
             $_SESSION['user_info'] = $username;
             echo $this->success("登陆成功", "index.php?r=index/index", '1');
         } else {
             echo $this->error("密码错误,登陆失败", "index.php?r=public/login", '1');
         }
     } else {
         echo $this->error("账号错误,登陆失败", "index.php?r=public/login", '1');
     }
 }
Exemplo n.º 10
0
 public function actionHuaner()
 {
     $pid = $_GET['pid'];
     if ($pid == 0) {
         echo 0;
         exit;
     }
     $query = new Query();
     $query->select(['_id', 'nickname', 'n_level'])->from('node')->where(['p_id' => $pid]);
     $rows = $query->all();
     if (empty($rows)) {
         echo 1;
         exit;
     } else {
         echo json_encode($rows);
     }
     // return $rows;
 }
Exemplo n.º 11
0
 /**
  * Executes query and returns all results as an array.
  * @param Connection $db the Mongo connection used to execute the query.
  * If null, the Mongo connection returned by [[modelClass]] will be used.
  * @return array|ActiveRecord the query results. If the query results in nothing, an empty array will be returned.
  */
 public function all($db = null)
 {
     return parent::all($db);
 }
Exemplo n.º 12
0
 public function actionFen_role()
 {
     $user = $_GET['id'];
     $query = new Query();
     $query->select(['r_name'])->from('role')->where(['r_status' => 1, 'r_status' => '1']);
     $rows = $query->all();
     return $this->renderPartial('fen_role', ['user' => $user, 'rows' => $rows]);
 }
Exemplo n.º 13
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.º 14
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];
 }
Exemplo n.º 15
0
 public function actionHuan()
 {
     $id = $_GET['id'];
     if ($id == 1) {
         return 0;
         exit;
         //不查数据
     }
     $dd = $id - 1;
     $query = new Query();
     $query->select(['nickname'])->from('node')->where(['n_level' => "{$dd}"]);
     $rows = $query->all();
     //var_dump($rows);
     echo json_encode($rows);
 }
Exemplo n.º 16
0
 public function actionSec_save()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['z_name', 'z_introduce', 'parent_id', 'z_content', 'practice_type'])->from('chapter_class')->where(["_id" => $id]);
     $rows = $query->one();
     $que = new Query();
     $que->select(['cha_name', 'lecturer'])->from('goods_class');
     $data = $que->all();
     return $this->renderPartial("sec_save", ['rows' => $rows, 'data' => $data]);
 }
Exemplo n.º 17
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.º 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
 public function actionGetOneCookbookById()
 {
     $accountId = $this->getAccountId();
     $cookbookId = $request = Yii::$app->request->get("cookbookId", "");
     $mobile = Yii::$app->request->get('mobile', null);
     $query = new Query();
     $query->from('uhkklpCookbook')->select(['_id', 'title', 'image', 'content', 'ingredient', 'startDate', 'endDate', 'shareUrl', 'isSampleOpen', 'sample', 'active', 'createdDate', 'updatedDate', 'operator', 'type', 'video', 'restaurantName', 'cookName', 'category', 'subCategory', 'portionSize', 'preparationMethod', 'yield', 'creativeExperience', 'deliciousSecret', 'cuisineType', 'averageScore'])->where(['_id' => $cookbookId]);
     $cookbook = $query->one();
     if ($cookbook == false) {
         return ['code' => 1204, 'msg' => 'cookbook not found.'];
     }
     $cookbook = $this->formatCookbook($cookbook);
     $cookbook = $this->formatCookbookForAPI($cookbook);
     if ($mobile != null && strlen($mobile) != 0) {
         //collection and score
         $query = new Query();
         $query->from('uhkklpUserCookbook')->where(['mobile' => $mobile, 'isDeleted' => false, 'accountId' => $accountId]);
         $userCookbook = $query->all();
         $cookbook['collection'] = 'N';
         $cookbook['score'] = 0;
         for ($j = 0; $j < count($userCookbook); $j++) {
             if ($userCookbook[$j]['cookbookId'] == $cookbook['cookbookId']) {
                 if (!isset($userCookbook[$j]['collection'])) {
                     $userCookbook[$j]['collection'] = 'N';
                 } else {
                     if ($userCookbook[$j]['collection'] != 'N') {
                         $userCookbook[$j]['collection'] = 'Y';
                     }
                 }
                 if (!isset($userCookbook[$j]['score'])) {
                     $userCookbook[$j]['score'] = 0;
                 }
                 $cookbook['collection'] = $userCookbook[$j]['collection'];
                 $cookbook['score'] = $userCookbook[$j]['score'];
                 break;
             }
         }
         //samplerecord
         $query = new Query();
         $query->from('uhkklpSamplerecord')->where(['mobile' => $mobile, 'isDeleted' => false, 'accountId' => $accountId]);
         $record = $query->all();
         $sample = $cookbook['sample'];
         for ($j = 0; $j < count($sample); $j++) {
             for ($k = 0; $k < count($record); $k++) {
                 if ($record[$k]['sampleId'] == $sample[$j]['id']) {
                     $sample[$j]['getSampled'] = 'Y';
                     break;
                 }
             }
             if ($k >= count($record)) {
                 $sample[$j]['getSampled'] = 'N';
             }
         }
         $cookbook['sample'] = $sample;
     }
     $result['cookbook'] = $cookbook;
     LogUtil::info('GetOneCookbookById' . ' mobile:' . $mobile, 'cookbook-log');
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $result];
 }
Exemplo n.º 20
0
 public function actionJob()
 {
     $query = new Query();
     $query->select(['j_name', 'add_time'])->from('work_direction');
     $rows = $query->all();
     return $this->renderPartial('job', compact('rows'));
 }
Exemplo n.º 21
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];
 }