问题描述:
新增用户数表示:2020-7-3第一次下单加油,计算出所有加油员加油用户数量及金额。
解决办法:
thinkphp5,mysql。
先把加油员所有信息查询出来,再查询第一次下单的数量及金额,使用$list->offsetSet($k,$data);拼接到数组中。
$list = Db::name('order')
->alias('o')
->join('admin a','a.id=o.worker_id')
->join('card c','c.id=a.card_id')
->where('o.is_type', '3')
->where('o.confirm_date','between',[strtotime($k3.'00:00:00'),strtotime($k4.'23:59:59')])
->group('o.worker_id')
->field('o.site_id,o.worker_id,sum(o.realoil_price) as sumPrice,count(o.id) as countOtder,a.u_name,c.number')
->order('sumPrice','desc')
->paginate($perPage);
if($list->toArray()) {
foreach($list as $k=>$v){
$data = array();
$data = $v;
$data['count'] = 0;
$data['sunmoney'] = 0;
$sql="SELECT count(id) as num,sum(realoil_price) as sumprice FROM
order
WHERE
confirm_dat >= '".strtotime($k3.'00:00:00')."'
AND confirm_dat < '".strtotime($k4.'24:00:00')."'
AND is_type = 3
AND worker_id = '".$v['worker_id']."'
AND user_id NOT IN ( SELECT user_id FROM order WHERE confirm_dat < '".strtotime($k3.'00:00:00')."' AND is_type = 3 )";
$count=Db::query($sql);
$data['count']=$count[0]['num'];
$data['sunmoney']=$count[0]['sumprice'];
$list->offsetSet($k,$data);
}
}