添加进货补贴详情日志
parent
135f9ee7fa
commit
d2b9cd104d
|
|
@ -29,6 +29,8 @@ class LogoutController extends Controller
|
|||
'm_cid'=>null,
|
||||
]);
|
||||
break;
|
||||
case Device::DEALER:
|
||||
break;
|
||||
default:
|
||||
//解绑用户商城端cid
|
||||
$user->cid->update([
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class EarningController extends Controller
|
|||
*/
|
||||
public function show($id, Request $request)
|
||||
{
|
||||
$earning = $request->user()->dealerEarnings()->findOrFail($id);
|
||||
$earning = $request->user()->dealerEarnings()->with('earningable')->findOrFail($id);
|
||||
return DealerEarningResource::make($earning);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class DealerEarningResource extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$purchaseSubsidyLogs = $this->getPurchaseSubsidyLogs();
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type_name,
|
||||
|
|
@ -29,6 +30,7 @@ class DealerEarningResource extends JsonResource
|
|||
'pay_image' => $this->pay_image,
|
||||
'pay_at' => $this->pay_at?->toDateTimeString(),
|
||||
'is_payer' => $this->payer_id ? ($this->payer_id == $request->user()->id) : false,
|
||||
'purchase_subsidy_logs' => $purchaseSubsidyLogs ? DealerEarningSubsidyLogResource::collection($purchaseSubsidyLogs) : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Dealer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DealerEarningSubsidyLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'change_amount' => $this->changeAmount,
|
||||
'remark' => $this->remark,
|
||||
// 'settle_at'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -76,6 +76,36 @@ class Dealer extends Model
|
|||
return $this->lvl->text();
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计经销商进货补贴实时的【基数业绩】
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getSalePriceAttribute()
|
||||
{
|
||||
$tz = now();
|
||||
|
||||
$tz = now();
|
||||
|
||||
if ($tz->day >= 20) {
|
||||
// 结算当月5号-19号的管理津贴
|
||||
$startAt = $tz->copy()->setDay(5)->startOfDay();
|
||||
$endAt = $tz->copy()->setDay(19)->endOfDay();
|
||||
} elseif ($tz->day >= 5) {
|
||||
// 结算上月20号-到当月4号的管理津贴
|
||||
$startAt = $tz->copy()->subMonthNoOverflow()->set('day', 20)->startOfDay();
|
||||
$endAt = $tz->copy()->set('day', 4)->endOfDay();
|
||||
} else {
|
||||
// 结算上月5号-到19号的管理津贴
|
||||
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(5)->startOfDay();
|
||||
$endAt = $startAt->copy()->setDay(19)->endOfDay();
|
||||
}
|
||||
|
||||
return DealerPurchaseLog::query()->whereBetween('order_completed_at', [$startAt, $endAt])
|
||||
->where('path', 'like', "{$this->userInfo->full_path}%")
|
||||
->sum('total_amount');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认此经销商是否是金牌经销商
|
||||
*
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ class DealerEarning extends Model
|
|||
return $this->belongsTo(User::class, 'payer_id');
|
||||
}
|
||||
|
||||
public function earningable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 待打款
|
||||
*
|
||||
|
|
@ -160,4 +165,17 @@ class DealerEarning extends Model
|
|||
}
|
||||
return $payInfo ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进货补贴的日志
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getPurchaseSubsidyLogs()
|
||||
{
|
||||
if ($this->earningable_type == (new DealerPurchaseSubsidy())->getMorphClass()) {
|
||||
return $this->earningable?->logs;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue