Rider.php
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace app\api\controller;
use app\api\model\RiderOrder;
use app\common\controller\Api;
/**
* 骑手
*/
class Rider extends Api
{
protected $noNeedRight = ['*'];
// protected $noNeedLogin = ['*'];
/**
* @ApiTitle (骑手订单页)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=page, type=integer, required=true, description="页数")
* @ApiParams (name=lat, type=integer, required=true, description="骑手纬度")
* @ApiParams (name=lng, type=integer, required=true, description="骑手经度")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
"total": 2,
"per_page": 5,
"current_page": 1,
"last_page": 1,
"data": [
{
"id": 1,
"distance": 111.263, 距离
"address": {
"name": "1", 收件人
"phone": "13549059988", 电话号码
"detail": "阿松大", 地址
"address": "阿松大", 门牌号
},
"orderdetail": {
"order_no": "LQ-16420622494781", 订单编号
"createtime_text": ""
}
}
]
})
*/
public function index()
{
$page = $this->request->post('page',1);
$lat = $this->request->post('lat');
$lng = $this->request->post('lng');
if (!is_numeric($page)) $this->error('页数不合法');
if (!is_numeric($lat)) $this->error('纬度不合法');
if (!is_numeric($lng)) $this->error('经度不合法');
$model = new RiderOrder();
$EARTH=6378.137; //地球半径
$PI=3.14; //PI值 圆周率
$list = $model
->with(['address','orderdetail'])
->where('fa_rider_order.user_id',$this->auth->id)
->where('fa_rider_order.status','1')
->field('Round((2 * '.$EARTH.'* ASIN(SQRT(POW(SIN('.$PI.'*('.$lat.'-lat)/360),2)
+COS('.$PI.'*'.$lat.'/180)* COS(lat * '.$PI.'/180)
*POW(SIN('.$PI.'*('.$lng.'-lng)/360),2)))),3) as distance')
->order('distance')
->paginate(5,false,['page'=>$page])
->each(function ($item,$key){
$item->getRelation('orderdetail')->visible(['order_no']);
$item->getRelation('address')->visible(['name','phone','address','detail']);
$item->visible(['orderdetail','address','distance','id']);
});
$this->success('订单列表',$list);
}
/**
* @ApiTitle (骑手个人页面)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
"avatar": 头像,
"nickname": 昵称,
"money": 余额,
"today_price": 今日所得,
"seven_price": 七日所得,
"all_price": 历史所得,
"today_order": 今日订单数,
"seven_order": 七日订单数,
"all_order": 历史订单数,
})
*/
public function userIndex()
{
$data = [
'avatar' => cdnurl($this->auth->avatar,true),
'nickname' => $this->auth->nickname,
'money' => $this->auth->money
];
$model = new RiderOrder();
$todaytime = strtotime(date('Y-m-d',time()));
$seventime = $todaytime-86400*7;
$today = $model
->where('user_id',$this->auth->id)
->where('status','2')
->where('sendtime','>',$todaytime)
->sum('price');
$todaycount = $model
->where('user_id',$this->auth->id)
->where('status','2')
->where('sendtime','>',$todaytime)
->count();
$seven = $model
->where('fa_rider_order.user_id',$this->auth->id)
->where('status','2')
->where('fa_rider_order.status','>',$seventime)
->sum('price');
$sevencount = $model
->where('fa_rider_order.user_id',$this->auth->id)
->where('status','2')
->where('fa_rider_order.status','>',$seventime)
->count();
$all = $model
->where('fa_rider_order.user_id',$this->auth->id)
->where('fa_rider_order.status','2')
->sum('price');
$allcount = $model
->where('fa_rider_order.user_id',$this->auth->id)
->where('fa_rider_order.status','2')
->count();
$data['today_price'] = $today;
$data['seven_price'] = $seven;
$data['all_price'] = $all;
$data['today_order'] = $todaycount;
$data['seven_order'] = $sevencount;
$data['all_order'] = $allcount;
$this->success('骑手个人页',$data);
}
}