Esempio n. 1
0
 public static function getSelectItem($id)
 {
     $select_ret = [];
     $selects = TbSelectItem::find()->where('fdSelectID = :id', [':id' => $id])->orderBy('fdOrder desc')->all();
     foreach ($selects as $select) {
         $select_ret[$select->fdKey] = $select->fdValue;
     }
     return $select_ret;
 }
Esempio n. 2
0
 private function generate_where_clause()
 {
     $where = $this->table->fdCondition > '' ? $this->table->fdCondition : "1 = 1";
     foreach ($this->search_columns as $search) {
         switch ($search->fdSearchType) {
             case 1:
                 //下拉选择
                 $value = 0;
                 if (\Yii::$app->request->post($search->fdName) > '') {
                     $value = \Yii::$app->request->post($search->fdName);
                 } else {
                     if ($search->fdSelectID > 0) {
                         $select_item = TbSelectItem::find()->where('fdSelectID = :select_id', [':select_id' => $search->fdSelectID])->orderBy('fdOrder desc')->one();
                         $value = $select_item->fdKey;
                     }
                 }
                 if (!is_integer($value)) {
                     $value = "'{$value}'";
                 }
                 $where = "{$where} and {$search->fdName} = {$value}";
                 break;
             case 2:
                 //搜索
                 if (\Yii::$app->request->post($search->fdName) > '') {
                     $value = \Yii::$app->request->post($search->fdName);
                     $where = "{$where} and {$search->fdName} like '%{$value}%'";
                 }
                 break;
             case 3:
             case 4:
                 //时间点
                 if (\Yii::$app->request->post($search->fdName) > '') {
                     $value = \Yii::$app->request->post($search->fdName);
                 } else {
                     if ($search->fdSearchType == 3) {
                         $value = date('Y-m-d');
                     } else {
                         $value = date('Y-m-d', strtotime('-1 days'));
                     }
                 }
                 $where = "{$where} and {$search->fdName} between '{$value} 00:00:00' and '{$value} 23:59:59'";
                 break;
             case 5:
             case 6:
             case 7:
             case 8:
             case 9:
                 //时间段
                 $end = date('Y-m-d 23:59:59');
                 if ($search->fdSearchType == 5) {
                     $begin = date('Y-m-d 00:00:00', strtotime('-1 days'));
                 } elseif ($search->fdSearchType == 6) {
                     $begin = date('Y-m-d 00:00:00', strtotime('-7 days'));
                 } elseif ($search->fdSearchType == 7) {
                     $begin = date('Y-m-d 00:00:00', strtotime('-30 days'));
                 } elseif ($search->fdSearchType == 8) {
                     $begin = date('Y-m-d 00:00:00', strtotime('-90 days'));
                 } else {
                     $begin = date('Y-m-d 00:00:00', strtotime('-180 days'));
                 }
                 if (\Yii::$app->request->post($search->fdName . "_begin") > '') {
                     $begin = \Yii::$app->request->post($search->fdName . "_begin") . ' 00:00:00';
                 }
                 if (\Yii::$app->request->post($search->fdName . "_end") > '') {
                     $end = \Yii::$app->request->post($search->fdName . "_end") . ' 23:59:59';
                 }
                 $where = "{$where} and {$search->fdName} between '{$begin}' and '{$end}'";
                 break;
             case 10:
                 //搜索地区
                 $where = "{$where} and {$search->fdName} = " . \Yii::$app->request->post('area_id', 0);
                 break;
             default:
                 break;
         }
     }
     return $where;
 }