第一种
//订单
public function moneyType($where)
{
//待支付金额
if ($where['order_type'] == 1 || $where['order_type'] == '') {
$umoney = $this->umoney($where);
} else {
$umoney = 0;
}
//退款金额
if ($where['order_type'] == 10 || $where['order_type'] == '') {
$rmoney = $this->rmoney($where);
} else {
$rmoney = 0;
}
//预计收入
if ($where['order_type'] == 2 || $where['order_type'] == '' || $where['order_type'] == 3
|| $where['order_type'] == 4 || $where['order_type'] == 5 || $where['order_type'] == 7
|| $where['order_type'] == 8 || $where['order_type'] == 9 || $where['order_type'] == 11) {
switch ($where['order_type']) {
case 2:
$where['order_type'] = 2;
$pmoney = $this->pmoney($where);
break;
case 3:
$where['order_type'] = 3;
$pmoney = $this->pmoney($where);
break;
case 4:
$where['order_type'] = 4;
$pmoney = $this->pmoney($where);
break;
case 5:
$where['order_type'] = 5;
$pmoney = $this->pmoney($where);
break;
case 7:
$where['order_type'] = 7;
$pmoney = $this->pmoney($where);
break;
case 8:
$where['order_type'] = 8;
$pmoney = $this->pmoney($where);
break;
case 9:
$where['order_type'] = 9;
$pmoney = $this->pmoney($where);
break;
case 11:
$where['order_type'] = 11;
$pmoney = $this->pmoney($where);
break;
case '':
$where['order_type'] = ['in', '2,3,4,5,7,8,9.11'];
$pmoney = $this->pmoney($where);
break;
}
} else {
$pmoney = 0;
}
return [$umoney, $rmoney, $pmoney];
}
//待支付金额
public function umoney($where)
{
$where ['order_type'] = 1;
return Db::name('shop_order')->alias('o')
->join('shop_vip v', 'v.id=o.uid')
->join('shop_shop_list l', 'l.id=o.mid')
->where($where)
->sum('order_money');
}
//退款金额
public function rmoney($where)
{
$where ['order_type'] = 10;
return Db::name('shop_order')->alias('o')
->join('shop_vip v', 'v.id=o.uid')
->join('shop_shop_list l', 'l.id=o.mid')
->where($where)
->sum('tk_money');
}
//预计收入
public function pmoney($where)
{
return Db::name('shop_order')->alias('o')
->join('shop_vip v', 'v.id=o.uid')
->join('shop_shop_list l', 'l.id=o.mid')
->where($where)
->sum('order_money');
}
第二种
//代付款金额
$umoney = array_reduce($items, function ($preVal, $val) {
if ($val['order_type'] == 1) {
return $preVal + $val['order_money'];
} else {
return $preVal + 0.00;
};
}, 0.00);
//退款金额
$rmoney = array_reduce($items, function ($preVal, $val) {
if ($val['order_type'] == 10) {
return $preVal + $val['tk_money'];
} else {
return $preVal + 0.00;
};
}, 0.00);
//预计收入金额
$pmoney = array_reduce($items, function ($preVal, $val) {
switch ($val['order_type']) {
case 2:
case 3:
case 4:
case 5:
case 7:
case 8:
case 9:
case 11:
return $preVal + $val['order_money'];
default:
return $preVal + 0.00;
}
}, 0.00);