初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace app\shopapi\lists;
use app\coachapi\lists\BaseCoachApiDataLists;
use app\common\enum\OrderEnum;
use app\common\lists\ListsExtendInterface;
use app\common\model\coach\Coach;
use app\common\model\order\Order;
use app\common\model\settle\Settle;
use app\common\model\settle\SettleOrder;
use app\common\model\shop\Shop;
use think\facade\Db;
class IncomeLists extends BaseShopApiDataLists implements ListsExtendInterface
{
public function setWhere()
{
$where = [];
$where[] = ['shop_id','=',$this->shopId];
$type = $this->params['type'] ?? 1;
$where[] = ['is_settle','=',$type];
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_refund_amount,total_order_amount,user_remark,pay_status,appoint_time,is_settle,total_num,order_amount,user_remark,address_snap,true_server_finish_time,server_finish_time,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_num,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 = SettleOrder::where(['order_id'=>$orderIds])->column('*','order_id');
foreach ($lists as $key => $order){
$status = 0;
$settleOrder = $settleOrderLists[$order['id']] ?? [];
if($settleOrder){
$status = 1;
}
$shopCommission = $settleOrder['shop_commission'] ?? 0;
$shopCarAmount = $settleOrder['shop_car_amount'] ?? 0;
$coachCommission = $settleOrder['coach_commission'] ?? 0;
$coachCarAmount = $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['shop_car_amount'] ?? 0 ,
'settle_amount' => $settleOrder['total_commission'] ?? 0 ,
'coach_settle' => $coachCommission,
'shop_settle' => round($shopCommission-$shopCarAmount,2),
];
}
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_shop_amount)') ?:0;
}else{
$settleAmount = Order::whereOr($this->setWhere())->value('sum(total_order_amount - total_refund_amount)') ?:0;
}
return [
'settle_amount' => $settleAmount
];
}
}