关联表查询及加 ""

 //*** 用于推广统计查询-start* @param int $page* @param int $pageSize* @param array $args * @return array */
    public static function queryList($page, $pageSize, $args = array()) {
        $condition ='1=1';
        $params = array(); 
        //查询条件
        //加入expand 
        if ($args['expand'] != '') {
            $condition.=' AND user_expand.expand=:expand';
            $params['expand'] =$args['expand'];
        }
        //加入开始datetime
        if ($args['dttm_start'] != '') {
            $condition.=' AND user_expand.datetime>=:dttm_start';
            $params['dttm_start'] = $args['dttm_start'] . " 00:00:00";
        }
        //加入结束datetime
        if ($args['dttm_end'] != '') {
            $condition.=' AND user_expand.datetime<=:dttm_end';
            $params['dttm_end'] = $args['dttm_end'] . " 23:59:59";
        }
        //用户status
           $args['status']=0;
      //  if ($args['status'] != '') {
            $condition.=' AND user.status=:status';
            $params['status'] = $args['status'];  
        //服务号 订阅号          
         if($args['q_by']!=""){
                $condition .= " AND user.appid ='".$args['q_by']."'" ;
             }      
//        print_r($condition);
        if ($_REQUEST['q_order'] == '') {
            $order = 'user_expand.datetime DESC';
        } else {
            if (substr($_REQUEST['q_order'], -1) == '~')
                $order = substr($_REQUEST['q_order'], 0, -1) . ' DESC';
            else
                $order = $_REQUEST['q_order'] . ' ASC';
        }
        
        //计算记录数目  -先生成一个字表 ,在查询
        $text= Yii::app()->db->createCommand()
        ->select("user_expand.expand")
        ->from("user_expand")
        ->leftJoin('user', 'user.openid=user_expand.openid')
        ->where($condition, $params)
        ->group("user_expand.expand")
        ->text;
       
        $total_num = Yii::app()->db->createCommand()
        ->select("count(1) cnt ")
        ->from("( $text ) t")
        ->where("", $params)
        ->queryRow();
        $total_num = $total_num["cnt"];
        
       // 查询所有记录
        $rows = Yii::app()->db->createCommand()
        ->select(" user_expand.expand,count(1) c ")
        ->from("user_expand")
        ->leftJoin('user', 'user.openid=user_expand.openid')
        ->where($condition, $params)
        ->order($order)
        ->limit($pageSize)
        ->offset($page * $pageSize)
        ->group("user_expand.expand")
        ->queryAll();
        $rs['status'] = 0;
        $rs['desc'] = '成功';
        $rs['page_num'] = ($page + 1);
        $rs['total_num'] = $total_num;
        $rs['num_of_page'] = $pageSize;
        $rs['rows'] = $rows; 
        return $rs; 
 
    } // 用于推广统计查询-end  //
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值