接口按月 按日查询数据
环境php本地写接口
1.PHP工具箱配置好相应的本地域名
2.下载一个客户端postman
1.按日查询.接口传过来 $page $uid $time
/*
* 2019.10.15
*订单统计
* & 骑手的id
* orderstatistics 按日查询
* */
public function orderstatistics(){
$res = [];
$param = input('');
$page = input('page');
$uid = $param['uid'];//骑手的id
$time = $param['time'];//查询的时间
$data = $this-> order -> statistics($uid,$time,$page);//获取订单的列表
foreach ($data['data'] as $k=>&$v){
// status = 1:已接单 2:取货中 3:已取消 4:配送中 5:已完成 6:已评价',
switch ($v['status']){
case 1: $v['status_name'] = '已接单';break;
case 2: $v['status_name'] = '取货中';break;
case 3: $v['status_name'] = '已取消';break;
case 4: $v['status_name'] = '配送中';break;
case 5: $v['status_name'] = '已完成';break;
case 6: $v['status_name'] = '已评价';break;
}
$v['gettime'] = date('H:i',$v['gettime']);
}
//总收入 总的订单数
if(!empty($data['data'])){
$res['list'] = $data['data'];
}else{
$res['list'] = '暂无数据';
}
$res['money'] = $data['money'];
$res['count'] = $data['count'];
if($data !== false){
$res['code'] = 1;
$res['msg'] = '成功';
//return json(date('t',1571068800));
return json($res);
}else{
$res['code'] = 0;
$res['msg'] = '失败';
return json($res);
}
/* statistics
* 订单统计
* &uid 骑手的id
* 1.按日查询
* $time 查询的时间
* $param page 页数
*/
public function statistics($uid,$time,$page)
{
//1571068800 1571068800
$res = [];
$where =[];
$where['ho.hid'] = $uid;
$pageNum = 10; // 每页显示个数 10 个
$page = $page ? $page : 1; //默认当前页1
$limit = ($page - 1) * $pageNum;
if(empty($time)){//第一次进来没有时间的时候
//php获取今日开始时间戳和结束时间戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
$where['ho.jtime'] = [['gt',$beginToday],['lt',$endToday]];
}else{//操作本页面的时候 传过来时间的时候
$beginTime = strtotime($time);//传来的开始时间
$endTime = $beginTime + (24*60*60 - 1);//传来的结束时间
$where['ho.jtime'] = [['gt',$beginTime],['lt',$endTime]];
}
//gettime 预计送到时间
$data = db('horseman_order ho')
->join('merchants_food_order o','o.id=ho.oid','left')
->join('merchants m','m.id=o.mid')
->where($where)
-> limit($limit, $pageNum)
->field('ho.id,ho.oid,ho.address,ho.status,ho.earnings,m.name as mname,o.gettime')
->select();
$res['data'] = $data;
$count = db('horseman_order ho')->count();
$res['count'] = $count;
$money = db('horseman_order ho')
->where($where)
//总收益 status = 1:已接单 2:取货中 3:已取消 4:配送中 5:已完成 6:已评价',
->where('ho.status','in','5,6')
->sum('earnings');
$res['money'] = $money;
return $res;
}
2.按月查询.接口传过来 $page $uid
/*
* 2019.10.15
*订单统计
* & 骑手的id 按月查询
* */
public function monthstatistics(){
$param = input('');
$uid = $param['uid'];
$data = $this ->order ->monthstatistics($uid);
$res = [];
if($data){
$res['list'] = $data;
$res['code'] = 1;
$res['msg'] = '成功';
}else{
$res['list'] = '暂无数据';
$res['code'] = 0;
$res['msg'] = '失败';
}
return json($res);
}
/*
* monthstatistics
* uid 骑手的id
* */
public function monthstatistics($uid){
//骑手的注册时间
$ctime = db('horseman')->where('id',$uid)->value('ctime');
$start_m = date("Y-m-d",$ctime);
$end_m = date("Y-m-d",time());
$date1 = explode('-',$start_m);
$date2 = explode('-',$end_m);
if($date1[1]<$date2[1]){ //判断月份大小,进行相应加或减
$month_number= abs($date1[0] - $date2[0]) * 12 + abs($date1[1] - $date2[1]);
}else{
$month_number= abs($date1[0] - $date2[0]) * 12 - abs($date1[1] - $date2[1]);
}
//总的月份时间
$months = [];
for($i=0;$i<=$month_number;$i++)
{
$months[] .= date("Y-m", strtotime('-'. $i . 'months'));
}
//总收益 status = 1:已接单 2:取货中 3:已取消 4:配送中 5:已完成 6:已评价',
$money = [];
for($i=0;$i<=$month_number;$i++)
{
$money[] .= db('horseman_order')
->where(array('wtime'=>array(array('egt',strtotime(date("Y-m-01", strtotime(' -'. $i . 'month')))),array('elt',strtotime(date("Y-m-31", strtotime(' -'. $i . 'month')))))))
->where(['hid'=>$uid])
->where('status','in','5,6')
->sum('earnings');
}
$count = [];
for($i=0;$i<=$month_number;$i++)
{
$count[] .= db('horseman_order')
->where(array('wtime'=>array(array('egt',strtotime(date("Y-m-01", strtotime(' -'. $i . 'month')))),array('elt',strtotime(date("Y-m-31", strtotime(' -'. $i . 'month')))))))
->where(['hid'=>$uid])
->where('status','in','5,6')
->count();
}
$res = [];
foreach ($months as $k=>$v){
$res[$k]['time'] = $v;
$res[$k]['money'] = $money[$k];
$res[$k]['count'] = $count[$k];
}
return $res;
}
返回的值
1.按日返回值
{
"list": [ list 订单的列表
{
"id": 2, 骑手订单的 id
"oid": 162, 商品订单的id
"address": "山西省-朔州市", 送货的地址
"status": 5, 状态值 1:已接单 2:取货中 3:已取消 4:配送中 5:已完成 6:已评价
"earnings": "5.10", 订单收益
"mname": "FPS店", 店铺名称
"gettime": "08:00", 期望/预计送达
"status_name": "已完成" 状态值的名称
},
{
"id": 3,
"oid": 230,
"address": "安徽-阜阳",
"status": 6,
"earnings": "6.00",
"mname": "FPS店",
"gettime": "08:00",
"status_name": "已评价"
}
],
"money": 11.1, 一天的收益
"count": 5, 一天的订单数
"code": 1, 1成功 0失败
"msg": "成功"
}
2.按月返回值
{
"list": [
{
"time": "2019-10", //时间
"money": "8", //这个月的总收益
"count": "3" //这个月的总订单数
},
{
"time": "2019-09",
"money": "11.1",
"count": "2"
},
{
"time": "2019-08",
"money": "7",
"count": "2"
},
{
"time": "2019-07",
"money": "0",
"count": "0"
},
{
"time": "2019-06",
"money": "0",
"count": "0"
},
{
"time": "2019-05",
"money": "0",
"count": "0"
},
{
"time": "2019-04",
"money": "0",
"count": "0"
}
],
"code": 1, 1成功 0失败
"msg": "成功"
}