PHP查询统计年月日流水的具体方法tp6和原生SQL

话不多说 直接上代码:

	public function test()
    {
   
        $count = 30;
        for ($i = 1; $i <= $count; $i++) {
   
            $time = time();
            $arr = ["uid" => 11, "number" => $i, "mark" => '测试30天数据', 'add_time' => $time];
            //将测试数据 push到列表中
            $user = new UserBill();
            $data = $user->create($arr);
        }
        print_r($data);
    }

    /**
     * 财报明细
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function ResultsAnalysis()
    {
   
        $param = input();
        if (empty($param['uid'])) {
   
            return app('json')->success('用户id不能为空');
        }
            $type = $param['type'] ?? 'week';//默认这周
            $pm = $param['pm'] ?? 1;//默认为总支出 1 2为总收入
            $where = ['pm' => $pm, 'uid' => $param['uid']];
            switch ($type) {
   
                case 'week':
                    $lst = $this->week($param,$pm,$where);
                    break;
                case 'month'://本月
                    $lst = $this->month($param,$pm,$where);
                    break;
                case 'year'://今年
                    $lst = $this->year($param,$pm,$where);
                    break;
                default:
                    return app('json')->success('参数有误');
            }
        return app('json')->success($lst);

    }

    /**
     * 周
     * @param $param
     * @param $pm
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author fyk
     */
    public function week($param, $pm, $where): array
    {
   
        $ret = placeOrder::lowerGetOrder('week'.$param['uid'].$pm);
        if($ret){
   
            return json_decode($ret,true);
        }else
            $weekArray = array(['7'], ['1'], ['2'], ['3'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值