话不多说 直接上代码:
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'