weizong song 3 years ago
parent 5ee21e9ae2
commit 5633aa3631

@ -120,6 +120,11 @@ class Customer extends Authenticatable implements JWTSubject
return $this->hasMany(Balance::class, "customer_id");
}
public function oneBalance()
{
return $this->hasOne(Balance::class, "customer_id");
}
public function recharges()
{
return $this->hasMany(Recharge::class, "customer_id")->whereNotNull("paid_at");

@ -255,11 +255,12 @@ class StatisticsController extends CommonController
DB::enableQueryLog();
//todo:子订单的数量增加,用更省查询时间的方式获取项目相关数据
$customers = (new Customer())
->whereNull("deleted_at")
->with([
"patients" => function ($query) use ($before_datetime) {
$query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc");
},
"balances" => function ($query) use ($before_datetime) {
"oneBalance" => function ($query) use ($before_datetime) {
$query->whereRaw("UNIX_TIMESTAMP(`created_at`) <= {$before_datetime}")->orderBy("id", "desc");
}
])

@ -35,35 +35,25 @@
<th class="p-1" style="white-space: nowrap">客户手机号</th>
<th class="p-1" style="white-space: nowrap">客户家属</th>
<th class="p-1" style="white-space: nowrap">截止日期</th>
<th class="p-1" style="white-space: nowrap">充值汇总</th>
<th class="p-1" style="white-space: nowrap">退款汇总</th>
<th class="p-1" style="white-space: nowrap">扣款汇总</th>
<th class="p-1" style="white-space: nowrap">已到帐未结算余额表</th>
<th class="p-1" style="white-space: nowrap">未结算余额</th>
</tr>
</thead>
<tbody>
@foreach($customers as $item)
@if(!$item->oneBalance)
@continue
@elseif (!($item->oneBalance->balance > 0))
@continue
@endif
<tr>
<td class="p-1">{{ $loop->iteration }}</td>
<td class="p-1">{{ $item->mobile }}</td>
<td class="p-1">{{ $item->patients->count() ? $item->patients->first()->name : "无" }}</td>
<td class="p-1">{{ $item->patients->count() ? $item->patients->last()->name : "无" }}</td>
<td class="p-1">{{ date("Y-m-d H:i:s",$before_datetime) }}</td>
<td class="p-1">{{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\Recharge"; })->sum("money") }}</td>
<td class="p-1">{{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\Refund"; })->sum("money") }}</td>
<td class="p-1">{{ $item->balances->filter(function($item) { return $item->belongs_type == "App\Models\OrderItems"; })->sum("money") }}</td>
<td class="p-1 {{ $item->balances->sum("money") != $item->balances->first()->balance ? "text-danger" : "" }}">{{ $item->balances->sum("money") }}</td>
<td class="p-1">{{ $item->oneBalance->balance }}</td>
</tr>
@endforeach
<tr>
<td class="p-1">&nbsp;</td>
<td class="p-1">&nbsp;</td>
<td class="p-1">&nbsp;</td>
<td class="p-1">&nbsp;</td>
<td class="p-1">&nbsp;</td>
<td class="p-1">&nbsp;</td>
<td class="p-1">总计</td>
<td class="p-1">{{ $customers->each(function($customer) { $customer->balance = $customer->balances->sum("money"); })->sum("balance") }}</td>
</tr>
</tbody>
</table>
</div>

Loading…
Cancel
Save