字符串查询,包含了union ,虚拟字段,

这里写代码片
public function actionStatus1()
    {
        $user_id = Yii::$app->user->id;

        $query1 = (new \yii\db\Query())
            ->select('expense_type as name,description as text,status as status_text,id,created_at,(1) as type')
            ->from('tbl_expense_ask ')
            ->where(['fault_user_id'=>$user_id]);

        $query2 = (new \yii\db\Query())
            ->select(new Expression('type_status as name,text,status as status_text,id,created_at,(2) as type'))
            ->from('tbl_task_ask_v3')
            ->where(['fault_user_id'=>$user_id]);
        
        $query1->union($query2,'all');

        $totalCount = $query1->count();
        $pages = new Pagination(['totalCount' =>$totalCount, 'pageSize' => '50']);
        $query = $query1->offset($pages->offset)->limit($pages->limit)->all();
     
        return [
            'items'=>$query,
            '_meta'=>[
                'totalCount'=>$totalCount,
                'pageCount'=>$pages->getPageCount(),
                'currentPage'=>$pages->getPage()+1,
                'perPage'=>$pages->getPageSize(),
            ]
        ];
  }

你可能感兴趣的:(数据的操作)