tp5.1查询whereRaw 和 query使用

whereRwa

  $where = '';
        $value = [];

        if ($senduid) {
            if ($senduid == '全部用户') {
                $u_id = 0;
            } else {
                $u_id = DB::name('Member')->where('nickname', $senduid)->value('id');
            }
            $where .= ' AND senduid = :senduid';
            $value['senduid'] = $u_id;
        }

        if (!empty($m_status) && $m_status != 'none') {
            $where .= ' AND status = :status';
            $value['status'] = $m_status;
        }

        //得到limit参数
        $limit_start = $data['start'];
        $limit_length = $data['length'];

        $list = Db::name('messages')->whereRaw('msg_status = 2 AND status <> 2' . $where . '', $value)->limit($limit_start, $limit_length)->order('date', 'desc')->select();

        $total = Db::name('messages')->whereRaw('msg_status = 2 AND status <> 2' . $where . '', $value)->count();

query

//获取一个本周7天以内的资金走向表


 public function sevenpicture(Request $request)
    {


        $uid = input('uid');
        //佣金走势图
        $timestr = time();    //当前时间戳
        $now_day = date('w',$timestr);  //当前是周几

        //获取周一
        $monday_str = $timestr - ($now_day-1)*60*60*24;
        $monday = date('Y-m-d', $monday_str);

        //获取周日
        $sunday_str = $timestr + (7-$now_day)*60*60*24;
        $sunday = date('Y-m-d', $sunday_str);
        for($i=0;$i<7;$i++)
        {
            $arr[date('Y-m-d',strtotime($monday.'+'.$i.'day'))]=0;
        }

        $sql =
            "SELECT
        sum(`carprice`) as price,
        date_format(`createtime`,\"%Y-%m-%d\") as date 
    FROM
        `y_agent` 
    WHERE
        `caruid` = :uid
        AND date_format(`createtime`,\"%Y-%m-%d\") BETWEEN :s_time 
        AND :c_time 
    GROUP BY date";


        $re = Db::query($sql,['uid'=>$uid,'s_time'=>$monday,'c_time'=>$sunday]);
        foreach ($re as $k=>$v)
        {
            $dateinfo[$v['date']] =$v['price'];
        }


        $linepicture =array_merge($arr,$dateinfo);

        foreach ($linepicture as $key=>$value )
        {
            $line[] =[
                'time'=>$key,
                'tem'=>$value,
            ];
        }
        //`````````````````````
        if($line)
        {
            return json(['code'=>1,'data'=>$line,'msg'=>"获取数据成功"]);
        }else{
            return json(['code'=>2,'data'=>'','msg'=>"获取数据失败!"]);
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值