103 lines
4.0 KiB
PHP
Executable File
103 lines
4.0 KiB
PHP
Executable File
<?php
|
|
namespace app\coachapi\lists;
|
|
|
|
use app\common\enum\OrderEnum;
|
|
use app\common\lists\ListsExtendInterface;
|
|
use app\common\model\order\Order;
|
|
use app\common\model\settle\Settle;
|
|
use app\common\model\settle\SettleOrder;
|
|
use think\facade\Db;
|
|
|
|
class IncomeLists extends BaseCoachApiDataLists implements ListsExtendInterface
|
|
{
|
|
public function setWhere()
|
|
{
|
|
$where = [];
|
|
$where[] = ['coach_id','=',$this->coachId];
|
|
$type = $this->params['type'] ?? 1;
|
|
if(1 == $type){
|
|
$where[] = ['shop_id','=',0];
|
|
}else{
|
|
$where[] = ['shop_id','>',0];
|
|
}
|
|
$where[] = ['order_status','not in',[OrderEnum::ORDER_STATUS_WAIT_PAY,OrderEnum::ORDER_STATUS_WAIT_RECEIVING]];
|
|
|
|
if(isset($this->params['start_time']) && $this->params['start_time']){
|
|
$where[] = ['create_time','>',strtotime($this->params['start_time'])];
|
|
}
|
|
if(isset($this->params['end_time']) && $this->params['end_time']){
|
|
$where[] = ['create_time','<',strtotime($this->params['end_time'])+86399];
|
|
}
|
|
$whereOr1 = array_merge($where,[['order_status','not in',[OrderEnum::ORDER_STATUS_WAIT_PAY,OrderEnum::ORDER_STATUS_WAIT_RECEIVING,OrderEnum::ORDER_STATUS_CLOSE]]],);
|
|
$whereOr2 = array_merge($where, [
|
|
['order_status','=',OrderEnum::ORDER_STATUS_CLOSE],
|
|
['total_order_amount','exp',Db::raw('>total_refund_amount')],
|
|
]);
|
|
|
|
return [$whereOr1,$whereOr2];
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
|
|
$lists = Order::field('id,sn,order_status,total_order_amount,user_remark,pay_status,appoint_time,is_settle,total_num,order_amount,user_remark,total_refund_amount,address_snap,true_server_finish_time,server_finish_time,is_settle,create_time,coach_id,order_distance')
|
|
->order('id','desc')
|
|
->append(['order_distance_desc','true_server_finish_time_desc','appoint_time','appoint_date','order_status_desc','order_cancel_time'])
|
|
->with(['order_goods' => function($query){
|
|
$query->field('order_id,goods_snap,duration,goods_image,goods_name,goods_price')->hidden(['goods_snap']);
|
|
}])
|
|
->whereOr($this->setWhere())
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()->toArray();
|
|
|
|
$orderIds = array_column($lists,'id');
|
|
$settleOrderLists = [];
|
|
if($orderIds){
|
|
$settleOrderLists = SettleOrder::where(['order_id'=>$orderIds])->column('*','order_id');
|
|
}
|
|
foreach ($lists as $key => $order){
|
|
$status = 0;
|
|
$settleOrder = $settleOrderLists[$order['id']] ?? [];
|
|
if($settleOrder){
|
|
$status = 1;
|
|
}
|
|
$coachCommission = $settleOrder['coach_commission'] ?? 0;
|
|
$coachCarCommission = $settleOrder['coach_car_amount'] ?? 0;
|
|
$lists[$key]['settle_info'] = [
|
|
'status' => $status,
|
|
'order_amount' => $settleOrder['order_amount'] ?? 0,
|
|
'refund_amount' => $order['total_refund_amount'],
|
|
'settle_car' => $settleOrder['coach_car_amount'] ?? 0 ,
|
|
'settle_amount' => $settleOrder['total_commission'] ?? 0,
|
|
'coach_settle' => round($coachCommission - $coachCarCommission,2),
|
|
'shop_settle' => 0,
|
|
];
|
|
}
|
|
return $lists;
|
|
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
|
|
return Order::whereOr($this->setWhere())
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->count();
|
|
}
|
|
|
|
public function extend()
|
|
{
|
|
$type = $this->params['type'] ?? 1;
|
|
if(1 == $type){
|
|
|
|
$settleAmount = Order::whereOr($this->setWhere())->where(['is_settle'=>1])->value('sum(settle_coach_amount)') ?: 0;
|
|
|
|
}else{
|
|
$settleAmount = Order::whereOr($this->setWhere())->where(['is_settle'=>1])->value('sum(settle_coach_amount)') ?: 0;
|
|
}
|
|
return [
|
|
'settle_amount' => round($settleAmount,2)
|
|
];
|
|
|
|
}
|
|
} |