移除批零
parent
3cd5161b94
commit
221d1bcda7
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions\Dealer;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
|
||||
class CalculateManageSubsidiesOfCurrentPeriod
|
||||
{
|
||||
/**
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return string
|
||||
*/
|
||||
public function handle(Dealer $dealer): string
|
||||
{
|
||||
$tz = now();
|
||||
|
||||
if ($tz->day >= 20) {
|
||||
$startAt = $tz->copy()->setDay(20)->startOfDay();
|
||||
} elseif ($tz->day >= 5) {
|
||||
$startAt = $tz->copy()->setDay(5)->startOfDay();
|
||||
} else {
|
||||
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
|
||||
}
|
||||
|
||||
$total = DealerManageSubsidyLog::where('order_completed_at', '>=', $startAt)->where('user_id', $dealer->user_id)->sum('total_amount');
|
||||
|
||||
return bcmul($total, '1', 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions\Dealer;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerPurchaseLog;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class CalculatePurchaseAmount
|
||||
{
|
||||
/**
|
||||
* 计算经销商的进货业绩
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @param \Illuminate\Support\Carbon|null $start
|
||||
* @param \Illuminate\Support\Carbon|null $end
|
||||
* @return string
|
||||
*/
|
||||
public function handle(Dealer $dealer, ?Carbon $start = null, ?Carbon $end = null): string
|
||||
{
|
||||
$query = DealerPurchaseLog::query();
|
||||
|
||||
if ($start && $end) {
|
||||
$query->whereBetween('order_completed_at', [$start, $end]);
|
||||
} else {
|
||||
$query->when($start, function ($query, $start) {
|
||||
$query->where('order_completed_at', '>=', $start);
|
||||
})->when($end, function ($query, $end) {
|
||||
$query->where('order_completed_at', '<=', $end);
|
||||
});
|
||||
}
|
||||
|
||||
return $query->where('path', 'like', "{$dealer->userInfo->full_path}%")->sum('total_amount');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions\Dealer;
|
||||
|
||||
use App\Models\Dealer;
|
||||
|
||||
class CalculatePurchaseAmountOfCurrentPeriod
|
||||
{
|
||||
public function __construct(
|
||||
protected CalculatePurchaseAmount $calculatePurchaseAmount,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算当期的进货业绩
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @return string
|
||||
*/
|
||||
public function handle(Dealer $dealer): string
|
||||
{
|
||||
$tz = now();
|
||||
|
||||
if ($tz->day >= 20) {
|
||||
$startAt = $tz->setDay(20)->startOfDay();
|
||||
} else {
|
||||
$startAt = $tz->subMonthNoOverflow()->setDay(20)->startOfDay();
|
||||
}
|
||||
|
||||
return bcmul($this->calculatePurchaseAmount->handle($dealer, $startAt), '1', 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerBonds as DealerBondsForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerBonds extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-stop-circle grid-action-icon"></i> 保证金 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.bonds');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerBondsForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerEarning;
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerChannelSubsidyBatchPay extends BatchAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_channel_subsidies.batch_pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的渠道补贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () {
|
||||
foreach ($this->getKey() as $id) {
|
||||
$dealerEarning = DealerEarning::lockForUpdate()->channelSubsidy()->withoutPayer()->find($id);
|
||||
|
||||
if (! $dealerEarning?->isSettled() || ! $dealerEarning?->isPending()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
(new DealerEarningService())->pay($dealerEarning);
|
||||
}
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
return $this->response()->error('操作失败:'.$e->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerEarning;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerChannelSubsidyPay extends RowAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_channel_subsidies.pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的渠道补贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$id = $this->getKey();
|
||||
|
||||
$dealerEarning = DealerEarning::lockForUpdate()->channelSubsidy()->withoutPayer()->find($id);
|
||||
|
||||
(new DealerEarningService())->pay($dealerEarning);
|
||||
});
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Enums\DealerDeliveryBillStatus;
|
||||
use App\Models\DealerDeliveryBill;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerDeliveryShipping extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-package grid-action-icon"></i> 确认发货 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return true;
|
||||
return $user->can('dcat.admin.dealer_delivery_bills.shipping');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$order = DealerDeliveryBill::findOrFail($this->getKey());
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$order->update([
|
||||
'status' => DealerDeliveryBillStatus::Shippinged,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['确认当前云仓单已发货?', '确认后将无法逆操作'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerEditLvl as DealerEditLvlForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerEditLvl extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather grid-action-icon icon-shuffle"></i> 修改等级 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.edit_lvl');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerEditLvlForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerEditProduct as DealerEditProductForm;
|
||||
use App\Admin\Renderable\DealerUserProductSimpleTable;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerEditProduct extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather grid-action-icon icon-package"></i> 修改库存 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.edit_product');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerEditProductForm::make()->payload(['id'=>$this->primaryKey]);
|
||||
// $grid = DealerUserProductSimpleTable::make(['id'=>$this->primaryKey]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerManageSubsidyBatchPay extends BatchAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_manage_subsidies.batch_pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的管理津贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () {
|
||||
foreach ($this->getKey() as $id) {
|
||||
$dealerManageSubsidy = DealerManageSubsidy::lockForUpdate()->settled()->find($id);
|
||||
|
||||
if ($dealerManageSubsidy?->isPending()) {
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerManageSubsidy->earning->setRelation('earningable', $dealerManageSubsidy)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
return $this->response()->error('操作失败:'.$e->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerManageSubsidyPay extends RowAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_manage_subsidies.pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的管理津贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$id = $this->getKey();
|
||||
|
||||
$dealerManageSubsidy = DealerManageSubsidy::lockForUpdate()->settled()->findOrFail($id);
|
||||
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerManageSubsidy->earning->setRelation('earningable', $dealerManageSubsidy)
|
||||
);
|
||||
});
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerManagerSubsidyBatchPay extends BatchAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_manager_subsidies.batch_pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的管理者津贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () {
|
||||
foreach ($this->getKey() as $id) {
|
||||
$dealerManagerSubsidy = DealerManagerSubsidy::lockForUpdate()->settled()->find($id);
|
||||
|
||||
if ($dealerManagerSubsidy?->isPending()) {
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerManagerSubsidy->earning->setRelation('earningable', $dealerManagerSubsidy)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
return $this->response()->error('操作失败:'.$e->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerManagerSubsidyPay extends RowAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_manager_subsidies.pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的管理者津贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$id = $this->getKey();
|
||||
|
||||
$dealerManagerSubsidy = DealerManagerSubsidy::lockForUpdate()->settled()->findOrFail($id);
|
||||
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerManagerSubsidy->earning->setRelation('earningable', $dealerManagerSubsidy)
|
||||
);
|
||||
});
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Models\DealerOrder;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderAllocate extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-stop-circle grid-action-icon"></i> 分配订单 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_orders.allocate');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$order = DealerOrder::findOrFail($this->getKey());
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
(new OrderService())->updateOrderConsignor($order);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['确认自动分配当前订单接单人?', '确认后将无法逆操作'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Models\DealerOrder;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderCancel extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-trash grid-action-icon"></i> 取消订单 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_orders.cancel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$order = DealerOrder::findOrFail($this->getKey());
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
(new OrderService())->cancelOrder($order);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['确认取消当前订单?', '确认后将无法逆操作'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Models\DealerOrder;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderPaid extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-stop-circle grid-action-icon"></i> 确认收款 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_orders.paid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$order = DealerOrder::findOrFail($this->getKey());
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
(new OrderService())->paidOrder($order);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['确认当前订单已收款?', '确认后将无法逆操作'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerOrderRefuse as DealerOrderRefuseForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerOrderRefuse extends RowAction
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
$form = DealerOrderRefuseForm::make()->payload(['id' => $this->getKey()]);
|
||||
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title('拒绝收款')
|
||||
->body($form)
|
||||
->button('<i class="feather icon-x-circle grid-action-icon"></i> 拒绝收款 ');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderShipping extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-package grid-action-icon"></i> 确认发货 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_orders.shipping');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$order = DealerOrder::findOrFail($this->getKey());
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
(new OrderService())->shippingOrder($order);
|
||||
DB::commit();
|
||||
} catch (QueryException $e) {
|
||||
DB::rollBack();
|
||||
if (strpos($e->getMessage(), 'Numeric value out of range') !== false) {
|
||||
$e = new BizException('当前可发货库存不足');
|
||||
}
|
||||
return $this->response()->error('操作失败,'.$e->getMessage())->refresh();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['确认当前订单已发货?', '确认后将无法逆操作'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerProductLvlRule as DealerProductLvlRuleForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerProductLvlRule extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-package grid-action-icon"></i> 等级规则 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.lvl_rules');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerProductLvlRuleForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerProductManageRule as DealerProductManageRuleForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerProductManageRule extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-bookmark grid-action-icon"></i> 管理规则 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.manage_rules');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerProductManageRuleForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerProductSaleRule as DealerProductSaleRuleForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerProductSaleRule extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather icon-bar-chart grid-action-icon"></i> 销售规则 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.sale_rules');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerProductSaleRuleForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerPurchaseSubsidyBatchPay extends BatchAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_purchase_subsidies.batch_pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的进货补贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () {
|
||||
foreach ($this->getKey() as $id) {
|
||||
$dealerPurchaseSubsidy = DealerPurchaseSubsidy::lockForUpdate()->settleCompleted()->find($id);
|
||||
|
||||
if ($dealerPurchaseSubsidy?->isPending()) {
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerPurchaseSubsidy->earning->setRelation('earningable', $dealerPurchaseSubsidy)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
return $this->response()->error('操作失败:'.$e->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerPurchaseSubsidyPay extends RowAction
|
||||
{
|
||||
protected $title = '<i class="feather grid-action-icon icon-stop-circle"></i> 付款';
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_purchase_subsidies.pay');
|
||||
}
|
||||
|
||||
// 确认弹窗信息
|
||||
public function confirm()
|
||||
{
|
||||
return '您确定要支付选中的进货补贴吗?';
|
||||
}
|
||||
|
||||
// 处理请求
|
||||
public function handle(Request $request)
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$id = $this->getKey();
|
||||
|
||||
$dealerPurchaseSubsidy = DealerPurchaseSubsidy::lockForUpdate()->settleCompleted()->findOrFail($id);
|
||||
|
||||
(new DealerEarningService())->pay(
|
||||
$dealerPurchaseSubsidy->earning->setRelation('earningable', $dealerPurchaseSubsidy)
|
||||
);
|
||||
});
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid;
|
||||
|
||||
use App\Admin\Forms\DealerWalletChange as DealerWalletChangeForm;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerWalletChange extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
return '<i class="feather grid-action-icon icon-credit-card"></i> 变更余额 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_change');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerWalletChangeForm::make()->payload(['id'=>$this->getKey()]);
|
||||
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title())
|
||||
->body($form)
|
||||
->button($this->title());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Grid\Exports;
|
||||
|
||||
use Dcat\Admin\Actions\Response;
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Traits\HasPermissions;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DealerWalletWithdraw extends RowAction
|
||||
{
|
||||
public function title()
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
}
|
||||
return '<i class="feather grid-action-icon icon-download"></i> 导出打款单 ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.export');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
$last_path_arr = parse_url(session('admin.prev.url'));
|
||||
return $this->response()->download(admin_route('dealer_wallet_to_bank_logs.export').'?'.($last_path_arr['query']??''));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\DealerEarningPay as DealerEarningPayForm;
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerEarningPay extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-file-text"></i> 打款';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn btn-sm btn-danger';
|
||||
|
||||
// public function render()
|
||||
// {
|
||||
// $form = DealerEarningPayForm::make()->payload(['id'=>$this->getKey()]);
|
||||
// return Modal::make()
|
||||
// ->lg()
|
||||
// ->title($this->title)
|
||||
// ->body($form)
|
||||
// ->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a> ");
|
||||
// }
|
||||
|
||||
public function handle(Request $request)
|
||||
{
|
||||
// 获取主键
|
||||
$key = $this->getKey();
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$earning = DealerEarning::findOrFail($key);
|
||||
$earning->update([
|
||||
'pay_way' => DealerEarning::PAY_WAY_WALLET,
|
||||
'pay_info' => $earning->getPayInfo(),
|
||||
'pay_at' => now(),
|
||||
'status' => DealerEarningStatus::Completed,
|
||||
]);
|
||||
//打款到余额;
|
||||
$walletService = new WalletService();
|
||||
switch ($earning->earningable_type) {
|
||||
case (new DealerManagerSubsidy())->getMorphClass():
|
||||
$action = DealerWalletAction::ManagerSubsidyIn;
|
||||
break;
|
||||
case (new DealerManageSubsidy())->getMorphClass():
|
||||
$action = DealerWalletAction::ManageSubsidyIn;
|
||||
break;
|
||||
case (new DealerChannelSubsidyLog())->getMorphClass():
|
||||
$action = DealerWalletAction::ChannelSubsidyIn;
|
||||
break;
|
||||
default:
|
||||
$action = DealerWalletAction::PurchaseSubsidyIn;
|
||||
break;
|
||||
}
|
||||
$walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->earningable_type_text, $earning);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
public function html()
|
||||
{
|
||||
return parent::html().' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认弹窗信息,如不需要可以删除此方法
|
||||
*
|
||||
* @return string|array|void
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
return ['是否确认打款?', '该操作不可逆,确认后将打款到余额。'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\DealerOrderRemark as DealerOrderRemarkForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerOrderRemark extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-file-text"></i> 备注';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-success';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerOrderRemarkForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title)
|
||||
->body($form)
|
||||
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\DealerWalletPay as DealerWalletPayForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerWalletPay extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-file-text"></i> 打款';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-danger mr-1';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerWalletPayForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title)
|
||||
->body($form)
|
||||
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\DealerWalletRefuse as DealerWalletRefuseForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class DealerWalletRefuse extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-file-text"></i> 拒绝';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-warning mr-1';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = DealerWalletRefuseForm::make()->payload(['id'=>$this->getKey()]);
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title)
|
||||
->body($form)
|
||||
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerChannelSubsidyBatchPay;
|
||||
use App\Admin\Actions\Grid\DealerChannelSubsidyPay;
|
||||
use App\Admin\Repositories\DealerEarning;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Models\DealerEarning as DealerEarningModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
|
||||
class DealerChannelSubsidyController extends AdminController
|
||||
{
|
||||
protected $title = '签约渠道补贴';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerEarning::with(['user.userInfo']);
|
||||
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->channelSubsidy()->withoutPayer()->orderBy('id', 'desc');
|
||||
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone', '手机号');
|
||||
$grid->column('user.userInfo.nickname', '昵称');
|
||||
$grid->column('lvl', '经销商等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('total_amount', '补贴金额')->prepend('¥');
|
||||
$grid->column('fee', '手续费')->prepend('¥')->help('手续费=补贴金额*手续费率');
|
||||
$grid->column('fee_rate', '手续费率')->append('%');
|
||||
$grid->column('total_earnings', '总收入')->prepend('¥')->help('总收入=补贴金额-手续费');
|
||||
$grid->column('remark', '备注')->display('查看') // 设置按钮名称
|
||||
->expand(function () {
|
||||
$card = new Card(null, nl2br($this->remark));
|
||||
|
||||
return "<div style='padding:10px 10px 0'>$card</div>";
|
||||
});
|
||||
$grid->column('settle_at', '结算时间')->display(function () {
|
||||
return $this->settle_at?->toDateTimeString();
|
||||
})->sortable();
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$v->color()}'></i> {$v->text()}";
|
||||
});
|
||||
$grid->column('pay_at', '付款时间')->display(function () {
|
||||
return $this->pay_at?->toDateTimeString();
|
||||
})->sortable();
|
||||
$grid->column('created_at', '创建时间')->display(function () {
|
||||
return $this->created_at?->toDateTimeString();
|
||||
});
|
||||
|
||||
// $grid->showRowSelector();
|
||||
// $grid->tools(function ($tools) {
|
||||
// $tools->batch(function ($batch) {
|
||||
// $batch->disableDelete();
|
||||
|
||||
// if (Admin::user()->can('dcat.admin.dealer_channel_subsidies.batch_pay')) {
|
||||
// $batch->add(new DealerChannelSubsidyBatchPay());
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
$grid->disableActions();
|
||||
// $grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
// if (
|
||||
// $actions->row->isSettled() &&
|
||||
// $actions->row->isPending() &&
|
||||
// Admin::user()->can('dcat.admin.dealer_channel_subsidies.pay')
|
||||
// ) {
|
||||
// $actions->append(new DealerChannelSubsidyPay());
|
||||
// }
|
||||
// });
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
|
||||
$filter->equal('user.phone', '手机号')->width(3);
|
||||
$filter->equal('status', '状态')->select([
|
||||
DealerEarningStatus::Pending->value => '待付款',
|
||||
DealerEarningStatus::Completed->value => '已完成',
|
||||
])->width(3);
|
||||
$filter->between('settle_at', '结算时间')->datetime()->width(6);
|
||||
});
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerEarningModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$totalAmount = (clone $query)->sum('total_amount');
|
||||
$totalFee = (clone $query)->sum('fee');
|
||||
|
||||
$row->column(3, new InfoBox('补贴金额', $totalAmount, 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('手续费', $totalFee, 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,242 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerBonds;
|
||||
use App\Admin\Actions\Grid\DealerEditLvl;
|
||||
use App\Admin\Actions\Grid\DealerEditProduct;
|
||||
use App\Admin\Actions\Grid\DealerWalletChange;
|
||||
use App\Admin\Renderable\DealerEarningSimpleTable;
|
||||
use App\Admin\Renderable\DealerSubordinateCard;
|
||||
use App\Admin\Renderable\DealerUserProductLogSimpleTable;
|
||||
use App\Admin\Renderable\DealerWalletLogSimpleTable;
|
||||
use App\Admin\Repositories\Dealer;
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Models\Dealer as DealerModel;
|
||||
use App\Models\DealerUserProduct;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\Column;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
use Dcat\Admin\Widgets\Tab;
|
||||
|
||||
class DealerController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$builder = Dealer::with(['user', 'userInfo', 'userInfo.inviterInfo.user', 'userInfo.realInviterInfo.user', 'wallet']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
// $grid->column('id')->sortable();
|
||||
$grid->column('user.phone')->copyable();
|
||||
$grid->column('userInfo.nickname');
|
||||
$grid->column('userInfo.inviterInfo.user.phone')->copyable();
|
||||
$grid->column('userInfo.realInviterInfo.user.phone')->copyable();
|
||||
// $grid->column('user_id');
|
||||
|
||||
$lvlTexts = DealerLvl::texts();
|
||||
$grid->column('lvl')->display(function () {
|
||||
return $this->lvl->text();
|
||||
})->filter(Grid\Column\Filter\In::make($lvlTexts))->modal(function ($modal) {
|
||||
// $modal->title('消费值');
|
||||
return DealerSubordinateCard::make(['id'=>$this->user_id]);
|
||||
})->setHeaderAttributes(['style' => 'color:#5b69bc']);
|
||||
$grid->column('wallet.balance')->display(function ($value) {
|
||||
return $value ?? 0;
|
||||
})->prepend('¥');
|
||||
$grid->column('is_sale')
|
||||
->if(function () {
|
||||
return Admin::user()->can('dcat.admin.dealers.update');
|
||||
})
|
||||
->then(function (Column $column) {
|
||||
$column->switch();
|
||||
})
|
||||
->else(function (Column $column) {
|
||||
$column->bool();
|
||||
});
|
||||
$grid->column('is_manager')
|
||||
->if(function () {
|
||||
return Admin::user()->can('dcat.admin.dealers.update');
|
||||
})
|
||||
->then(function (Column $column) {
|
||||
$column->switch();
|
||||
})
|
||||
->else(function (Column $column) {
|
||||
$column->bool();
|
||||
});
|
||||
$grid->column('bonds')->prepend('¥')->filter(
|
||||
Grid\Column\Filter\Between::make()
|
||||
);
|
||||
// $grid->column('created_at')->sortable();
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealers.show')) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealers.show', ['dealer_user'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
|
||||
$actions->append(new DealerEditLvl());
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.dealers.wallet_change')) {
|
||||
$actions->append(new DealerWalletChange());
|
||||
}
|
||||
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
|
||||
$actions->append(new DealerBonds());
|
||||
}
|
||||
$actions->append((new DealerEditProduct())->setKey($actions->row->user_id));
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->equal('user.phone')->width(3);
|
||||
$filter->equal('userInfo.inviterInfo.user.phone')->width(3);
|
||||
$filter->equal('userInfo.realInviterInfo.user.phone')->width(3);
|
||||
$filter->equal('userInfo.nickname')->width(4);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return function (Row $row) use ($id) {
|
||||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = Dealer::with(['user', 'userInfo', 'userInfo.inviterInfo.user']);
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
// $show->field('id');
|
||||
$show->field('user.phone');
|
||||
$show->field('userInfo.nickname')->as(function () {
|
||||
return $this->userInfo->nickname;
|
||||
});
|
||||
$show->field('lvl')->as(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$show->field('is_sale')->as(function ($val) {
|
||||
return $val ? '是' : '否';
|
||||
});
|
||||
$show->field('is_manager')->as(function ($val) {
|
||||
return $val ? '是' : '否';
|
||||
});
|
||||
|
||||
$show->divider('收款信息-银行');
|
||||
$show->field('bank_user_name', '银行-收款人')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['bank']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_name', '银行-名称')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['bank']['bank_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_number', '银行-卡号')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['bank']['bank_number'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_description', '银行-开户行')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['bank']['bank_description'] ?? '';
|
||||
});
|
||||
$show->divider('收款信息-支付宝');
|
||||
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['alipay']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['alipay']['ali_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_image', '支付宝-收款码')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['alipay']['image'] ?? '';
|
||||
})->image();
|
||||
$show->divider('收款信息-微信');
|
||||
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['wechat']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['wechat']['wechat_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_image', '微信-收款码')->as(function () {
|
||||
$payInfo = $this->pay_info;
|
||||
return $payInfo['wechat']['image'] ?? '';
|
||||
})->image();
|
||||
|
||||
// $show->field('pay_info');
|
||||
$show->field('created_at');
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
});
|
||||
}));
|
||||
});
|
||||
$row->column(7, function ($column) use ($id) {
|
||||
$dealer = DealerModel::findOrFail($id);
|
||||
$tab = Tab::make();
|
||||
// 资金记录
|
||||
$tab->add('资金记录', new DealerEarningSimpleTable(['id'=>$dealer->user_id]));
|
||||
// 剩余库存
|
||||
$builder = DealerUserProduct::query();
|
||||
$builder->with(['product'])->where('user_id', $dealer->user_id);
|
||||
$productGrid = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('product.cover', '商品封面')->image(80, 80);
|
||||
$grid->column('stock', '库存');
|
||||
$grid->column('deposit_stock', '云库存');
|
||||
$grid->column('created_at', '创建时间');
|
||||
$grid->column('logs', '库存记录')->display('查看')->modal(function ($modal) {
|
||||
$modal->title('商品');
|
||||
return DealerUserProductLogSimpleTable::make(['product_id'=>$this->product_id, 'id'=> $this->user_id]);
|
||||
});
|
||||
// $grid->withBorder();
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
});
|
||||
|
||||
$tab->add('剩余库存', $productGrid);
|
||||
|
||||
$tab->add('余额记录', new DealerWalletLogSimpleTable(['id'=>$dealer->user_id]));
|
||||
// $tab->add('升级记录', '');
|
||||
// 上级列表
|
||||
// $tab->add('上级列表', '');
|
||||
$column->row(Box::make('用户记录', $tab));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new Dealer(), function (Form $form) {
|
||||
$form->display('id');
|
||||
// $form->text('user_id');
|
||||
// $form->text('lvl');
|
||||
$form->text('is_sale');
|
||||
$form->text('is_manager');
|
||||
// $form->text('pay_info');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerDeliveryShipping;
|
||||
use App\Admin\Repositories\DealerDeliveryBill;
|
||||
use App\Admin\Repositories\DealerDeliveryProduct;
|
||||
use App\Enums\DealerDeliveryBillStatus;
|
||||
use App\Enums\PayWay;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
|
||||
class DealerDeliveryBillController extends AdminController
|
||||
{
|
||||
protected $title = '云仓提货单';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$repository = DealerDeliveryBill::with(['user.userInfo']);
|
||||
|
||||
return Grid::make($repository, function (Grid $grid) {
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('sn', '提货单号');
|
||||
$grid->column('user.phone', '手机号');
|
||||
$grid->column('user.userInfo.nickname', '昵称');
|
||||
$grid->column('shipping_fee', '运费')->prepend('¥');
|
||||
$grid->column('pay_way', '支付方式')->display(function ($v) {
|
||||
return $v?->text();
|
||||
})->circleDot(PayWay::colors());
|
||||
$grid->column('pay_at', '付款时间')->display(function ($v) {
|
||||
return $v?->toDateTimeString();
|
||||
});
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
return $v?->text();
|
||||
})->circleDot(DealerDeliveryBillStatus::colors());
|
||||
$grid->column('created_at', '创建时间')->display(function ($v) {
|
||||
return $v?->toDateTimeString();
|
||||
});
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealer_orders.show')) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_delivery_bills.show', [$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
}
|
||||
|
||||
if ($actions->row->isPaid()) {
|
||||
$actions->append(new DealerDeliveryShipping());
|
||||
}
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('sn', '提货单号')->width(4);
|
||||
$filter->like('user.phone', '手机号')->width(4);
|
||||
$filter->equal('status', '状态')->select(DealerDeliveryBillStatus::texts())->width(4);
|
||||
$filter->between('pay_at', '付款时间')->dateTime()->width(4);
|
||||
$filter->between('created_at', '创建时间')->dateTime()->width(4);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return function (Row $row) use ($id) {
|
||||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = DealerDeliveryBill::with(['user.userInfo']);
|
||||
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('sn', '提货单号');
|
||||
$show->field('user.phone', '手机号');
|
||||
$show->field('user.user_info.nickname', '昵称');
|
||||
$show->field('shipping_fee', '运费');
|
||||
$show->field('remark', '备注');
|
||||
$show->field('status', '状态')->as(function () {
|
||||
return $this->status?->text();
|
||||
})->circleDot(DealerDeliveryBillStatus::colors());
|
||||
$show->field('created_at')->as(function ($v) {
|
||||
return $this->created_at->toDateTimeString();
|
||||
});
|
||||
|
||||
$show->divider();
|
||||
$show->field('consignee_name', '收货人');
|
||||
$show->field('consignee_telephone', '联系方式');
|
||||
$show->field('consignee', '收货地址')->as(function () {
|
||||
return $this->consignee_zone . ' '. $this->consignee_address;
|
||||
});
|
||||
|
||||
$show->divider();
|
||||
$show->field('pay_sn', '支付单号');
|
||||
$show->field('pay_way', '支付方式')->as(function () {
|
||||
return $this->pay_way?->text();
|
||||
})->circleDot(PayWay::colors());
|
||||
$show->field('pay_at', '付款时间')->as(function () {
|
||||
return $this->pay_at?->toDateTimeString();
|
||||
});
|
||||
$show->field('out_trade_no', '外部交易号');
|
||||
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
});
|
||||
}));
|
||||
});
|
||||
$row->column(7, function ($column) use ($id) {
|
||||
$repository = DealerDeliveryProduct::with(['product']);
|
||||
|
||||
$column->row(Box::make('提货单商品', Grid::make($repository, function (Grid $grid) use ($id) {
|
||||
$grid->model()->where('delivery_bill_id', $id);
|
||||
|
||||
$grid->column('product.name', '名称');
|
||||
$grid->column('product.cover', '封面')->image(50, 50);
|
||||
$grid->column('qty', '数量');
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
$grid->disableRefreshButton();
|
||||
})));
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,321 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Show\DealerEarningPay;
|
||||
use App\Admin\Renderable\Grid\Filter\DealerEarningStatusIn;
|
||||
use App\Admin\Repositories\DealerEarning;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\PayWay;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning as DealerEarningModel;
|
||||
use App\Models\DealerManagerSalesLog;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use App\Models\DealerPurchaseSubsidyLog;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
|
||||
class DealerEarningController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$earning = DealerEarning::with(['user.userInfo', 'payer']);
|
||||
|
||||
return Grid::make($earning, function (Grid $grid) {
|
||||
$grid->setResource('dealer-earnings');
|
||||
$grid->model()->orderBy('id', 'desc'); //默认ID倒叙
|
||||
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone');
|
||||
$grid->column('user.userInfo.nickname', '昵称');
|
||||
$grid->column('lvl')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('earningable_type', '资金类型')->display(function () {
|
||||
return $this->earningable_type_text;
|
||||
})->label([
|
||||
(new DealerManageSubsidy())->getMorphClass() => 'primary',
|
||||
(new DealerManagerSubsidy())->getMorphClass() => 'success',
|
||||
(new DealerPurchaseSubsidy())->getMorphClass() => 'danger',
|
||||
(new DealerChannelSubsidyLog())->getMorphClass() => 'warning',
|
||||
])->filter(Grid\Column\Filter\In::make([
|
||||
(new DealerManagerSubsidy())->getMorphClass() =>'管理者补贴',
|
||||
(new DealerManageSubsidy())->getMorphClass() => '管理补贴',
|
||||
(new DealerChannelSubsidyLog())->getMorphClass() => '渠道补贴',
|
||||
(new DealerPurchaseSubsidy())->getMorphClass() => '进货补贴',
|
||||
]));
|
||||
$grid->column('total_amount')->prepend('¥');
|
||||
$grid->column('fee_rate')->append('%');
|
||||
$grid->column('fee')->prepend('¥');
|
||||
$grid->column('total_earnings')->prepend('¥');
|
||||
$grid->column('remark')->display('查看') // 设置按钮名称
|
||||
->expand(function () {
|
||||
$card = new Card(null, nl2br($this->remark));
|
||||
|
||||
return "<div style='padding:10px 10px 0'>$card</div>";
|
||||
});
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
if (! $this->isSettled()) {
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: #b9c3cd'></i> 待结算";
|
||||
}
|
||||
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$v->color()}'></i> {$v->text()}";
|
||||
})->filter(DealerEarningStatusIn::make([
|
||||
-1 => '待结算',
|
||||
0 => '待打款',
|
||||
1 => '待收款',
|
||||
5 => '已完成',
|
||||
]));
|
||||
$grid->column('settle_at');
|
||||
$grid->column('payer_id')->display(function () {
|
||||
return $this->payer_id ? $this->payer?->phone : '公司';
|
||||
});
|
||||
$grid->column('pay_way', '支付方式')->display(function ($v) {
|
||||
return $v?->text();
|
||||
})->circleDot(PayWay::colors());
|
||||
$grid->column('pay_at');
|
||||
$grid->column('created_at')->sortable();
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_earnings.show', ['dealer_earning'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
});
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerEarningModel::query();
|
||||
|
||||
// 拿到表格筛选 where 条件数组进行遍历
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
// 查出统计数据
|
||||
$totalAmount = (clone $query)->sum('total_amount');
|
||||
|
||||
$row->column(3, new InfoBox('金额', $totalAmount, 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('手续费', (clone $query)->sum('fee'), 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->equal('user.phone')->width(3);
|
||||
$filter->between('settle_at')->dateTime()->width(6);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return function (Row $row) use ($id) {
|
||||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = DealerEarning::with(['user.userInfo', 'payer']);
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('user.phone');
|
||||
$show->field('user.user_info.nickname', '昵称');
|
||||
$show->field('lvl')->as(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$show->field('earningable_type', '资金类型')->as(function () {
|
||||
return $this->earningable_type_text;
|
||||
})->label();
|
||||
$show->field('total_amount')->prepend('¥');
|
||||
$show->field('fee_rate')->append('%');
|
||||
$show->field('fee')->prepend('¥');
|
||||
$show->field('total_earnings')->prepend('¥');
|
||||
$show->field('payer.phone', '打款人')->as(function () {
|
||||
return $this->payer_id ? $this->payer?->phone : '公司';
|
||||
});
|
||||
$show->field('pay_way', '打款方式')->as(function () {
|
||||
return $this->pay_way?->text();
|
||||
})->circleDot(PayWay::colors());
|
||||
$show->field('pay_at', '打款时间')->as(function () {
|
||||
return $this->pay_at?->toDateTimeString();
|
||||
});
|
||||
$show->field('pay_image')->image();
|
||||
$show->field('settle_at');
|
||||
$show->field('remark')->unescape()->as(function () {
|
||||
return nl2br($this->remark);
|
||||
});
|
||||
$show->field('status', '状态')->unescape()->as(function () {
|
||||
if (! $this->isSettled()) {
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: #b9c3cd'></i> 待结算";
|
||||
}
|
||||
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$this->status->color()}'></i> {$this->status->text()}";
|
||||
});
|
||||
$show->field('created_at');
|
||||
|
||||
// 非(待结算)显示收款人信息
|
||||
if ($show->model()->isSettled()) {
|
||||
$show->divider('收款信息-银行');
|
||||
$show->field('bank_user_name', '银行-收款人')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_name', '银行-名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_number', '银行-卡号')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_number'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_description', '银行-开户行')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_description'] ?? '';
|
||||
});
|
||||
$show->divider('收款信息-支付宝');
|
||||
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['ali_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_image', '支付宝-收款码')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['image'] ?? '';
|
||||
})->image();
|
||||
$show->divider('收款信息-微信');
|
||||
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['wechat_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_image', '微信-收款码')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['image'] ?? '';
|
||||
})->image();
|
||||
}
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
// if ($show->model()->status == DealerEarningStatus::Pending && Admin::user()->can('dcat.admin.dealer_earnings.pay')) {
|
||||
// if (!$show->model()->payer_id || $show->model()->payer_id == 1) {
|
||||
// $tools->append(new DealerEarningPay());
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}));
|
||||
});
|
||||
$row->column(7, function ($column) use ($id) {
|
||||
$earning = DealerEarningModel::with('earningable')->findOrFail($id);
|
||||
$grid = '暂无记录';
|
||||
switch (get_class($earning->earningable)) {
|
||||
case DealerManagerSubsidy::class://管理者补贴
|
||||
$builder = DealerManagerSalesLog::with(['order', 'product'])->where('user_id', $earning->earningable->user_id)->whereBetween('order_completed_at', [$earning->earningable->start_at, $earning->earningable->end_at]);
|
||||
$grid = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('id');
|
||||
$grid->column('order.sn', '订单编号');
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('sales_volume', '销量');
|
||||
$grid->column('order_completed_at', '结算时间');
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
});
|
||||
break;
|
||||
case DealerManageSubsidy::class://管理补贴
|
||||
$builder = DealerManageSubsidyLog::with(['order', 'product'])->where('user_id', $earning->earningable->user_id)->whereBetween('order_completed_at', [$earning->earningable->start_at, $earning->earningable->end_at]);
|
||||
$grid = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('id');
|
||||
$grid->column('order.sn', '订单编号');
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('sales_volume', '销量');
|
||||
$grid->column('total_amount', '金额');
|
||||
$grid->column('order_completed_at', '结算时间');
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
// $grid->disablePagination();
|
||||
});
|
||||
break;
|
||||
case DealerPurchaseSubsidy::class://进货补贴
|
||||
$builder = DealerPurchaseSubsidyLog::where('purchase_subsidy_id', $earning->earningable_id);
|
||||
$grid = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('id');
|
||||
$grid->column('change_amount', '变更金额');
|
||||
$grid->column('remark', '备注');
|
||||
$grid->column('created_at', '结算时间');
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
});
|
||||
break;
|
||||
}
|
||||
$column->row(Box::make('明细记录', $grid));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerEarning(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('user_id');
|
||||
$form->text('earningable_type');
|
||||
$form->text('earningable_id');
|
||||
$form->text('lvl');
|
||||
$form->text('is_manager');
|
||||
$form->text('total_amount');
|
||||
$form->text('total_earnings');
|
||||
$form->text('fee');
|
||||
$form->text('fee_rate');
|
||||
$form->text('payer_id');
|
||||
$form->text('pay_info');
|
||||
$form->text('pay_at');
|
||||
$form->text('settle_at');
|
||||
$form->text('status');
|
||||
$form->text('remark');
|
||||
$form->text('pay_image');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerManageSubsidyBatchPay;
|
||||
use App\Admin\Actions\Grid\DealerManageSubsidyPay;
|
||||
use App\Admin\Repositories\DealerManageSubsidy;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Enums\DealerManageSubsidyStatus;
|
||||
use App\Models\DealerManageSubsidy as DealerManageSubsidyModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
|
||||
class DealerManageSubsidyController extends AdminController
|
||||
{
|
||||
protected $title = '管理津贴';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerManageSubsidy::with(['dealer', 'user', 'userinfo', 'earning']);
|
||||
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->settled()->orderBy('id', 'desc');
|
||||
|
||||
$grid->column('settle_period', '结算周期')->display(function () {
|
||||
return $this->start_at->rawFormat('Y/m/d') . '-' . $this->end_at->rawFormat('Y/m/d');
|
||||
})->link(function () {
|
||||
return admin_route('dealer_manage_subsidy_logs.index', [
|
||||
'user[phone]' => $this->user?->phone,
|
||||
'order_completed_at[start]' => $this->start_at->toDateTimeString(),
|
||||
'order_completed_at[end]' => $this->end_at->toDateTimeString(),
|
||||
]);
|
||||
});
|
||||
$grid->column('user.phone', '手机号');
|
||||
$grid->column('userinfo.nickname', '昵称');
|
||||
$grid->column('lvl', '经销商等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('total_amount', '津贴总额')->prepend('¥');
|
||||
$grid->column('fee', '手续费')->prepend('¥')->help('手续费=津贴总额*手续费率');
|
||||
$grid->column('real_amount', '总收入')->prepend('¥')->help('总收入=津贴总额-手续费');
|
||||
$grid->column('fee_rate', '手续费率')->append('%');
|
||||
$grid->column('remark', '备注')->display('查看') // 设置按钮名称
|
||||
->expand(function () {
|
||||
$card = new Card(null, nl2br($this->remark));
|
||||
|
||||
return "<div style='padding:10px 10px 0'>$card</div>";
|
||||
});
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
return $v->text();
|
||||
})->circleDot(DealerManageSubsidyStatus::colors());
|
||||
$grid->column('earning.pay_at', '付款时间');
|
||||
|
||||
$grid->showRowSelector();
|
||||
|
||||
$grid->tools(function ($tools) {
|
||||
$tools->batch(function ($batch) {
|
||||
$batch->disableDelete();
|
||||
|
||||
if (Admin::user()->can('dcat.admin.dealer_manage_subsidies.batch_pay')) {
|
||||
$batch->add(new DealerManageSubsidyBatchPay());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if ($actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_manage_subsidies.pay')) {
|
||||
$actions->append(new DealerManageSubsidyPay());
|
||||
}
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
|
||||
$filter->equal('user.phone', '手机号')->width(3);
|
||||
$filter->equal('status', '状态')->select(DealerManageSubsidyStatus::texts())->width(3);
|
||||
$filter->whereBetween('settle_period', function ($query) {
|
||||
$start = $this->input['start'] ?? null;
|
||||
$end = $this->input['end'] ?? null;
|
||||
|
||||
$query->when($start, function ($query, $start) {
|
||||
$query->where('start_at', '>=', "{$start} 00:00:00");
|
||||
});
|
||||
|
||||
$query->when($end, function ($query, $end) {
|
||||
$query->where('end_at', '<=', "{$end} 23:59:59");
|
||||
});
|
||||
}, '结算周期')->date()->width(6);
|
||||
});
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerManageSubsidyModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$totalAmount = (clone $query)->sum('total_amount');
|
||||
$totalFee = (clone $query)->sum('fee');
|
||||
|
||||
$row->column(3, new InfoBox('津贴总额', $totalAmount, 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('手续费', $totalFee, 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\DealerManageSubsidyLog;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Models\DealerManageSubsidyLog as DealerManageSubsidyLogModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
|
||||
class DealerManageSubsidyLogController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerManageSubsidyLog::with(['user', 'order', 'product']);
|
||||
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->orderBy('id', 'desc');//默认ID倒叙
|
||||
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone', '手机号')->copyable();
|
||||
$grid->column('lvl', '等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('order.sn', '订单编号');
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('sales_volume', '销量');
|
||||
$grid->column('total_amount', '金额');
|
||||
$grid->column('order_completed_at', '结算时间')->sortable();
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerManageSubsidyLogModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$row->column(3, new InfoBox('津贴总额', (clone $query)->sum('total_amount'), 'fa fa-cny'));
|
||||
});
|
||||
$query = DealerManageSubsidyLogModel::query();
|
||||
|
||||
// 拿到表格筛选 where 条件数组进行遍历
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
// 查出统计数据
|
||||
$totalAmount = (clone $query)->sum('total_amount');
|
||||
// 自定义组件
|
||||
return "<div style='padding: 10px;'>金额:".$totalAmount.' 元</div>';
|
||||
});
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel(false);
|
||||
$filter->equal('user.phone', '手机号')->width(3);
|
||||
$filter->between('order_completed_at', '结算时间')->dateTime()->width(7);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new DealerManageSubsidyLog(), function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('user_id');
|
||||
$show->field('lvl');
|
||||
$show->field('order_id');
|
||||
$show->field('product_id');
|
||||
$show->field('sales_volume');
|
||||
$show->field('total_amount');
|
||||
$show->field('order_completed_at');
|
||||
$show->field('created_at');
|
||||
$show->field('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerManageSubsidyLog(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('user_id');
|
||||
$form->text('lvl');
|
||||
$form->text('order_id');
|
||||
$form->text('product_id');
|
||||
$form->text('sales_volume');
|
||||
$form->text('total_amount');
|
||||
$form->text('order_completed_at');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\DealerManagerSalesLog;
|
||||
use App\Models\DealerManagerSalesLog as DealerManagerSalesLogModel;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Show;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerManagerSalesLogController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$builder = DealerManagerSalesLog::with(['user', 'order', 'product']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->orderBy('id', 'desc');//默认ID倒叙
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone', '手机号')->copyable();
|
||||
$grid->column('lvl', '等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('order.sn', '订单编号');
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('sales_volume', '销量');
|
||||
$grid->column('order_completed_at', '结算时间')->sortable();
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
$query = DealerManagerSalesLogModel::query()->with(['product'])
|
||||
->select(['product_id', DB::raw('sum(sales_volume) as sales_volume')]);
|
||||
|
||||
// 拿到表格筛选 where 条件数组进行遍历
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
// 查出统计数据
|
||||
$text = '';
|
||||
foreach ($query->groupBy('product_id')->get() as $log) {
|
||||
if ($text !== '') {
|
||||
$text .= '<br>';
|
||||
}
|
||||
$text .= $log->product->name.'销量:'.$log->sales_volume;
|
||||
}
|
||||
|
||||
// 自定义组件
|
||||
return "<div style='padding: 10px;'>".$text.'</div>';
|
||||
});
|
||||
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel(false);
|
||||
$filter->equal('user.phone', '手机号')->width(4);
|
||||
$filter->between('order_completed_at', '结算时间')->dateTime()->width(4);
|
||||
$filter->between('created_at', '创建时间')->dateTime()->width(4);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new DealerManagerSalesLog(), function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('user_id');
|
||||
$show->field('order_id');
|
||||
$show->field('product_id');
|
||||
$show->field('lvl');
|
||||
$show->field('sales_volume');
|
||||
$show->field('order_completed_at');
|
||||
$show->field('created_at');
|
||||
$show->field('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerManagerSalesLog(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('user_id');
|
||||
$form->text('order_id');
|
||||
$form->text('product_id');
|
||||
$form->text('lvl');
|
||||
$form->text('sales_volume');
|
||||
$form->text('order_completed_at');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerManagerSubsidyBatchPay;
|
||||
use App\Admin\Actions\Grid\DealerManagerSubsidyPay;
|
||||
use App\Admin\Repositories\DealerManagerSubsidy;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Enums\DealerManagerSubsidyStatus;
|
||||
use App\Models\DealerManagerSubsidy as DealerManagerSubsidyModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
|
||||
class DealerManagerSubsidyController extends AdminController
|
||||
{
|
||||
protected $title = '管理者津贴';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerManagerSubsidy::with(['dealer', 'user', 'userinfo', 'earning']);
|
||||
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->settled()->orderBy('id', 'desc');
|
||||
|
||||
$grid->column('settle_period', '结算周期')->display(function () {
|
||||
return $this->start_at->rawFormat('Y/m/d') . '-' . $this->end_at->rawFormat('Y/m/d');
|
||||
})->link(function () {
|
||||
return admin_route('dealer_manager_sales_logs.index', [
|
||||
'user[phone]' => $this->user?->phone,
|
||||
'order_completed_at[start]' => $this->start_at->toDateTimeString(),
|
||||
'order_completed_at[end]' => $this->end_at->toDateTimeString(),
|
||||
]);
|
||||
});
|
||||
$grid->column('user.phone', '手机号');
|
||||
$grid->column('userinfo.nickname', '昵称');
|
||||
$grid->column('is_manager', '管理者')->bool();
|
||||
$grid->column('lvl', '经销商等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('total_amount', '津贴总额')->prepend('¥');
|
||||
$grid->column('fee', '手续费')->prepend('¥')->help('手续费=津贴总额*手续费率');
|
||||
$grid->column('real_amount', '总收入')->prepend('¥')->help('总收入=津贴总额-手续费');
|
||||
$grid->column('fee_rate', '手续费率')->append('%');
|
||||
$grid->column('remark', '备注')->display('查看') // 设置按钮名称
|
||||
->expand(function () {
|
||||
$card = new Card(null, nl2br($this->remark));
|
||||
|
||||
return "<div style='padding:10px 10px 0'>$card</div>";
|
||||
});
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
return $v->text();
|
||||
})->circleDot(DealerManagerSubsidyStatus::colors());
|
||||
$grid->column('earning.pay_at', '付款时间');
|
||||
|
||||
$grid->showRowSelector();
|
||||
|
||||
$grid->tools(function ($tools) {
|
||||
$tools->batch(function ($batch) {
|
||||
$batch->disableDelete();
|
||||
|
||||
if (Admin::user()->can('dcat.admin.dealer_manager_subsidies.batch_pay')) {
|
||||
$batch->add(new DealerManagerSubsidyBatchPay());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if ($actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_manager_subsidies.pay')) {
|
||||
$actions->append(new DealerManagerSubsidyPay());
|
||||
}
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
|
||||
$filter->equal('user.phone', '手机号')->width(3);
|
||||
$filter->equal('status', '状态')->select(DealerManagerSubsidyStatus::texts())->width(3);
|
||||
$filter->whereBetween('settle_period', function ($query) {
|
||||
$start = $this->input['start'] ?? null;
|
||||
$end = $this->input['end'] ?? null;
|
||||
|
||||
$query->when($start, function ($query, $start) {
|
||||
$query->where('start_at', '>=', "{$start} 00:00:00");
|
||||
});
|
||||
|
||||
$query->when($end, function ($query, $end) {
|
||||
$query->where('end_at', '<=', "{$end} 23:59:59");
|
||||
});
|
||||
}, '结算周期')->date()->width(6);
|
||||
});
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerManagerSubsidyModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$totalAmount = (clone $query)->sum('total_amount');
|
||||
$totalFee = (clone $query)->sum('fee');
|
||||
|
||||
$row->column(3, new InfoBox('津贴总额', $totalAmount, 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('手续费', $totalFee, 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,309 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerOrderAllocate;
|
||||
use App\Admin\Actions\Grid\DealerOrderCancel;
|
||||
use App\Admin\Actions\Grid\DealerOrderPaid;
|
||||
use App\Admin\Actions\Grid\DealerOrderRefuse;
|
||||
use App\Admin\Actions\Grid\DealerOrderShipping;
|
||||
use App\Admin\Actions\Show\DealerOrderRemark;
|
||||
use App\Admin\Renderable\Grid\Filter\DealerOrderPayWayIn;
|
||||
use App\Admin\Repositories\DealerOrder;
|
||||
use App\Enums\DealerOrderStatus;
|
||||
use App\Enums\PayWay;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerOrderProduct;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class DealerOrderController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$builder = DealerOrder::with(['user', 'userInfo', 'consignor']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$type = Request::input('type', '');
|
||||
if ($type == 'manager') {
|
||||
$grid->model()->where(function ($query) {
|
||||
return $query->where('consignor_id', 1)->orWhereNull('consignor_id');
|
||||
});
|
||||
}
|
||||
$grid->setResource('dealer-orders');
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('sn');
|
||||
$grid->column('user.phone')->copyable();
|
||||
$grid->column('userInfo.nickname');
|
||||
$grid->column('consignor.phone')->display(function ($value) {
|
||||
return $value ?? '系统';
|
||||
});
|
||||
$grid->column('total_amount')->prepend('¥');
|
||||
$statusTexts = DealerOrderStatus::texts();
|
||||
|
||||
$grid->column('pay_way')->display(function ($v) {
|
||||
return $v?->text();
|
||||
})->circleDot(PayWay::colors())->filter(DealerOrderPayWayIn::make([
|
||||
PayWay::Offline->value => '线下',
|
||||
PayWay::Wallet->value => '钱包',
|
||||
PayWay::WxpayH5->value => '微信支付',
|
||||
]));
|
||||
|
||||
$grid->column('order_status')->display(function ($v) {
|
||||
return $this->order_status;
|
||||
})->using($statusTexts)->dot([
|
||||
DealerOrderStatus::Pending->value => 'primary',
|
||||
DealerOrderStatus::Paying->value => 'danger',
|
||||
DealerOrderStatus::Confirming->value => 'warning',
|
||||
DealerOrderStatus::Paid->value => 'danger',
|
||||
DealerOrderStatus::Shipped->value => 'warning',
|
||||
DealerOrderStatus::Completed->value => 'success',
|
||||
DealerOrderStatus::Cancelled->value => '#b3b9bf',
|
||||
])->filter(Grid\Column\Filter\In::make($statusTexts)->setColumnName('status'));
|
||||
// $grid->column('settle_state');
|
||||
// $grid->column('pay_info');
|
||||
// $grid->column('pay_image');
|
||||
// $grid->column('pay_time');
|
||||
$grid->column('paied_time');
|
||||
// $grid->column('shipping_time');
|
||||
// $grid->column('shippinged_time');
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
// $grid->column('updated_at')->sortable();
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealer_orders.show')) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_orders.show', ['dealer_order'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
// $actions->disableView(false);
|
||||
}
|
||||
if (!(empty($actions->row->consignor) || $actions->row->consignor_id == 1) && $actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_orders.allocate')) {
|
||||
$actions->append(new DealerOrderAllocate());
|
||||
}
|
||||
|
||||
if ((empty($actions->row->consignor))) {
|
||||
if ($actions->row->isPay() && Admin::user()->can('dcat.admin.dealer_orders.paid')) {
|
||||
$actions->append(new DealerOrderPaid());
|
||||
}
|
||||
|
||||
if (
|
||||
$actions->row->isPay() &&
|
||||
$actions->row->isPayWayOffline() &&
|
||||
Admin::user()->can('dcat.admin.dealer_orders.refuse')
|
||||
) {
|
||||
$actions->append(new DealerOrderRefuse());
|
||||
}
|
||||
|
||||
if ($actions->row->isPaid() && Admin::user()->can('dcat.admin.dealer_orders.shipping')) {
|
||||
$actions->append(new DealerOrderShipping());
|
||||
}
|
||||
}
|
||||
if ((
|
||||
$actions->row->isPending() //待确认
|
||||
|| $actions->row->isPendinged() //待付款
|
||||
|| $actions->row->isPay()//待收款
|
||||
) && Admin::user()->can('dcat.admin.dealer_orders.cancel')) {
|
||||
$actions->append(new DealerOrderCancel());
|
||||
}
|
||||
});
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->like('user.phone')->width(3);
|
||||
$filter->like('consignor.phone')->width(3);
|
||||
$filter->like('sn')->width(3);
|
||||
$filter->between('paied_time')->dateTime()->width(5);
|
||||
$filter->between('created_at')->dateTime()->width(5);
|
||||
// $filter->equal('id');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return function (Row $row) use ($id) {
|
||||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = DealerOrder::with(['user', 'userInfo', 'consignor']);
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('sn');
|
||||
$show->field('created_at');
|
||||
$show->field('order_status')->as(function ($v) {
|
||||
return $this->order_status;
|
||||
})->using(DealerOrderStatus::texts())->dot([
|
||||
DealerOrderStatus::Pending->value => 'primary',
|
||||
DealerOrderStatus::Paying->value => 'danger',
|
||||
DealerOrderStatus::Confirming->value => 'warning',
|
||||
DealerOrderStatus::Paid->value => 'danger',
|
||||
DealerOrderStatus::Shipped->value => 'warning',
|
||||
DealerOrderStatus::Completed->value => 'success',
|
||||
DealerOrderStatus::Cancelled->value => '#b3b9bf',
|
||||
]);
|
||||
$show->field('user.phone');
|
||||
$show->field('user_info.nickname');
|
||||
$show->field('consignor.phone')->as(function ($value) {
|
||||
return $value ?? '系统';
|
||||
});
|
||||
$show->field('pay_way', '支付方式')->as(function () {
|
||||
return $this->pay_way?->text();
|
||||
})->circleDot(PayWay::colors());
|
||||
$show->field('pay_sn', '支付流水号');
|
||||
$show->field('pay_time', '支付时间');
|
||||
$show->field('paied_time');
|
||||
if ($show->model()->isPayWayWxpay()) {
|
||||
$show->field('out_trade_no', '外部交易号');
|
||||
} elseif ($show->model()->isPayWayOffline()) {
|
||||
$show->field('pay_image')->image();
|
||||
}
|
||||
$show->field('remark');
|
||||
$show->divider();
|
||||
$show->field('consignee_name');
|
||||
$show->field('consignee_telephone');
|
||||
$show->field('consignee', '收货地址')->as(function () {
|
||||
return $this->consignee_zone . ' '. $this->consignee_address;
|
||||
});
|
||||
|
||||
if (
|
||||
$show->model()->isPayWayOffline() &&
|
||||
!in_array($show->model()->order_status, [
|
||||
DealerOrderStatus::Pending->value, DealerOrderStatus::Cancelled->value,
|
||||
])
|
||||
) {
|
||||
$show->divider('收款信息-银行');
|
||||
$show->field('bank_user_name', '银行-收款人')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['bank']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_name', '银行-名称')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['bank']['bank_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_number', '银行-卡号')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['bank']['bank_number'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_description', '银行-开户行')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['bank']['bank_description'] ?? '';
|
||||
});
|
||||
$show->divider('收款信息-支付宝');
|
||||
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['alipay']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['alipay']['ali_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_image', '支付宝-收款码')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['alipay']['image'] ?? '';
|
||||
})->image();
|
||||
$show->divider('收款信息-微信');
|
||||
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['wechat']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['wechat']['wechat_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_image', '微信-收款码')->as(function () {
|
||||
$payInfo = $this->getConsignorPayInfo();
|
||||
return $payInfo['wechat']['image'] ?? '';
|
||||
})->image();
|
||||
}
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
if (Admin::user()->can('dcat.admin.dealer_orders.remark')) {
|
||||
$tools->append(new DealerOrderRemark());
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
$row->column(7, function ($column) use ($id) {
|
||||
$builder = DealerOrderProduct::where('order_id', $id);
|
||||
$productGrid = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('name');
|
||||
$grid->column('cover', '封面')->image(50, 50);
|
||||
$grid->column('price', '标价')->prepend('¥');
|
||||
$grid->column('sale_price', '实际售价')->prepend('¥');
|
||||
$grid->column('qty', '数量');
|
||||
$grid->column('deposit_qty', '云数量');
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
$grid->disableRefreshButton();
|
||||
});
|
||||
$column->row(Box::make('订单商品', $productGrid));
|
||||
//显示渠道补贴明细
|
||||
// $channelSubsidy = '';
|
||||
$builder = DealerChannelSubsidyLog::with(['user', 'earning'])->where('order_id', $id);
|
||||
$channelSubsidy = Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('user.phone', '手机号');
|
||||
$grid->column('lvl', '等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('total_amount', '补贴金额');
|
||||
$grid->column('remark', '备注');
|
||||
$grid->column('earning.id', '操作')->display(function () {
|
||||
return '查看';
|
||||
})->link(function ($value) {
|
||||
return admin_route('dealer_earnings.show', ['dealer_earning'=>$this->earning->id]);
|
||||
});
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
$grid->disableRefreshButton();
|
||||
});
|
||||
$column->row(Box::make('渠道补贴', $channelSubsidy));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerOrder(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('sn');
|
||||
$form->text('user_id');
|
||||
$form->text('consignor_id');
|
||||
$form->text('total_amount');
|
||||
$form->text('status');
|
||||
$form->text('settle_state');
|
||||
$form->text('consignee_name');
|
||||
$form->text('consignee_telephone');
|
||||
$form->text('consignee_zone');
|
||||
$form->text('consignee_address');
|
||||
$form->text('pay_info');
|
||||
$form->text('pay_image');
|
||||
$form->text('pay_time');
|
||||
$form->text('paied_time');
|
||||
$form->text('shipping_time');
|
||||
$form->text('shippinged_time');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerProductLvlRule as DealerProductLvlRuleAction;
|
||||
use App\Admin\Actions\Grid\DealerProductManageRule as DealerProductManageRuleAction;
|
||||
use App\Admin\Actions\Grid\DealerProductSaleRule as DealerProductSaleRuleAction;
|
||||
use App\Admin\Repositories\DealerProduct;
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\Column;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Show;
|
||||
|
||||
class DealerProductController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new DealerProduct(), function (Grid $grid) {
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('name');
|
||||
$grid->column('unit')->label();
|
||||
// $grid->column('subtitle');
|
||||
$grid->column('cover')->image(80, 80);
|
||||
// $grid->column('images');
|
||||
// $grid->column('description');
|
||||
$grid->column('price')->prepend('¥');
|
||||
$grid->column('manager_subsidy')->prepend('¥');
|
||||
// $grid->column('stock');
|
||||
// $grid->column('sales_count');
|
||||
$grid->column('is_sale')->if(function () {
|
||||
return Admin::user()->can('dcat.admin.dealer_products.edit');
|
||||
})
|
||||
->then(function (Column $column) {
|
||||
$column->switch();
|
||||
})
|
||||
->else(function (Column $column) {
|
||||
$column->bool();
|
||||
});
|
||||
$grid->column('created_at')->sortable();
|
||||
/** 操作 **/
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.dealer_products.create')) {
|
||||
$grid->disableCreateButton(false);
|
||||
}
|
||||
//修改
|
||||
// $grid->showQuickEditButton(Admin::user()->can('dcat.admin.product_spus.edit'));
|
||||
//删除以及自定义操作
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
$actions->disableEdit(Admin::user()->cannot('dcat.admin.dealer_products.edit'));
|
||||
$actions->disableDelete(Admin::user()->cannot('dcat.admin.dealer_products.destroy'));
|
||||
if (Admin::user()->can('dcat.admin.dealers_products.lvl_rules')) {
|
||||
$actions->append(new DealerProductLvlRuleAction());
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.dealers_products.sale_rules')) {
|
||||
$actions->append(new DealerProductSaleRuleAction());
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.dealers_products.manage_rules')) {
|
||||
$actions->append(new DealerProductManageRuleAction());
|
||||
}
|
||||
});
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->equal('name')->width(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new DealerProduct(), function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('name');
|
||||
$show->field('subtitle');
|
||||
$show->field('cover');
|
||||
$show->field('images');
|
||||
$show->field('description');
|
||||
$show->field('price');
|
||||
$show->field('stock');
|
||||
$show->field('sales_count');
|
||||
$show->field('is_sale');
|
||||
$show->field('created_at');
|
||||
$show->field('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerProduct(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('name')->required();
|
||||
$form->text('unit')->required();
|
||||
// $form->text('subtitle');
|
||||
$form->divider();
|
||||
$form->image('cover')
|
||||
->move('dealer-products/cover/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->retainable()
|
||||
->autoUpload()->retainable();
|
||||
$form->multipleImage('images')
|
||||
->move('dealer-products/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->retainable()
|
||||
->autoUpload()->retainable();
|
||||
$form->editor('description');
|
||||
$form->currency('price')->symbol('¥')->required();
|
||||
$form->currency('manager_subsidy')->symbol('¥')->required();
|
||||
// $form->text('stock');
|
||||
// $form->text('sales_count');
|
||||
$form->switch('is_sale');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Repositories\DealerPurchaseLog;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Models\DealerPurchaseLog as DealerPurchaseLogModel;
|
||||
use App\Models\User;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class DealerPurchaseLogController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerPurchaseLog::with(['user', 'order']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$phone = Request::input('user_phone', '');
|
||||
// dd($phone);
|
||||
if ($phone) {
|
||||
$user = User::where('phone', $phone)->first();
|
||||
if ($user) {
|
||||
$grid->model()->where('path', 'like', '%-'.$user->id.'-%');
|
||||
} else {
|
||||
//不存的手机号查询数据置为空
|
||||
$grid->model()->where('id', 0);
|
||||
}
|
||||
}
|
||||
$grid->model()->orderBy('id', 'desc');//默认ID倒叙
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone', '手机号')->copyable();
|
||||
$grid->column('lvl', '等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('order.sn', '订单编号');
|
||||
$grid->column('total_amount');
|
||||
$grid->column('remark');
|
||||
$grid->column('order_completed_at', '结算时间')->sortable();
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerPurchaseLogModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$row->column(3, new InfoBox('进货业绩', (clone $query)->sum('total_amount'), 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel(false);
|
||||
$filter->equal('user_phone', '手机号')->ignore()->width(4);
|
||||
$filter->between('order_completed_at', '结算时间')->dateTime()->width(4);
|
||||
$filter->between('created_at', '创建时间')->dateTime()->width(4);
|
||||
|
||||
// $filter->equal('user.phone', '手机号')->width(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new DealerPurchaseLog(), function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('user_id');
|
||||
$show->field('order_id');
|
||||
$show->field('lvl');
|
||||
$show->field('total_amount');
|
||||
$show->field('remark');
|
||||
$show->field('order_completed_at');
|
||||
$show->field('created_at');
|
||||
$show->field('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerPurchaseLog(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('user_id');
|
||||
$form->text('order_id');
|
||||
$form->text('lvl');
|
||||
$form->text('total_amount');
|
||||
$form->text('remark');
|
||||
$form->text('order_completed_at');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,188 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\DealerPurchaseSubsidyBatchPay;
|
||||
use App\Admin\Actions\Grid\DealerPurchaseSubsidyPay;
|
||||
use App\Admin\Repositories\DealerPurchaseSubsidy;
|
||||
use App\Admin\Repositories\DealerPurchaseSubsidyLog;
|
||||
use App\Admin\Widgets\InfoBox;
|
||||
use App\Enums\DealerPurchaseSubsidyStatus;
|
||||
use App\Models\DealerPurchaseSubsidy as DealerPurchaseSubsidyModel;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
|
||||
class DealerPurchaseSubsidyController extends AdminController
|
||||
{
|
||||
protected $title = '进货补贴';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
Admin::style(
|
||||
<<<CSS
|
||||
.card-header {
|
||||
margin-top: 1.5rem !important;
|
||||
margin-bottom: -1rem !important;
|
||||
}
|
||||
CSS
|
||||
);
|
||||
|
||||
$builder = DealerPurchaseSubsidy::with(['user.userInfo']);
|
||||
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->model()->settleCompleted()->orderBy('id', 'desc');//默认ID倒叙
|
||||
|
||||
$grid->column('settle_period', '结算周期')->display(function () {
|
||||
return $this->start_at->rawFormat('Y/m/d') . '-' . $this->end_at->rawFormat('Y/m/d');
|
||||
})->link(function () {
|
||||
return admin_route('dealer_purchase_logs.index', [
|
||||
'user_phone' => $this->user?->phone,
|
||||
'order_completed_at[start]' => $this->start_at->toDateTimeString(),
|
||||
'order_completed_at[end]' => $this->end_at->toDateTimeString(),
|
||||
]);
|
||||
});
|
||||
$grid->column('user.phone', '手机号')->copyable();
|
||||
$grid->column('user.userInfo.nickname', '昵称');
|
||||
$grid->column('lvl', '等级')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$grid->column('total_purchase_amount', '进货业绩')->prepend('¥');
|
||||
$grid->column('subsidy_rate', '补贴比例')->append('%');
|
||||
$grid->column('total_subsidy', '补贴总额')->prepend('¥')->help('补贴总额=进货业绩*补贴比例');
|
||||
$grid->column('total_amount', '应得补贴')->prepend('¥');
|
||||
$grid->column('fee_rate', '手续费率')->append('%');
|
||||
$grid->column('fee', '手续费')->prepend('¥')->help('手续费=应得补贴*手续费率');
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
return $v->text();
|
||||
})->circleDot(DealerPurchaseSubsidyStatus::colors());
|
||||
|
||||
$grid->showRowSelector();
|
||||
$grid->tools(function ($tools) {
|
||||
$tools->batch(function ($batch) {
|
||||
$batch->disableDelete();
|
||||
|
||||
if (Admin::user()->can('dcat.admin.dealer_purchase_subsidies.batch_pay')) {
|
||||
$batch->add(new DealerPurchaseSubsidyBatchPay());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealer_purchase_subsidies.show')) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_purchase_subsidies.show', ['dealer_purchase_subsidy' => $actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
}
|
||||
|
||||
if ($actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_purchase_subsidies.pay')) {
|
||||
$actions->append(new DealerPurchaseSubsidyPay());
|
||||
}
|
||||
});
|
||||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = DealerPurchaseSubsidyModel::query();
|
||||
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
|
||||
$row->column(3, new InfoBox('进货业绩', (clone $query)->sum('total_purchase_amount'), 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('补贴金额', (clone $query)->sum('total_amount'), 'fa fa-cny'));
|
||||
$row->column(3, new InfoBox('手续费', (clone $query)->sum('fee'), 'fa fa-cny'));
|
||||
});
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
|
||||
$filter->equal('user.phone', '手机号')->width(3);
|
||||
$filter->equal('status', '状态')->select(DealerPurchaseSubsidyStatus::texts())->width(3);
|
||||
$filter->whereBetween('settle_period', function ($query) {
|
||||
$start = $this->input['start'] ?? null;
|
||||
$end = $this->input['end'] ?? null;
|
||||
|
||||
$query->when($start, function ($query, $start) {
|
||||
$query->where('start_at', '>=', "{$start} 00:00:00");
|
||||
});
|
||||
|
||||
$query->when($end, function ($query, $end) {
|
||||
$query->where('end_at', '<=', "{$end} 23:59:59");
|
||||
});
|
||||
}, '结算周期')->date()->width(6);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$row = new Row();
|
||||
|
||||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = DealerPurchaseSubsidy::with(['user.userInfo']);
|
||||
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('settle_period', '结算周期')->as(function () {
|
||||
return $this->start_at->rawFormat('Y/m/d') . '-' . $this->end_at->rawFormat('Y/m/d');
|
||||
});
|
||||
$show->field('user.phone', '手机号');
|
||||
$show->field('user.user_info.nickname', '昵称');
|
||||
$show->field('lvl', '经销商等级')->as(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
$show->field('total_purchase_amount', '进货业绩')->prepend('¥');
|
||||
$show->field('subsidy_rate', '补贴比例')->append('%');
|
||||
$show->field('total_subsidy', '补贴总额')->prepend('¥');
|
||||
$show->field('total_amount', '应得补贴')->prepend('¥');
|
||||
$show->field('fee_rate', '手续费率')->append('%');
|
||||
$show->field('fee', '手续费')->prepend('¥');
|
||||
$show->field('real_amount', '实得补贴')->prepend('¥');
|
||||
$show->field('status', '状态')->as(function () {
|
||||
return $this->status?->text();
|
||||
})->circleDot(DealerPurchaseSubsidyStatus::colors());
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
});
|
||||
}));
|
||||
});
|
||||
$row->column(7, function ($column) use ($id) {
|
||||
$dealerPurchaseSubsidyLogBox = Box::make('补贴明细', Grid::make(DealerPurchaseSubsidyLog::class, function (Grid $grid) use ($id) {
|
||||
$grid->model()->where('purchase_subsidy_id', $id);
|
||||
|
||||
$grid->column('id');
|
||||
$grid->column('change_amount', '变更金额');
|
||||
$grid->column('remark', '备注');
|
||||
$grid->column('created_at', '结算时间');
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
$grid->disableRefreshButton();
|
||||
}));
|
||||
|
||||
$column->row($dealerPurchaseSubsidyLogBox);
|
||||
});
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,243 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\Exports\DealerWalletWithdraw;
|
||||
use App\Admin\Actions\Show\DealerWalletPay;
|
||||
use App\Admin\Actions\Show\DealerWalletRefuse;
|
||||
use App\Admin\Repositories\DealerWalletToBankLog;
|
||||
use App\Enums\DealerWalletToBankLogStatus;
|
||||
use App\Models\DealerWalletToBankLog as DealerWalletToBankLogModel;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Show;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class DealerWalletToBankLogController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$builder = DealerWalletToBankLog::with(['user', 'manager.userInfo']);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->tools(function (Grid\Tools $tools) {
|
||||
$tools->append(new DealerWalletWithdraw());
|
||||
});
|
||||
$grid->column('id')->sortable();
|
||||
$grid->column('user.phone');
|
||||
$grid->column('amount')->prepend('¥');
|
||||
$grid->column('rate')->append('%');
|
||||
$grid->column('service_amount')->prepend('¥');
|
||||
$grid->column('account_amount')->prepend('¥');
|
||||
$grid->column('manager_id')->display(function () {
|
||||
if ($this->manager) {
|
||||
$href = admin_route('dealers.show', ['dealer_user' => $this->manager->id]);
|
||||
|
||||
return "<a href=\"{$href}\" target=\"_blank\">{$this->manager->userInfo->nickname}</a>";
|
||||
}
|
||||
});
|
||||
$grid->column('status')->display(function ($v) {
|
||||
$text = $v->text();
|
||||
$background = $v->color();
|
||||
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$background}'></i> {$text}";
|
||||
})->filter(Grid\Column\Filter\In::make(Arr::except(DealerWalletToBankLogStatus::texts(), [
|
||||
DealerWalletToBankLogStatus::Failed->value,
|
||||
DealerWalletToBankLogStatus::Passed->value,
|
||||
DealerWalletToBankLogStatus::Paying->value,
|
||||
])));
|
||||
$grid->column('remarks');
|
||||
$grid->column('created_at')->sortable();
|
||||
// $grid->column('updated_at')
|
||||
$grid->model()->orderBy('status', 'asc');
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
|
||||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||||
if (Admin::user()->can('dcat.admin.dealer_wallet_to_bank_logs.show')) {
|
||||
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_wallet_to_bank_logs.show', ['dealer_wallet_to_bank_log'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
||||
}
|
||||
});
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->equal('user.phone')->width(3);
|
||||
$filter->between('created_at')->dateTime()->width(7);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$builder = DealerWalletToBankLog::with(['user', 'manager.userInfo']);
|
||||
return Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('id');
|
||||
$show->field('user.phone');
|
||||
$show->field('amount')->prepend('¥');
|
||||
$show->field('rate')->append('%');
|
||||
$show->field('service_amount')->prepend('¥');
|
||||
$show->field('account_amount')->prepend('¥');
|
||||
$show->field('manager_id')->unescape()->as(function () {
|
||||
if ($this->manager) {
|
||||
$href = admin_route('dealers.show', ['dealer_user' => $this->manager->id]);
|
||||
|
||||
return "<a href=\"{$href}\" target=\"_blank\">{$this->manager->userInfo->nickname}</a>";
|
||||
}
|
||||
});
|
||||
$show->field('status')->unescape()->as(function ($v) {
|
||||
$text = $this->status->text();
|
||||
$background = $this->status->color();
|
||||
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$background}'></i> {$text}";
|
||||
});
|
||||
$show->field('pay_image')->image();
|
||||
$show->field('remarks');
|
||||
if ($show->model()->isFailed()) {
|
||||
$show->field('failed_reason');
|
||||
}
|
||||
$show->divider('收款信息-银行');
|
||||
$show->field('bank_user_name', '银行-收款人')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_name', '银行-名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_name'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_number', '银行-卡号')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_number'] ?? '';
|
||||
});
|
||||
$show->field('bank_bank_description', '银行-开户行')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['bank']['bank_description'] ?? '';
|
||||
});
|
||||
$show->divider('收款信息-支付宝');
|
||||
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['ali_name'] ?? '';
|
||||
});
|
||||
$show->field('alipay_image', '支付宝-收款码')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['alipay']['image'] ?? '';
|
||||
})->image();
|
||||
$show->divider('收款信息-微信');
|
||||
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['user_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['wechat_name'] ?? '';
|
||||
});
|
||||
$show->field('wechat_image', '微信-收款码')->as(function () {
|
||||
$payInfo = $this->getPayInfo();
|
||||
return $payInfo['wechat']['image'] ?? '';
|
||||
})->image();
|
||||
$show->field('created_at');
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
|
||||
if (in_array($show->model()->status, [DealerWalletToBankLogStatus::Pending, DealerWalletToBankLogStatus::Failed]) && Admin::user()->can('dcat.admin.dealer_wallet_to_bank_logs.verify')) {
|
||||
$tools->append(new DealerWalletRefuse());
|
||||
$tools->append(new DealerWalletPay());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new DealerWalletToBankLog(), function (Form $form) {
|
||||
$form->display('id');
|
||||
$form->text('user_id');
|
||||
$form->text('amount');
|
||||
$form->text('rate');
|
||||
$form->text('service_amount');
|
||||
$form->text('account_amount');
|
||||
$form->text('status');
|
||||
$form->text('remarks');
|
||||
|
||||
$form->display('created_at');
|
||||
$form->display('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
return response()->streamDownload(function () use ($request) {
|
||||
$writer = WriterEntityFactory::createXLSXWriter();
|
||||
$writer->openToBrowser('打款单'.date('Ymd').'.xlsx');
|
||||
$writer->addRow(WriterEntityFactory::createRowFromArray([
|
||||
'提现手机号', '打款金额', '状态', '收款人', '收款银行', '收款账号', '开户行', '提现时间',
|
||||
]));
|
||||
$query = DealerWalletToBankLogModel::with('dealer', 'user');
|
||||
foreach ($request->input() as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'created_at':
|
||||
if ($value['start'] || $value['end']) {
|
||||
$query->whereBetween('created_at', $value);
|
||||
}
|
||||
break;
|
||||
case 'status':
|
||||
if ($value) {
|
||||
$query->where('status', $value);
|
||||
}
|
||||
break;
|
||||
case 'user':
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $kk =>$vv) {
|
||||
$query->whereHas($key, function ($q) use ($kk, $vv) {
|
||||
if ($vv) {
|
||||
$q->where($kk, $vv);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($query->cursor() as $log) {
|
||||
$payInfo = $log->getPayInfo();
|
||||
$writer->addRow(WriterEntityFactory::createRowFromArray([
|
||||
$log->user->phone,
|
||||
$log->account_amount,
|
||||
$log->status->text(),
|
||||
$payInfo ? $payInfo['bank']['user_name'] : '',
|
||||
$payInfo ? $payInfo['bank']['bank_name'] : '',
|
||||
$payInfo ? $payInfo['bank']['bank_number'] : '',
|
||||
$payInfo ? $payInfo['bank']['bank_description'] : '',
|
||||
$log->created_at->toDateTimeString(),
|
||||
]));
|
||||
};
|
||||
$writer->close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -8,13 +8,10 @@ use App\Admin\Metrics\Orders;
|
|||
use App\Admin\Metrics\StatisticsTotal;
|
||||
use App\Admin\Metrics\Users;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Admin\Layout\Menu as ActiveMenu;
|
||||
use App\Models\Admin\Menu;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Layout\Column;
|
||||
use Dcat\Admin\Layout\Content;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
|
|
@ -44,18 +41,4 @@ class HomeController extends Controller
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
// public function test(Request $request)
|
||||
// {
|
||||
// $menus = (new Menu())->fetchAll();
|
||||
// $activeMenu = new ActiveMenu();
|
||||
// foreach ($menus as $menu) {
|
||||
// dump([
|
||||
// 'title' => $menu->title,
|
||||
// 'uri' => $menu->uri,
|
||||
// ]);
|
||||
// dump($activeMenu->isActive($menu->toArray(), 'dealer-earnings-manage?filter-earningable_type%5B0%5D=dealer_manage_subsidy&_pjax=%23pjax-container&page=2'));
|
||||
// }
|
||||
// dd(123465);
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ namespace App\Admin\Controllers;
|
|||
use App\Admin\Forms\Settings\Android;
|
||||
use App\Admin\Forms\Settings\App;
|
||||
use App\Admin\Forms\Settings\Custom;
|
||||
use App\Admin\Forms\Settings\Dealer;
|
||||
use App\Admin\Forms\Settings\Distribution;
|
||||
use App\Admin\Forms\Settings\Ios;
|
||||
use App\Admin\Forms\Settings\Kuaidi100;
|
||||
use App\Admin\Forms\Settings\Unipush;
|
||||
|
|
@ -112,8 +110,6 @@ class SettingController extends AdminController
|
|||
switch ($type) {
|
||||
case 'app':
|
||||
$tab->add('系统配置', new App(), true);
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
|
|
@ -123,19 +119,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'distribution':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
$tab->add('会员奖励配置', new Distribution(), true);
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
$tab->addLink('快递100配置', admin_route('settings.index', ['type'=>'kuaidi100']));
|
||||
$tab->addLink('Uni-push配置', admin_route('settings.index', ['type'=>'unipush']));
|
||||
$tab->addLink('自定义配置', admin_route('settings.index', ['type'=>'custom']));
|
||||
break;
|
||||
case 'dealer':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->add('经销商配置', new Dealer(), true);
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
@ -145,8 +128,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'withdraw':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->add('提现配置', new Withdraw(), true);
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
@ -156,8 +137,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'ios':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->add('Ios配置', new Ios(), true);
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
@ -167,8 +146,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'android':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->add('Android配置', new Android(), true);
|
||||
|
|
@ -178,8 +155,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'kuaidi100':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
@ -189,8 +164,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'unipush':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
@ -200,8 +173,6 @@ class SettingController extends AdminController
|
|||
break;
|
||||
case 'custom':
|
||||
$tab->addLink('系统配置', admin_route('settings.index', ['type'=>'app']));
|
||||
// $tab->addLink('会员奖励配置', admin_route('settings.index', ['type'=>'distribution']));
|
||||
$tab->addLink('经销商配置', admin_route('settings.index', ['type'=>'dealer']));
|
||||
$tab->addLink('提现配置', admin_route('settings.index', ['type'=>'withdraw']));
|
||||
$tab->addLink('Ios配置', admin_route('settings.index', ['type'=>'ios']));
|
||||
$tab->addLink('Android配置', admin_route('settings.index', ['type'=>'android']));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ use App\Admin\Renderable\UserSalesValueLogSimpleTable;
|
|||
use App\Admin\Renderable\UserWalletLogSimpleTable;
|
||||
use App\Admin\Repositories\User;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\Order;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Models\UserInfo;
|
||||
|
|
@ -287,10 +286,6 @@ class UserController extends AdminController
|
|||
if (Order::where('user_id', $user->id)->exists()) {
|
||||
throw new BizException('该用户存在商城订单');
|
||||
}
|
||||
//判断是否有批零订单
|
||||
if (DealerOrder::where('user_id', $user->id)->orWhere('consignor_id', $user->id)->exists()) {
|
||||
throw new BizException('该用户存在批零订单');
|
||||
}
|
||||
//抹除用户手机号
|
||||
$user->update([
|
||||
'phone'=>null,
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Models\Dealer;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerBonds extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.bonds');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
$dealer->update([
|
||||
'bonds'=>$input['bonds'],
|
||||
]);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->currency('bonds')->required();
|
||||
}
|
||||
|
||||
public function default()
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
return [
|
||||
'bonds'=>$dealer->bonds,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerEarningPay extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_earnings.pay');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$earning = DealerEarning::findOrFail($id);
|
||||
$earning->update([
|
||||
'pay_way' => DealerEarning::PAY_WAY_WALLET,
|
||||
'pay_info' => $earning->getPayInfo(),
|
||||
'pay_image' => $input['pay_image'] ?? null,
|
||||
'pay_at' => now(),
|
||||
'status' => DealerEarningStatus::Completed,
|
||||
]);
|
||||
//打款到余额;
|
||||
$walletService = new WalletService();
|
||||
switch ($earning->earningable_type) {
|
||||
case (new DealerManagerSubsidy())->getMorphClass():
|
||||
$action = DealerWalletAction::ManagerSubsidyIn;
|
||||
break;
|
||||
case (new DealerManageSubsidy())->getMorphClass():
|
||||
$action = DealerWalletAction::ManageSubsidyIn;
|
||||
break;
|
||||
case (new DealerChannelSubsidyLog())->getMorphClass():
|
||||
$action = DealerWalletAction::ChannelSubsidyIn;
|
||||
break;
|
||||
default:
|
||||
$action = DealerWalletAction::PurchaseSubsidyIn;
|
||||
break;
|
||||
}
|
||||
|
||||
$walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->earningable_type_text, $earning);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->image('pay_image')
|
||||
->move('dealer-pay/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->autoUpload();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\UserInfo;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerEditLvl extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.edit_lvl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
if ($dealer?->lvl->value >= $input['lvl']) {
|
||||
throw new BizException('请选择大于当前的等级');
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
//执行自己升级
|
||||
$dealer->upgrade(DealerLvl::from($input['lvl']), '后台修改等级');
|
||||
//执行上级尝试升级
|
||||
foreach ($dealer->getDealers() as $parentDealer) {
|
||||
$parentDealer->attemptUpgrade();
|
||||
}
|
||||
// $dealer->update([
|
||||
// 'lvl'=>$input['lvl'],
|
||||
// ]);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
// dd(UserInfo::$agentLevelTexts);
|
||||
$this->select('lvl', '经销商级别')->options(DealerLvl::texts())
|
||||
->help('请选择大于当前的身份')
|
||||
->required();
|
||||
}
|
||||
|
||||
public function default()
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
$dealer = Dealer::findOrFail($id);
|
||||
return [
|
||||
'lvl' => $dealer->lvl->value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerUserProduct;
|
||||
use App\Models\DealerUserProductLog;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerEditProduct extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.edit_product');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$product = DealerUserProduct::where([
|
||||
'user_id' => $id,
|
||||
'product_id'=>$input['product_id'],
|
||||
])->first();
|
||||
switch ($input['type']) {
|
||||
case DealerUserProductLog::TYPE_ADMIN_IN:
|
||||
if (!$product) {
|
||||
$product = DealerUserProduct::create([
|
||||
'user_id' => $id,
|
||||
'product_id'=>$input['product_id'],
|
||||
]);
|
||||
}
|
||||
$product->increment('stock', $input['qty']);
|
||||
break;
|
||||
case DealerUserProductLog::TYPE_ADMIN_OUT:
|
||||
if (!$product) {
|
||||
throw new BizException('库存不足');
|
||||
}
|
||||
$product->decrement('stock', $input['qty']);
|
||||
break;
|
||||
}
|
||||
DealerUserProductLog::create([
|
||||
'user_id'=> $id,
|
||||
'product_id'=> $input['product_id'],
|
||||
'type' => $input['type'],
|
||||
'qty'=>$input['qty'],
|
||||
'remark'=>'后台改动:'.$input['remark'] ?? null,
|
||||
]);
|
||||
DB::commit();
|
||||
} catch (QueryException $e) {
|
||||
DB::rollBack();
|
||||
if (strpos($e->getMessage(), 'Numeric value out of range') !== false) {
|
||||
$e = new BizException('库存不足');
|
||||
}
|
||||
throw $e;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->radio('type', '操作')->options([
|
||||
DealerUserProductLog::TYPE_ADMIN_IN =>'添加',
|
||||
DealerUserProductLog::TYPE_ADMIN_OUT=>'扣减',
|
||||
])->required();
|
||||
$this->select('product_id', '商品')->options(DealerProduct::all()->pluck('name', 'id'))
|
||||
->required();
|
||||
$this->number('qty', '数量')->default(1)->min(1);
|
||||
$this->text('remark', '备注')->default('调整库存');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerOrderStatus;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderRefuse extends Form
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
try {
|
||||
$id = $this->payload['id'] ?? null;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$order = DealerOrder::lockForUpdate()->findOrFail($id);
|
||||
|
||||
if (! $order->isPayWayOffline()) {
|
||||
throw new BizException('订单付款方式不是线下打款');
|
||||
}
|
||||
|
||||
if (! $order->isPay()) {
|
||||
throw new BizException('无法收款:订单状态异常,请刷新后再试');
|
||||
}
|
||||
|
||||
$order->update([
|
||||
'status' => DealerOrderStatus::Paying,
|
||||
//置空已支付的信息
|
||||
'pay_way'=> null,
|
||||
'pay_image'=> null,
|
||||
'pay_info' => null,
|
||||
'pay_time' => null,
|
||||
]);
|
||||
|
||||
$order->refuseLogs()->create([
|
||||
'reason' => $input['reason'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
report($e);
|
||||
|
||||
return $this->response()->error('操作失败,'.$e->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this
|
||||
->response()
|
||||
->success('操作成功')
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->textarea('reason', '原因')->required()->rules('required|max:255');
|
||||
}
|
||||
|
||||
/**
|
||||
* The data of the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default()
|
||||
{
|
||||
return [
|
||||
'reason' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderRemark extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_orders.remark');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = DealerOrder::findOrFail($orderId);
|
||||
|
||||
$remark = $input['remark']??'';
|
||||
// try {
|
||||
// DB::beginTransaction();
|
||||
$order->update([
|
||||
'remark'=> $remark,
|
||||
]);
|
||||
// DB::commit();
|
||||
// } catch (Throwable $th) {
|
||||
// DB::rollBack();
|
||||
// report($th);
|
||||
// throw new BizException('操作失败:'.$th->getMessage());
|
||||
// }
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = DealerOrder::findOrFail($orderId);
|
||||
|
||||
$this->text('remark')->required()->value($order->remark);
|
||||
|
||||
$this->disableResetButton();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerProductLvlRule as DealerProductLvlRuleModel;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Form\NestedForm;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerProductLvlRule extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.lvl_rules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
$lvlRules = [];
|
||||
$delRules = [];
|
||||
foreach ($input['lvlRules'] as $rule) {
|
||||
if ($rule['_remove_'] == 1) {
|
||||
$delRules[] = $rule['id'];
|
||||
} else {
|
||||
if (is_null($rule['id'])) {
|
||||
$lvlRules[] = new DealerProductLvlRuleModel($rule);
|
||||
} else {
|
||||
$_rule = DealerProductLvlRuleModel::find($rule['id']);
|
||||
$_rule['lvl'] = $rule['lvl'];
|
||||
$_rule['sale_price'] = $rule['sale_price'];
|
||||
// $_rule['min_order_amount'] = $rule['min_order_amount'];
|
||||
$lvlRules[] = $_rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$product->lvlRules()->saveMany($lvlRules);
|
||||
|
||||
DealerProductLvlRuleModel::whereIn('id', $delRules)->delete();
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->hasMany('lvlRules', '等级规则', function (NestedForm $form) {
|
||||
$form->select('lvl')->options([
|
||||
2 => '金牌经销商',
|
||||
3 => '特邀经销商',
|
||||
4 => '签约经销商',
|
||||
5 => '二级经销商',
|
||||
6 => '一级经销商',
|
||||
]);
|
||||
$form->currency('sale_price', '等级进货单价')->symbol('¥');
|
||||
// $form->currency('min_order_amount', '等级单次最低进货价')->symbol('¥');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The data of the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default()
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
return [
|
||||
'lvlRules' => $product->lvlRules,
|
||||
// 'email' => 'John.Doe@gmail.com',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerProductManageRule as DealerProductManageRuleModel;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Form\NestedForm;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerProductManageRule extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.manage_rules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
$manageRules = [];
|
||||
$delRules = [];
|
||||
foreach ($input['manageRules'] as $rule) {
|
||||
if ($rule['_remove_'] == 1) {
|
||||
$delRules[] = $rule['id'];
|
||||
} else {
|
||||
if (is_null($rule['id'])) {
|
||||
$manageRules[] = new DealerProductManageRuleModel($rule);
|
||||
} else {
|
||||
$_rule = DealerProductManageRuleModel::find($rule['id']);
|
||||
$_rule['lvl'] = $rule['lvl'];
|
||||
$_rule['price_1st'] = $rule['price_1st'];
|
||||
$_rule['price_2st'] = $rule['price_2st'];
|
||||
$_rule['price_3st'] = $rule['price_3st'];
|
||||
$manageRules[] = $_rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$product->lvlRules()->saveMany($manageRules);
|
||||
|
||||
DealerProductManageRuleModel::whereIn('id', $delRules)->delete();
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->hasMany('manageRules', '管理规则', function (NestedForm $form) {
|
||||
$form->select('lvl')->options([
|
||||
5 => '二级经销商',
|
||||
6 => '一级经销商',
|
||||
]);
|
||||
$form->currency('price_1st', '价格1')->symbol('¥')->required();
|
||||
$form->currency('price_2st', '价格2')->symbol('¥')->required();
|
||||
$form->currency('price_3st', '价格3')->symbol('¥')->required();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The data of the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default()
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
return [
|
||||
'manageRules' => $product->manageRules,
|
||||
// 'email' => 'John.Doe@gmail.com',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerProductSaleRule as DealerProductSaleRuleModel;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Form\NestedForm;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerProductSaleRule extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_products.sale_rules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
$saleRules = [];
|
||||
$delRules = [];
|
||||
foreach ($input['saleRules'] as $rule) {
|
||||
if ($rule['_remove_'] == 1) {
|
||||
$delRules[] = $rule['id'];
|
||||
} else {
|
||||
if (is_null($rule['id'])) {
|
||||
$saleRules[] = new DealerProductSaleRuleModel($rule);
|
||||
} else {
|
||||
$_rule = DealerProductSaleRuleModel::find($rule['id']);
|
||||
$_rule['qty'] = $rule['qty'];
|
||||
$_rule['price'] = $rule['price'];
|
||||
$saleRules[] = $_rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$product->saleRules()->saveMany($saleRules);
|
||||
|
||||
DealerProductSaleRuleModel::whereIn('id', $delRules)->delete();
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage())->refresh();
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->hasMany('saleRules', '销售规则', function (NestedForm $form) {
|
||||
$form->number('qty', '达到数量')->min(0);
|
||||
$form->currency('price', '进货单价')->symbol('¥');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The data of the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default()
|
||||
{
|
||||
$productId = $this->payload['id'] ?? 0;
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
return [
|
||||
'saleRules' => $product->saleRules,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Models\Dealer;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerWalletChange extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealers.wallet_change');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
if (bccomp($input['change_balance'], '0', 2) <= 0) {
|
||||
return $this->response()->error('金额必须大于0');
|
||||
}
|
||||
|
||||
$dealer = Dealer::findOrFail($this->payload['id']);
|
||||
|
||||
$action = DealerWalletAction::from($input['action']);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealer->user,
|
||||
match ($action) {
|
||||
DealerWalletAction::Recharge => bcmul($input['change_balance'], '1', 2),
|
||||
DealerWalletAction::Deduct => bcmul($input['change_balance'], '-1', 2),
|
||||
},
|
||||
$action,
|
||||
$input['remarks'],
|
||||
Admin::user()
|
||||
);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
||||
report($th);
|
||||
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->radio('action', '操作')
|
||||
->options([
|
||||
DealerWalletAction::Recharge->value => '充值',
|
||||
DealerWalletAction::Deduct->value => '扣除',
|
||||
])
|
||||
->default(DealerWalletAction::Recharge->value)
|
||||
->required();
|
||||
$this->currency('change_balance', '金额')->symbol('¥')->required();
|
||||
$this->textarea('remarks', '备注')->required();
|
||||
$this->confirm('是否确认充值?', '提交后该动作无法逆转');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerWalletToBankLogPayWay;
|
||||
use App\Enums\DealerWalletToBankLogStatus;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerWalletToBankLog;
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerWalletPay extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.verify');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$log = DealerWalletToBankLog::lockForUpdate()->findOrFail($id);
|
||||
|
||||
if (! in_array($log->status, [DealerWalletToBankLogStatus::Pending, DealerWalletToBankLogStatus::Failed])) {
|
||||
throw new BizException('提现记录状态异常');
|
||||
}
|
||||
|
||||
$log->pay_info = $log->user->dealer->pay_info;
|
||||
$log->pay_image = $input['pay_image'] ?? null;
|
||||
$log->pay_way = DealerWalletToBankLogPayWay::Offline;
|
||||
$log->pay_at = now();
|
||||
$log->status = DealerWalletToBankLogStatus::Success;
|
||||
$log->save();
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->image('pay_image')
|
||||
->move('dealer-pay/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->autoUpload();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Enums\DealerWalletToBankLogStatus;
|
||||
use App\Models\DealerWalletToBankLog;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerWalletRefuse extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.dealer_wallet_to_bank_logs.verify');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$id = $this->payload['id'] ?? 0;
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$log = DealerWalletToBankLog::findOrFail($id);
|
||||
$log->update([
|
||||
'remark' => $input['remark'] ?? '',
|
||||
'status' => DealerWalletToBankLogStatus::Refused,
|
||||
]);
|
||||
//打回余额
|
||||
$walletService = new WalletService();
|
||||
$walletService->changeBalance($log->user, $log->amount, DealerWalletAction::WithdrawFiled, '提现-失败', $log);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->text('remarks', '备注')->required();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms\Settings;
|
||||
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Models\Setting;
|
||||
use App\Services\SettingService;
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
|
||||
class Dealer extends Form
|
||||
{
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
// dd($input);
|
||||
Setting::where('key', 'dealer')->updateOrCreate([
|
||||
'key' => 'dealer',
|
||||
], ['value' => $input]);
|
||||
|
||||
//清配置缓存
|
||||
app(SettingService::class)->cleanCache('dealer');
|
||||
|
||||
return $this
|
||||
->response()
|
||||
->success('配置更新成功!')
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$this->switch('wxpay_switch', '微信支付');
|
||||
$this->currency('delivery_bill_shipping_fee', '云仓运费')->symbol('¥');
|
||||
$this->currency('fee_rate', '手续费比例(百分比)')->symbol('%');
|
||||
$this->number('withdraw_threshold_amount', '起提金额(元)');
|
||||
$this->currency('withdraw_fee_rate', '提现费率')->symbol('%');
|
||||
$this->number('withdraw_days', '提现间隔');
|
||||
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌升级门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀升级门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约升级门槛')->symbol('¥');
|
||||
|
||||
$this->currency('min_order_amount_'.DealerLvl::Gold->value, '金牌单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Special->value, '特邀单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Contracted->value, '签约单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Secondary->value, '二级签约单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Top->value, '一级签约单次进货最低金额')->symbol('¥');
|
||||
|
||||
$this->number('order_auto_allocate_times', '订单自动分配时间(分)')->min(1);
|
||||
|
||||
$this->divider('签约->签约->签约');
|
||||
$this->currency('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Contracted->value.'.'.DealerLvl::Contracted->value.'_0', '签约0')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Contracted->value.'.'.DealerLvl::Contracted->value.'_1', '签约1')->symbol('¥');
|
||||
$this->divider('签约->特邀->签约->签约');
|
||||
$this->currency('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Special->value.'.'.DealerLvl::Special->value.'_0', '特邀0')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Special->value.'.'.DealerLvl::Contracted->value.'_1', '签约1')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Special->value.'.'.DealerLvl::Contracted->value.'_2', '签约2')->symbol('¥');
|
||||
$this->divider('特邀->特邀->特邀');
|
||||
$this->currency('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Special->value.'.'.DealerLvl::Special->value.'_0', '特邀0')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Special->value.'.'.DealerLvl::Special->value.'_1', '特邀1')->symbol('¥');
|
||||
$this->divider('特邀->金牌->特邀->特邀');
|
||||
$this->currency('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Gold->value.'.'.DealerLvl::Gold->value.'_0', '金牌0')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Gold->value.'.'.DealerLvl::Special->value.'_1', '特邀1')->symbol('¥');
|
||||
$this->currency('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Gold->value.'.'.DealerLvl::Special->value.'_2', '特邀2')->symbol('¥');
|
||||
$this->divider('金牌->金牌');
|
||||
$this->currency('channel_rules.'.DealerLvl::Gold->value.'_'.DealerLvl::Gold->value.'.'.DealerLvl::Gold->value.'_0', '金牌0')->symbol('¥');
|
||||
|
||||
|
||||
// $this->embeds('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Contracted->value, '渠道补贴规则(签约->签约->签约)', function ($form) {
|
||||
// $form->currency(DealerLvl::Contracted->value.'_0', '签约0')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Contracted->value.'_1', '签约1')->symbol('¥');
|
||||
// });
|
||||
// $this->embeds('channel_rules.'.DealerLvl::Contracted->value.'_'.DealerLvl::Special->value, '渠道补贴规则(签约->特邀->签约->签约)', function ($form) {
|
||||
// $form->currency(DealerLvl::Special->value.'_0', '特邀0')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Contracted->value.'_1', '签约1')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Contracted->value.'_2', '签约2')->symbol('¥');
|
||||
// });
|
||||
// $this->embeds('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Special->value, '渠道补贴规则(特邀->特邀->特邀)', function ($form) {
|
||||
// $form->currency(DealerLvl::Special->value.'_0', '特邀0')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Special->value.'_1', '特邀1')->symbol('¥');
|
||||
// });
|
||||
// $this->embeds('channel_rules.'.DealerLvl::Special->value.'_'.DealerLvl::Gold->value, '渠道补贴规则(特邀->金牌->特邀->特邀)', function ($form) {
|
||||
// $form->currency(DealerLvl::Gold->value.'_0', '金牌0')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Special->value.'_1', '特邀1')->symbol('¥');
|
||||
// $form->currency(DealerLvl::Special->value.'_2', '特邀2')->symbol('¥');
|
||||
// });
|
||||
// $this->embeds('channel_rules.'.DealerLvl::Gold->value.'_'.DealerLvl::Gold->value, '渠道补贴规则(金牌->金牌)', function ($form) {
|
||||
// $form->currency(DealerLvl::Gold->value.'_0', '金牌0')->symbol('¥');
|
||||
// });
|
||||
|
||||
$this->table('purchase_rules', '进货补贴规则', function ($table) {
|
||||
$table->number('price', '阶梯(万)');
|
||||
$table->currency('rate', '比例(百分比)')->symbol('%');
|
||||
})->disableCreate()->disableDelete();
|
||||
// $this->embeds('pay_info', '公司收款信息', function ($form) {
|
||||
$this->divider('银行账号收款');
|
||||
$this->text('bank.user_name', '收款人名称');
|
||||
$this->text('bank.bank_name', '银行名称');
|
||||
$this->text('bank.bank_number', '银行卡号');
|
||||
$this->text('bank.bank_description', '开户行');
|
||||
$this->divider('支付宝收款');
|
||||
$this->text('alipay.user_name', '收款人名称');
|
||||
$this->text('alipay.ali_name', '收款账号');
|
||||
$this->image('alipay.image', '收款码')
|
||||
->move('dealer/settings/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->retainable()
|
||||
->autoUpload();
|
||||
$this->divider('微信收款');
|
||||
$this->text('wechat.user_name', '收款人名称');
|
||||
$this->text('wechat.wechat_name', '微信ID');
|
||||
$this->image('wechat.image', '收款码')
|
||||
->move('dealer/settings/'.Carbon::now()->toDateString())
|
||||
->saveFullUrl()
|
||||
->removable(false)
|
||||
->retainable()
|
||||
->autoUpload();
|
||||
|
||||
// })->saving(function ($v) {
|
||||
// // 转化为json格式存储
|
||||
// dd($v);
|
||||
// return json_encode($v);
|
||||
// })->customFormat(function () use ($dealerSettings) {
|
||||
// return $dealerSettings['pay_info']??[];
|
||||
// });
|
||||
}
|
||||
|
||||
public function default()
|
||||
{
|
||||
$dealerSettings = (array) Setting::where('key', 'dealer')->value('value');
|
||||
return [
|
||||
'wxpay_switch'=> $dealerSettings['wxpay_switch'] ?? 1,
|
||||
'delivery_bill_shipping_fee'=> $dealerSettings['delivery_bill_shipping_fee'] ?? 0,
|
||||
'fee_rate'=> $dealerSettings['fee_rate'] ?? '',
|
||||
'withdraw_threshold_amount'=> $dealerSettings['withdraw_threshold_amount'] ?? 0,
|
||||
'withdraw_fee_rate'=> $dealerSettings['withdraw_fee_rate'] ?? 0,
|
||||
'withdraw_days'=> $dealerSettings['withdraw_days'] ?? 7,
|
||||
'order_auto_allocate_times'=> $dealerSettings['order_auto_allocate_times'] ?? 1,
|
||||
'upgrade_amount_'.DealerLvl::Contracted->value => $dealerSettings['upgrade_amount_'.DealerLvl::Contracted->value] ?? '',
|
||||
'upgrade_amount_'.DealerLvl::Special->value => $dealerSettings['upgrade_amount_'.DealerLvl::Special->value] ?? '',
|
||||
'upgrade_amount_'.DealerLvl::Gold->value => $dealerSettings['upgrade_amount_'.DealerLvl::Gold->value] ?? '',
|
||||
|
||||
'min_order_amount_'.DealerLvl::Gold->value => $dealerSettings['min_order_amount_'.DealerLvl::Gold->value] ?? '',
|
||||
'min_order_amount_'.DealerLvl::Special->value => $dealerSettings['min_order_amount_'.DealerLvl::Special->value] ?? '',
|
||||
'min_order_amount_'.DealerLvl::Contracted->value => $dealerSettings['min_order_amount_'.DealerLvl::Contracted->value] ?? '',
|
||||
'min_order_amount_'.DealerLvl::Secondary->value => $dealerSettings['min_order_amount_'.DealerLvl::Secondary->value] ?? '',
|
||||
'min_order_amount_'.DealerLvl::Top->value => $dealerSettings['min_order_amount_'.DealerLvl::Top->value] ?? '',
|
||||
|
||||
'bank'=>$dealerSettings['bank'] ?? [],
|
||||
'alipay'=>$dealerSettings['alipay'] ?? [],
|
||||
'wechat' =>$dealerSettings['wechat'] ?? [],
|
||||
'purchase_rules'=>$dealerSettings['purchase_rules'] ?? [],
|
||||
'channel_rules'=>$dealerSettings['channel_rules'] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,722 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Imports;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Exceptions\ImportException;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerManagerSalesLog;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerOrderAllocateLog;
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerPurchaseLog;
|
||||
use App\Models\DealerUserProduct;
|
||||
use App\Models\User;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DealerOrderImport extends Import
|
||||
{
|
||||
public function loadRow($row)
|
||||
{
|
||||
/**校验行数据 **/
|
||||
//获取下单用户
|
||||
$phone = $row->getCellAtIndex(0)?->getValue();
|
||||
if (empty($phone)) {
|
||||
throw new ImportException('未输入下单用户手机号');
|
||||
}
|
||||
//获取下单盒数;
|
||||
$qty = $row->getCellAtIndex(1)?->getValue();
|
||||
if (empty($qty)) {
|
||||
throw new ImportException('未输入下单盒数');
|
||||
}
|
||||
//获取下单金额;
|
||||
$totalAmount = $row->getCellAtIndex(2)?->getValue();
|
||||
if (empty($totalAmount)) {
|
||||
throw new ImportException('未输入下单金额');
|
||||
}
|
||||
//获取目标等级
|
||||
$toLv = $row->getCellAtIndex(3)?->getValue();
|
||||
if (empty($toLv)) {
|
||||
throw new ImportException('未输入目标等级');
|
||||
}
|
||||
|
||||
$productId = $row->getCellAtIndex(4)?->getValue();
|
||||
if (empty($productId)) {
|
||||
$productId = 1;
|
||||
}
|
||||
|
||||
$user = User::where('phone', $phone)->first();
|
||||
dump('手机号:'.$phone.'开始执行');
|
||||
if ($user) {
|
||||
$orderService = new OrderService();
|
||||
|
||||
$product = DealerProduct::findOrFail($productId);
|
||||
$shippingAddress = $user->shippingAddresses()->orderBy('is_default', 'desc')->first();
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
//执行自己升级
|
||||
if ($toLv < 4) {
|
||||
$user->dealer->upgrade(DealerLvl::from($toLv), '0217后台修改等级');
|
||||
//执行上级尝试升级
|
||||
foreach ($user->dealer->getDealers() as $parentDealer) {
|
||||
$parentDealer->attemptUpgrade();
|
||||
}
|
||||
} else {
|
||||
/**下单 -start **/
|
||||
//没有地址
|
||||
if (!$shippingAddress) {
|
||||
$shippingAddress = $user->shippingAddresses()->create([
|
||||
'zone_id'=>3,
|
||||
'zone'=>'北京市 北京市 东城区',
|
||||
'consignee'=>'测试',
|
||||
'telephone'=>'18888888888',
|
||||
'address'=>'1',
|
||||
'is_default'=>true,
|
||||
]);
|
||||
}
|
||||
$order = $orderService->quickCreateOrder($user, $product, $qty, $shippingAddress->id);
|
||||
//重新按新规则给一次发货人
|
||||
if ($order->consignor_id) {
|
||||
$order->update([
|
||||
'consignor_id'=>$this->getConsignor($user, $order->total_amount)?->user_id,
|
||||
]);
|
||||
$order->refresh();
|
||||
if (!($order->consignor_id > 1)) {//如果是null或者1
|
||||
//确认接单
|
||||
$order = $orderService->confirmOrder($order);
|
||||
}
|
||||
}
|
||||
/**下单 -end **/
|
||||
dump('下单:'.$order->sn);
|
||||
/**更新订单状态 -start **/
|
||||
//【金牌】,【特邀】订单需要发货人有对应的库存,否则往上丢
|
||||
if (in_array($toLv, [
|
||||
'2', '3',
|
||||
])) {
|
||||
do {
|
||||
if ($order->consignor_id > 1) {
|
||||
$userProduct = DealerUserProduct::where('user_id', $order->consignor_id)->where('stock', '>', 0)->first();
|
||||
if (!$userProduct) {
|
||||
//没找到库存商品,则继续往上丢
|
||||
$order = $this->updateOrderConsignor($order);
|
||||
$order->refresh();
|
||||
} else {
|
||||
// if ($userProduct->stock < $qty) {
|
||||
// //记录手机号
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (!$userProduct);
|
||||
}
|
||||
if ($order->isPending()) {
|
||||
//确认接单
|
||||
$order = $orderService->confirmOrder($order);
|
||||
}
|
||||
//确认打款
|
||||
$order = $orderService->payOrder($order, 'offline');
|
||||
//确认收款
|
||||
$order = $orderService->paidOrder($order);
|
||||
|
||||
//如果目标等级是【金牌】【特邀】则只到【待发货】。其余订单走到【已完成】
|
||||
if (!in_array($toLv, [
|
||||
'2', '3',
|
||||
])) {
|
||||
//确认发货
|
||||
$order = $orderService->shippingOrder($order);
|
||||
//确认收货
|
||||
$order = $orderService->shippingedOrder($order);
|
||||
}
|
||||
|
||||
/**更新订单状态 -end **/
|
||||
|
||||
//执行升级结算订单
|
||||
$this->handleDealerOrder($order);
|
||||
}
|
||||
DB::commit();
|
||||
} catch (QueryException $e) {
|
||||
DB::rollBack();
|
||||
if (strpos($e->getMessage(), 'Numeric value out of range') !== false) {
|
||||
$e = new BizException('当前可发货库存不足');
|
||||
}
|
||||
throw $e;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException($th->getMessage());
|
||||
}
|
||||
} else {
|
||||
throw new ImportException('未找到用户:'.$phone);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单发货人
|
||||
*
|
||||
* @return DealerOrder
|
||||
*/
|
||||
public function updateOrderConsignor(DealerOrder $order)
|
||||
{
|
||||
//只处理当前订单有发货人的情况
|
||||
if ($order->consignor) {
|
||||
$consignor = $this->getConsignor($order->user, $order->total_amount, $order->consignor);
|
||||
$oldConsignor = $order->consignor;
|
||||
$order->update([
|
||||
'allocated_at' => now(),
|
||||
'consignor_id' => $consignor?->user_id,
|
||||
]);
|
||||
//记录分配日志
|
||||
DealerOrderAllocateLog::create([
|
||||
'order_id'=>$order->id,
|
||||
'last_consignor_id'=>$oldConsignor->id,
|
||||
'new_consignor_id' =>$order->consignor_id,
|
||||
]);
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
private function getConsignor(User $user, $totalAmount, ?User $lastConsignor = null)
|
||||
{
|
||||
$rules = [
|
||||
[
|
||||
'amount' => '2640',
|
||||
'lvl' => DealerLvl::Contracted,
|
||||
],
|
||||
[
|
||||
'amount' => '860',
|
||||
'lvl' => DealerLvl::Special,
|
||||
],
|
||||
[
|
||||
'amount' => '630',
|
||||
'lvl' => DealerLvl::Gold,
|
||||
],
|
||||
];
|
||||
$lvl = $user->dealer->lvl;
|
||||
//计算通过这个订单可能升级成为的身份
|
||||
foreach ($rules as $rule) {
|
||||
if ($totalAmount >= $rule['amount'] && $lvl->value < $rule['lvl']->value) {
|
||||
$lvl = $rule['lvl'];
|
||||
}
|
||||
}
|
||||
//如果是签约单,直接抛到公司后台发货
|
||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||
return null;
|
||||
}
|
||||
//新逻辑
|
||||
$consignor = null;
|
||||
$_lastConsignor = $lastConsignor;
|
||||
do {
|
||||
$query = User::with(['userInfo', 'dealer']);
|
||||
if ($_lastConsignor) {
|
||||
$query->where('id', $_lastConsignor->userInfo->real_inviter_id);
|
||||
} else {
|
||||
$query->where('id', $user->userInfo->real_inviter_id);
|
||||
}
|
||||
$consignor = $query->first();
|
||||
if ($consignor) {//找到老上级
|
||||
if ($consignor->dealer->is_sale == true && $consignor->dealer->lvl->value > $lvl->value) {
|
||||
break;
|
||||
} else {
|
||||
$_lastConsignor = $consignor;
|
||||
$consignor = null;
|
||||
}
|
||||
} else {//如果找不到人了
|
||||
$consignor = $lastConsignor;
|
||||
break;
|
||||
}
|
||||
} while (empty($consignor));
|
||||
|
||||
return $consignor?->userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理经销商订单
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @return void
|
||||
*/
|
||||
protected function handleDealerOrder(DealerOrder $dealerOrder)
|
||||
{
|
||||
$tz = now()->toDateTimeString();
|
||||
|
||||
// 上级经销商
|
||||
$ancestors = $dealerOrder->dealer->getDealers();
|
||||
|
||||
// 签约经销商的进货日志
|
||||
$this->handlePurchaseLogsOfContractedDealer($dealerOrder, $tz);
|
||||
|
||||
// 一级签约经销商和二级经销商的管理津贴
|
||||
$this->handleManageSubsidyLogs($dealerOrder, $ancestors, $tz);
|
||||
|
||||
// 管理者的销售业绩
|
||||
$this->handleManagerSalesLogs($dealerOrder, $ancestors, $tz);
|
||||
|
||||
// 渠道补贴
|
||||
$this->handleChannelSubsidy($dealerOrder);
|
||||
|
||||
if ($dealerOrder->dealer->wasChanged('lvl')) {
|
||||
$dealers = [
|
||||
$dealerOrder->dealer,
|
||||
...$ancestors,
|
||||
];
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
$dealer->attemptUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
// 将订单标记为已处理
|
||||
$dealerOrder->forceFill([
|
||||
'settle_state' => DealerOrderSettleState::Processed,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算渠道补贴
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @return void
|
||||
*/
|
||||
protected function handleChannelSubsidy(DealerOrder $dealerOrder)
|
||||
{
|
||||
$lvl = $dealerOrder->dealer->lvl;
|
||||
|
||||
$lvlValue = [
|
||||
DealerLvl::Contracted->value => '2640',
|
||||
DealerLvl::Special->value => '860',
|
||||
DealerLvl::Gold->value => '630',
|
||||
|
||||
];
|
||||
|
||||
if ($dealerOrder->total_amount >= $lvlValue[DealerLvl::Contracted->value]) {
|
||||
// 升级为签约
|
||||
if ($lvl->value < DealerLvl::Contracted->value) {
|
||||
$lvl = DealerLvl::Contracted;
|
||||
}
|
||||
} elseif ($dealerOrder->total_amount >= $lvlValue[DealerLvl::Special->value]) {
|
||||
// 升级为特约
|
||||
if ($lvl->value < DealerLvl::Special->value) {
|
||||
$lvl = DealerLvl::Special;
|
||||
}
|
||||
} elseif ($dealerOrder->total_amount >= $lvlValue[DealerLvl::Gold->value]) {
|
||||
// 升级为金牌
|
||||
if ($lvl->value < DealerLvl::Gold->value) {
|
||||
$lvl = DealerLvl::Gold;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果经销商等级小于金牌,则没有渠道补贴
|
||||
if ($lvl->value < DealerLvl::Gold->value) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$dealers, $rule] = $this->mapDealersAndRuleOfChannel($dealerOrder->dealer, $lvl);
|
||||
|
||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||
$upgradeAmount = $lvlValue[DealerLvl::Contracted->value];
|
||||
} else {
|
||||
$upgradeAmount = $lvlValue[$lvl->value];
|
||||
}
|
||||
|
||||
// 手续费比例
|
||||
$feeRate = app_settings('dealer.fee_rate');
|
||||
|
||||
foreach ($dealers as $key => $dealer) {
|
||||
$ruleKey = $dealer->lvl->value.'_'.$key;
|
||||
|
||||
if ($dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
$ruleKey = DealerLvl::Contracted->value.'_'.$key;
|
||||
}
|
||||
|
||||
// 补贴金额
|
||||
$subsidyAmount = $rule[$ruleKey];
|
||||
|
||||
$totalAmount = bcmul($subsidyAmount, $dealerOrder->total_amount, 10);
|
||||
$totalAmount = bcdiv($totalAmount, $upgradeAmount, 3);
|
||||
$totalAmount = round($totalAmount, 2);
|
||||
|
||||
$channelSubsidyLog = DealerChannelSubsidyLog::create([
|
||||
'user_id' => $dealer->user_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'total_amount' => $totalAmount,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'remark' => "补贴总额={$dealerOrder->total_amount}/{$upgradeAmount}*{$subsidyAmount}",
|
||||
]);
|
||||
|
||||
$fee = bcmul($channelSubsidyLog->total_amount, bcdiv($feeRate, '100', 5), 3);
|
||||
$fee = round($fee, 2);
|
||||
|
||||
$channelSubsidyLog->earning()->create([
|
||||
'user_id' => $channelSubsidyLog->user_id,
|
||||
'lvl' => $channelSubsidyLog->lvl,
|
||||
'total_amount' => $channelSubsidyLog->total_amount,
|
||||
'total_earnings' => bcsub($channelSubsidyLog->total_amount, $fee, 2),
|
||||
'fee' => $fee,
|
||||
'fee_rate' => $feeRate,
|
||||
'payer_id' => $dealerOrder->consignor_id,
|
||||
'status' => DealerEarningStatus::Pending,
|
||||
'remark' => "订单号: {$dealerOrder->sn}",
|
||||
]);
|
||||
}
|
||||
|
||||
$dealerOrder->dealer->upgrade($lvl, '进货升级');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取渠道补贴经销商和补贴规则
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @param \App\Enums\DealerLvl $lvl
|
||||
* @return array
|
||||
*/
|
||||
protected function mapDealersAndRuleOfChannel(Dealer $dealer, DealerLvl $lvl): array
|
||||
{
|
||||
// 渠道补贴经销商
|
||||
$dealers = [];
|
||||
// 渠道补贴规则
|
||||
$rule = null;
|
||||
// 是否升级
|
||||
$isUp = $lvl->value > $dealer->lvl->value;
|
||||
// 最后参与渠道补贴的经销商
|
||||
$last = null;
|
||||
// 前一个直属邀请人
|
||||
$previous = null;
|
||||
|
||||
while (true) {
|
||||
if ($previous) {
|
||||
$_dealer = $previous->userInfo->realInviterInfo?->dealer;
|
||||
$_dealer?->setRelation('userInfo', $previous->userInfo->realInviterInfo);
|
||||
} else {
|
||||
$_dealer = $dealer->userInfo->realInviterInfo?->dealer;
|
||||
$_dealer?->setRelation('userInfo', $dealer->userInfo->realInviterInfo);
|
||||
}
|
||||
|
||||
$previous = $_dealer;
|
||||
|
||||
if ($_dealer === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 如果经销商等级小于金牌, 那么跳过
|
||||
if ($_dealer->lvl->value < DealerLvl::Gold->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||
if ($last === null) {
|
||||
if ($_dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
// 渠道补贴规则: 签约 -> 签约 -> 签约
|
||||
$rule = [
|
||||
DealerLvl::Contracted->value.'_0' => '396',
|
||||
DealerLvl::Contracted->value.'_1' => '79',
|
||||
];
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
} elseif ($isUp && $_dealer->isSpecialDealer()) {
|
||||
// 渠道补贴规则: 签约 -> 特邀 -> 签约 -> 签约
|
||||
$rule = [
|
||||
DealerLvl::Special->value.'_0' => '264',
|
||||
DealerLvl::Contracted->value.'_1' => '132',
|
||||
DealerLvl::Contracted->value.'_2' => '79',
|
||||
];
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($_dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
// 如果最后参与渠道补贴的经销商是签约, 那么已经找到所有参与渠道补贴的经销商
|
||||
if ($last->lvl->value >= DealerLvl::Contracted->value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($lvl === DealerLvl::Special) {
|
||||
if ($_dealer->lvl->value > DealerLvl::Special->value) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($last === null) {
|
||||
if ($_dealer->isSpecialDealer()) {
|
||||
// 渠道补贴规则: 特邀 -> 特邀 -> 特邀
|
||||
$rule = [
|
||||
DealerLvl::Special->value.'_0' => '80',
|
||||
DealerLvl::Special->value.'_1' => '20',
|
||||
];
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
} elseif ($isUp && $_dealer->isGoldDealer()) {
|
||||
// 渠道补贴规则: 特邀 -> 金牌 -> 特邀 -> 特邀
|
||||
$rule = [
|
||||
DealerLvl::Gold->value.'_0' => '50',
|
||||
DealerLvl::Special->value.'_1' => '30',
|
||||
DealerLvl::Special->value.'_2' => '20',
|
||||
];
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($_dealer->isSpecialDealer()) {
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
if ($last->isSpecialDealer()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($lvl === DealerLvl::Gold) {
|
||||
if ($_dealer->lvl->value >= DealerLvl::Gold->value) {
|
||||
if ($_dealer->isGoldDealer()) {
|
||||
// 渠道补贴规则: 金牌 -> 金牌
|
||||
$rule = [
|
||||
DealerLvl::Gold->value.'_0' => '75',
|
||||
];
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$dealers, $rule];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签约经销商的进货日志
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handlePurchaseLogsOfContractedDealer(DealerOrder $dealerOrder, string $tz)
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dealer = $dealerOrder->userInfo->dealer;
|
||||
|
||||
// 采购业绩是否算自己的业绩
|
||||
$valid = $dealer->lvl->value >= DealerLvl::Contracted->value;
|
||||
|
||||
$log = new DealerPurchaseLog([
|
||||
'user_id' => $dealer->user_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'total_amount' => $dealerOrder->total_amount,
|
||||
'path' => $valid ? $dealerOrder->userInfo->full_path : $dealerOrder->userInfo->path,
|
||||
'remark' => $valid ? null : '升级签约',
|
||||
]);
|
||||
$log->setCreatedAt($tz);
|
||||
$log->setUpdatedAt($tz);
|
||||
$log->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配一级签约经销商和二级经销商的管理津贴
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handleManageSubsidyLogs(DealerOrder $dealerOrder, array $dealers, string $tz)
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = [];
|
||||
|
||||
foreach ($dealerOrder->products as $product) {
|
||||
if ($product->productManageSubsidyRules->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 管理津贴分配规则
|
||||
$rules = $product->productManageSubsidyRules->keyBy('lvl');
|
||||
|
||||
$last = null;
|
||||
$ranking = 0;
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
if (! in_array($dealer->lvl, [DealerLvl::Secondary, DealerLvl::Top])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果当前经销商等级没有对应的管理津贴分配规则,则忽略
|
||||
if (is_null($rule = $rules->get($dealer->lvl->value))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 同等级管理津贴最多给三次
|
||||
if ($last === null || $dealer->lvl->value > $last->lvl->value) {
|
||||
if ($ranking < 3 && $dealer->lvl === DealerLvl::Top) {
|
||||
if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary->value)) {
|
||||
$key = 'price_'.(1 + $ranking).'st';
|
||||
|
||||
$secondarySubsidy = $secondarySubsidyRule->{$key};
|
||||
|
||||
if (bccomp($secondarySubsidy, '0') === 1) {
|
||||
$logs[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'sales_volume' => $product->qty,
|
||||
'total_amount' => bcmul($product->qty, $secondarySubsidy, 2),
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ranking = 1;
|
||||
} elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) {
|
||||
$ranking++;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subsidy = $rule->{"price_{$ranking}st"};
|
||||
|
||||
if (bccomp($subsidy, '0') === 1) {
|
||||
$logs[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'sales_volume' => $product->qty,
|
||||
'total_amount' => bcmul($product->qty, $subsidy, 2),
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
|
||||
$last = $dealer;
|
||||
}
|
||||
}
|
||||
|
||||
DealerManageSubsidyLog::insert($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤出可能会享受管理津贴的经销商(每个等级最多3人)
|
||||
*
|
||||
* @param array $dealers
|
||||
* @return array
|
||||
*/
|
||||
protected function mapManageSubsidyDealers(array $dealers): array
|
||||
{
|
||||
$map = [];
|
||||
$last = null;
|
||||
$ranking = 1;
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
if ($last === null || $dealer->lvl->value > $last->lvl->value) {
|
||||
$last = $dealer;
|
||||
$map[] = $last;
|
||||
$ranking = 1;
|
||||
} elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) {
|
||||
$last = $dealer;
|
||||
$map[] = $last;
|
||||
$ranking++;
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成管理者的销售业绩
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handleManagerSalesLogs(DealerOrder $dealerOrder, array $dealers, string $tz): void
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($manager = $this->firstManager($dealers))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = [];
|
||||
|
||||
foreach ($dealerOrder->products as $product) {
|
||||
$logs[] = [
|
||||
'user_id' => $manager->user_id,
|
||||
'lvl' => $manager->lvl,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'sales_volume' => $product->qty,
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
|
||||
DealerManagerSalesLog::insert($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从给定的经销商中获取第一个管理者
|
||||
*
|
||||
* @param array $dealers
|
||||
* @return \App\Models\Dealer|null
|
||||
*/
|
||||
protected function firstManager(array $dealers): ?Dealer
|
||||
{
|
||||
foreach ($dealers as $dealer) {
|
||||
if ($dealer->is_manager) {
|
||||
return $dealer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认是否是签约经销商进货
|
||||
*
|
||||
* @param DealerOrder $dealerOrder
|
||||
* @return bool
|
||||
*/
|
||||
protected function isContractedDealerToPurchase(DealerOrder $dealerOrder): bool
|
||||
{
|
||||
$dealer = $dealerOrder->userInfo->dealer;
|
||||
|
||||
if ($dealer->lvl->value < DealerLvl::Contracted->value) {
|
||||
if ($dealerOrder->total_amount < '2640') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Admin\Metrics;
|
||||
|
||||
use App\Models\Balance;
|
||||
use App\Models\DealerWallet;
|
||||
use App\Models\DistributionPreIncome;
|
||||
use App\Models\UserInfo;
|
||||
use App\Models\Wallet;
|
||||
|
|
@ -41,7 +40,6 @@ class StatisticsTotal extends RadialBar
|
|||
'total_distribution'=> DistributionPreIncome::unsettlement()->sum('total_revenue'),
|
||||
'total_quota_v2' => UserInfo::sum('quota_v2'),
|
||||
'total_quota_v1' => UserInfo::sum('quota_v1'),
|
||||
'total_dealer_wallet' => bcdiv(DealerWallet::sum('balance'), 1, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -84,10 +82,6 @@ class StatisticsTotal extends RadialBar
|
|||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_quota_v1']}</h1>
|
||||
老配额
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$content['total_dealer_wallet']}</h1>
|
||||
批零余额
|
||||
</div>
|
||||
</div>
|
||||
HTML
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\LazyRenderable;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
|
||||
class DealerEarningSimpleTable extends LazyRenderable
|
||||
{
|
||||
public function grid(): Grid
|
||||
{
|
||||
$userId = $this->payload['id'] ?? 0;
|
||||
$builder = DealerEarning::query();
|
||||
// dd($userId);
|
||||
$builder->with(['user', 'payer'])->where(function ($q) use ($userId) {
|
||||
return $q->where('user_id', $userId)->orWhere('payer_id', $userId);
|
||||
});
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('user.phone', '收款人');
|
||||
$grid->column('payer_id', '付款人')->display(function () {
|
||||
return $this->payer_id ? $this->payer?->phone : '公司';
|
||||
});
|
||||
$grid->column('earningable_type', '资金类型')->display(function () {
|
||||
return $this->earningable_type_text;
|
||||
})->label([
|
||||
(new DealerManageSubsidy())->getMorphClass() => 'primary',
|
||||
(new DealerManagerSubsidy())->getMorphClass() => 'success',
|
||||
(new DealerPurchaseSubsidy())->getMorphClass() => 'danger',
|
||||
(new DealerChannelSubsidyLog())->getMorphClass() => 'warning',
|
||||
]);
|
||||
$grid->column('remark', '备注')->display('详情') // 设置按钮名称
|
||||
->expand(function () {
|
||||
// 这里返回 content 字段内容,并用 Card 包裹起来
|
||||
$card = new Card(null, $this->remark);
|
||||
|
||||
return "<div style='padding:10px 10px 0;text-align: center'>$card</div>";
|
||||
});
|
||||
$grid->column('lvl')->display(function () {
|
||||
return $this->lvl->text();
|
||||
});
|
||||
// $grid->column('total_amount', '总金额')->prepend('¥');
|
||||
// $grid->column('fee_rate', '手续费率')->append('%');
|
||||
// $grid->column('fee', '手续费')->prepend('¥');
|
||||
$grid->column('total_earnings', '实际金额')->prepend('¥');
|
||||
$grid->column('status', '状态')->display(function ($v) {
|
||||
if (! $this->isSettled()) {
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: #b9c3cd'></i> 待结算";
|
||||
}
|
||||
|
||||
return "<i class='fa fa-circle' style='font-size: 13px;color: {$v->color()}'></i> {$v->text()}";
|
||||
});
|
||||
$grid->column('created_at', '创建时间');
|
||||
$grid->column('id', '操作')->display('查看')->link(function ($value) {
|
||||
return admin_route('dealer_earnings.show', ['dealer_earning' => $this->id]);
|
||||
});
|
||||
// $grid->withBorder();
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableActions();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Models\UserInfo;
|
||||
use Dcat\Admin\Support\LazyRenderable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DealerSubordinateCard extends LazyRenderable
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
// 获取外部传递的参数
|
||||
$id = $this->id;
|
||||
// dd($id);
|
||||
$query = DB::table('users')
|
||||
->join('user_infos', 'users.id', '=', 'user_infos.user_id')
|
||||
->join('dealers', 'users.id', '=', 'dealers.user_id');
|
||||
$userInfo = UserInfo::where('user_id', $id)->first();
|
||||
// 查询数据逻辑
|
||||
$data = [
|
||||
'top'=> (clone $query)->whereNotNull('users.phone')->where('dealers.lvl', 6)->where('user_infos.path', 'like', $userInfo->full_path.'%')->count(),
|
||||
'secondary'=> (clone $query)->whereNotNull('users.phone')->where('dealers.lvl', 5)->where('user_infos.path', 'like', $userInfo->full_path.'%')->count(),
|
||||
'contracted'=> (clone $query)->whereNotNull('users.phone')->where('dealers.lvl', 4)->where('user_infos.path', 'like', $userInfo->full_path.'%')->count(),
|
||||
'special'=> (clone $query)->whereNotNull('users.phone')->where('dealers.lvl', 3)->where('user_infos.path', 'like', $userInfo->full_path.'%')->count(),
|
||||
'gold'=> (clone $query)->whereNotNull('users.phone')->where('dealers.lvl', 2)->where('user_infos.path', 'like', $userInfo->full_path.'%')->count(),
|
||||
];
|
||||
|
||||
// 这里可以返回内置组件,也可以返回视图文件或HTML字符串
|
||||
return
|
||||
<<<HTML
|
||||
<div class="d-flex row text-center align-items-center justify-content-center" >
|
||||
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$data['top']}</h1>
|
||||
一级经销商
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$data['secondary']}</h1>
|
||||
二级经销商
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$data['contracted']}</h1>
|
||||
签约经销商
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex row text-center align-items-center justify-content-center" >
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$data['special']}</h1>
|
||||
特邀经销商
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<h1 class="font-lg-1 mt-2 mb-0">{$data['gold']}</h1>
|
||||
金牌经销商
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Models\DealerUserProductLog;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\LazyRenderable;
|
||||
|
||||
class DealerUserProductLogSimpleTable extends LazyRenderable
|
||||
{
|
||||
public function grid(): Grid
|
||||
{
|
||||
$userId = $this->payload['id'] ?? 0;
|
||||
$productId = $this->payload['product_id'] ?? 0;
|
||||
|
||||
$builder = DealerUserProductLog::query();
|
||||
$builder->with(['product'])->where(['user_id'=>$userId, 'product_id'=>$productId]);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('remark', '备注');
|
||||
$grid->column('is_deposit', '范围')->using([
|
||||
0=>'本地库存',
|
||||
1=>'云库存',
|
||||
]);
|
||||
$grid->column('qty', '变动数量')->display(function () {
|
||||
return $this->qty_format.$this->product?->unit;
|
||||
});
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
// $grid->withBorder();
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableActions();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Models\DealerUserProduct;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\LazyRenderable;
|
||||
|
||||
class DealerUserProductSimpleTable extends LazyRenderable
|
||||
{
|
||||
public function grid(): Grid
|
||||
{
|
||||
$userId = $this->payload['id'] ?? 0;
|
||||
$builder = DealerUserProduct::query();
|
||||
$builder->with(['product'])->where('user_id', $userId);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('product.name', '商品名称');
|
||||
$grid->column('product.cover', '商品封面')->image(80, 80);
|
||||
$grid->column('stock', '剩余库存');
|
||||
$grid->column('created_at', '创建时间');
|
||||
// $grid->withBorder();
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable;
|
||||
|
||||
use App\Models\DealerWalletLog;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\LazyRenderable;
|
||||
|
||||
class DealerWalletLogSimpleTable extends LazyRenderable
|
||||
{
|
||||
public function grid(): Grid
|
||||
{
|
||||
$userId = $this->payload['id']??0;
|
||||
$builder = DealerWalletLog::query();
|
||||
$builder->where('user_id', $userId);
|
||||
return Grid::make($builder, function (Grid $grid) {
|
||||
$grid->column('remarks', '备注');
|
||||
$grid->column('change_balance', '变动金额(元)')->prepend('¥');
|
||||
$grid->column('before_balance', '变动前(元)')->prepend('¥');
|
||||
$grid->column('created_at', '变动时间');
|
||||
// $grid->withBorder();
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
$grid->disableRefreshButton();
|
||||
$grid->disableActions();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable\Grid\Filter;
|
||||
|
||||
use Dcat\Admin\Grid\Column\Filter;
|
||||
use Dcat\Admin\Grid\Column\Filter\Checkbox;
|
||||
use Dcat\Admin\Grid\Model;
|
||||
|
||||
class DealerEarningStatusIn extends Filter
|
||||
{
|
||||
use Checkbox;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* CheckFilter constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
$this->class = [
|
||||
'all' => uniqid('column-filter-all-'),
|
||||
'item' => uniqid('column-filter-item-'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a binding to the query.
|
||||
*
|
||||
* @param array $value
|
||||
* @param Model $model
|
||||
*/
|
||||
public function addBinding($value, Model $model)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
$all = [-1, 0, 1, 5];
|
||||
|
||||
if (array_diff($all, $value)) {//无差别则直接跳过
|
||||
//判断查询的状态有哪些;
|
||||
$model->where(function ($query) use ($value) {
|
||||
foreach ($value as $status) {
|
||||
switch ($status) {
|
||||
case -1:
|
||||
$query->orWhereNull('settle_at');
|
||||
break;
|
||||
case 0:
|
||||
$query->orWhere(function ($q) {
|
||||
return $q->whereNotNull('settle_at')->where('status', 0);
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
$query->orWhere('status', 1);
|
||||
break;
|
||||
case 5:
|
||||
$query->orWhere('status', 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this filter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return $this->renderCheckbox();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable\Grid\Filter;
|
||||
|
||||
use App\Enums\PayWay;
|
||||
use Dcat\Admin\Grid\Column\Filter;
|
||||
use Dcat\Admin\Grid\Column\Filter\Checkbox;
|
||||
use Dcat\Admin\Grid\Model;
|
||||
|
||||
class DealerOrderPayWayIn extends Filter
|
||||
{
|
||||
use Checkbox;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* CheckFilter constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
$this->class = [
|
||||
'all' => uniqid('column-filter-all-'),
|
||||
'item' => uniqid('column-filter-item-'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a binding to the query.
|
||||
*
|
||||
* @param array $value
|
||||
* @param Model $model
|
||||
*/
|
||||
public function addBinding($value, Model $model)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
$all = [
|
||||
PayWay::Offline->value => '线下打款',
|
||||
PayWay::Wallet->value => '余额支付',
|
||||
PayWay::WxpayH5->value => '微信支付',
|
||||
''=>'Unknown',
|
||||
];
|
||||
|
||||
if (array_diff($all, $value)) {//无差别则直接跳过
|
||||
//判断查询的状态有哪些;
|
||||
$model->where(function ($query) use ($value) {
|
||||
foreach ($value as $payWay) {
|
||||
switch ($payWay) {
|
||||
case '':
|
||||
$query->orWhereNull('pay_way');
|
||||
break;
|
||||
default:
|
||||
$query->orWhere('pay_way', $payWay);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this filter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return $this->renderCheckbox();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\Dealer as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class Dealer extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerDeliveryBill as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerDeliveryBill extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerDeliveryProduct as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerDeliveryProduct extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerEarning as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerEarning extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerManageSubsidy as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerManageSubsidy extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerManageSubsidyLog as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerManageSubsidyLog extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerManagerSalesLog as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerManagerSalesLog extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerManagerSubsidy as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerManagerSubsidy extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerOrder as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerOrder extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerProduct as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerProduct extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerPurchaseLog as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerPurchaseLog extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerPurchaseSubsidy as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerPurchaseSubsidy extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerPurchaseSubsidyLog as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerPurchaseSubsidyLog extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Repositories;
|
||||
|
||||
use App\Models\DealerWalletToBankLog as Model;
|
||||
use Dcat\Admin\Repositories\EloquentRepository;
|
||||
|
||||
class DealerWalletToBankLog extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eloquentClass = Model::class;
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Services;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerManagerSubsidyStatus;
|
||||
use App\Enums\DealerManageSubsidyStatus;
|
||||
use App\Enums\DealerPurchaseSubsidyStatus;
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class DealerEarningService
|
||||
{
|
||||
public function pay(DealerEarning $dealerEarning)
|
||||
{
|
||||
if (! $dealerEarning->isSettled()) {
|
||||
throw new BizException('经销商收益还未结算');
|
||||
}
|
||||
|
||||
if (! $dealerEarning->isPending()) {
|
||||
throw new BizException('经销商收益状态不是待付款');
|
||||
}
|
||||
|
||||
switch (Relation::getMorphedModel($dealerEarning->earningable_type)) {
|
||||
// 管理津贴
|
||||
case DealerManageSubsidy::class:
|
||||
if (! $dealerEarning->earningable->isPending()) {
|
||||
throw new BizException('管理津贴状态不是待付款');
|
||||
}
|
||||
|
||||
$dealerEarning->earningable->update([
|
||||
'status' => DealerManageSubsidyStatus::Completed,
|
||||
]);
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealerEarning->user,
|
||||
$dealerEarning->total_earnings,
|
||||
DealerWalletAction::ManageSubsidyIn,
|
||||
'收入-管理津贴',
|
||||
$dealerEarning
|
||||
);
|
||||
break;
|
||||
|
||||
// 管理者津贴
|
||||
case DealerManagerSubsidy::class:
|
||||
if (! $dealerEarning->earningable->isPending()) {
|
||||
throw new BizException('管理者津贴状态不是待付款');
|
||||
}
|
||||
|
||||
$dealerEarning->earningable->update([
|
||||
'status' => DealerManagerSubsidyStatus::Completed,
|
||||
]);
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealerEarning->user,
|
||||
$dealerEarning->total_earnings,
|
||||
DealerWalletAction::ManagerSubsidyIn,
|
||||
'收入-管理者津贴',
|
||||
$dealerEarning
|
||||
);
|
||||
break;
|
||||
|
||||
// 管理者津贴
|
||||
case DealerPurchaseSubsidy::class:
|
||||
if (! $dealerEarning->earningable->isPending()) {
|
||||
throw new BizException('进货补贴状态不是待付款');
|
||||
}
|
||||
|
||||
$dealerEarning->earningable->update([
|
||||
'status' => DealerPurchaseSubsidyStatus::Completed,
|
||||
]);
|
||||
|
||||
(new WalletService())->changeBalance(
|
||||
$dealerEarning->user,
|
||||
$dealerEarning->total_earnings,
|
||||
DealerWalletAction::PurchaseSubsidyIn,
|
||||
'收入-进货补贴',
|
||||
$dealerEarning
|
||||
);
|
||||
break;
|
||||
|
||||
case DealerChannelSubsidyLog::class:
|
||||
(new WalletService())->changeBalance(
|
||||
$dealerEarning->user,
|
||||
$dealerEarning->total_earnings,
|
||||
DealerWalletAction::ChannelSubsidyIn,
|
||||
'收入-渠道补贴',
|
||||
$dealerEarning
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new BizException('经销商收入异常');
|
||||
break;
|
||||
}
|
||||
|
||||
$dealerEarning->update([
|
||||
'pay_way' => DealerEarning::PAY_WAY_WALLET,
|
||||
'pay_at' => now(),
|
||||
'pay_info' => null,
|
||||
'status' => DealerEarningStatus::Completed,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -170,50 +170,6 @@ Route::group([
|
|||
|
||||
$router->get('monthly-statistics', 'MonthlyStatisticsController@index')->name('monthly-statistics.index');
|
||||
|
||||
//经销商
|
||||
$router->resource('dealer-products', 'DealerProductController')->names('dealer_products');
|
||||
$router->resource('dealer-orders', 'DealerOrderController')->only([
|
||||
'index', 'show', 'edit', 'update',
|
||||
])->names('dealer_orders');
|
||||
$router->get('dealer-manager-orders', 'DealerOrderController@index')->name('dealer_orders.manager');
|
||||
$router->resource('dealer-users', 'DealerController')->only([
|
||||
'index', 'show', 'edit', 'update',
|
||||
])->names('dealers');
|
||||
|
||||
//渠道补贴
|
||||
$router->resource('dealer-earnings', 'DealerEarningController')->only([
|
||||
'index', 'show',
|
||||
])->names('dealer_earnings');
|
||||
$router->get('dealer-earnings-channel', 'DealerEarningController@index')->name('dealer_earnings.channel');
|
||||
$router->get('dealer-earnings-manage', 'DealerEarningController@index')->name('dealer_earnings.manage');
|
||||
$router->get('dealer-earnings-manager', 'DealerEarningController@index')->name('dealer_earnings.manager');
|
||||
$router->get('dealer-earnings-purchase', 'DealerEarningController@index')->name('dealer_earnings.purchase');
|
||||
|
||||
// 签约渠道补贴
|
||||
$router->get('dealer-channel-subsidies', 'DealerChannelSubsidyController@index')->name('dealer_channel_subsidies.index');
|
||||
|
||||
// 管理者津贴
|
||||
$router->get('dealer-manager-subsidies', 'DealerManagerSubsidyController@index')->name('dealer_manager_subsidies.index');
|
||||
$router->get('dealer-manager-sales-logs', 'DealerManagerSalesLogController@index')->name('dealer_manager_sales_logs.index');
|
||||
|
||||
// 管理津贴
|
||||
$router->get('dealer-manage-subsidies', 'DealerManageSubsidyController@index')->name('dealer_manage_subsidies.index');
|
||||
$router->get('dealer-manage-subsidy-logs', 'DealerManageSubsidyLogController@index')->name('dealer_manage_subsidy_logs.index');
|
||||
|
||||
$router->get('dealer-purchase-subsidies', 'DealerPurchaseSubsidyController@index')->name('dealer_purchase_subsidies.index');
|
||||
$router->get('dealer-purchase-subsidies/{dealer_purchase_subsidy}', 'DealerPurchaseSubsidyController@show')->name('dealer_purchase_subsidies.show');
|
||||
$router->get('dealer-purchase-logs', 'DealerPurchaseLogController@index')->name('dealer_purchase_logs.index');
|
||||
|
||||
//批零余额提现
|
||||
$router->get('dealer-wallet-to-bank-logs/export', 'DealerWalletToBankLogController@export')->name('dealer_wallet_to_bank_logs.export');
|
||||
$router->resource('dealer-wallet-to-bank-logs', 'DealerWalletToBankLogController')->only([
|
||||
'index', 'show',
|
||||
])->names('dealer_wallet_to_bank_logs');
|
||||
|
||||
//
|
||||
$router->get('dealer-delivery-bills', 'DealerDeliveryBillController@index')->name('dealer_delivery_bills.index');
|
||||
$router->get('dealer-delivery-bills/{dealer_delivery_bill}', 'DealerDeliveryBillController@show')->name('dealer_delivery_bills.show');
|
||||
|
||||
//商城端-砍价活动
|
||||
$router->resource('bargain-activities', 'BargainActivityController')->names('bargain_activities');
|
||||
$router->resource('bargain-orders', 'BargainOrderController')->only(['index', 'show'])->names('bargain_orders');
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Admin\Services\DealerEarningService;
|
||||
use App\Models\DealerEarning;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class ChannelSubsidySettleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:channel-subsidy-settle';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '结算签约经销商的渠道补贴';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
while (true) {
|
||||
$page = 0;
|
||||
|
||||
DealerEarning::channelSubsidy()->withoutPayer()->onlyPending()->chunkById(200, function ($earnings) use (&$page) {
|
||||
$earnings->load(['earningable', 'user']);
|
||||
|
||||
foreach ($earnings as $earning) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$earning->update([
|
||||
'settle_at' => now(),
|
||||
]);
|
||||
|
||||
(new DealerEarningService())->pay($earning);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
});
|
||||
|
||||
if ($page === 0) {
|
||||
sleep(60);
|
||||
} else {
|
||||
sleep(30);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Admin\Imports\DealerOrderImport;
|
||||
use App\Models\ImportJobLog;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ImportDealerOrder extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:import-order {fileUri}';
|
||||
|
||||
protected $fileUri = '';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '导入批零订单';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->hasArgument('fileUri')) {
|
||||
$this->fileUri = $this->argument('fileUri');
|
||||
}
|
||||
$import = new DealerOrderImport();
|
||||
$res = $import->readFileByUrl($this->fileUri);
|
||||
|
||||
ImportJobLog::insert(array_map(function ($value) {
|
||||
return array_merge($value, [
|
||||
'job_id'=> 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}, $res['errors']));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,284 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Enums\DealerManageSubsidyStatus;
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerManageSubsidy;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
use App\Models\DealerOrder;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManageSubsidySettleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:manage-subsidy-settle';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '结算一级经销商和二级经销商的管理津贴';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 管理津贴结算
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 管理津贴结算时间为每月的5号和20号。
|
||||
|
|
||||
| 5号结算上月20号0点0分0秒到当月4号23点59分59秒的管理津贴
|
||||
| 20号结算当月5号0点0分0秒到19号23点59分59秒的管理津贴
|
||||
|
|
||||
*/
|
||||
|
||||
$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 = $tz->copy()->subMonthNoOverflow()->setDay(19)->endOfDay();
|
||||
}
|
||||
|
||||
$head = '【'.$startAt->format('Y/m/d').'-'.$endAt->format('Y/m/d').'】';
|
||||
|
||||
$ordersCount = DealerOrder::onlyPaidSuccessfully()
|
||||
->where('settle_state', '!=', DealerOrderSettleState::Completed)
|
||||
->whereNotNull('paied_time')
|
||||
->where('paied_time', '<=', $endAt)
|
||||
->count();
|
||||
|
||||
if ($ordersCount > 0) {
|
||||
return $this->warn("{$head} 订单还没有结算完成!");
|
||||
}
|
||||
|
||||
$this->info("{$head}------------[开始]管理津贴结算------------".PHP_EOL);
|
||||
|
||||
$this->info("{$head}管理津贴初始化...");
|
||||
$this->initializeManageSubsidies($startAt, $endAt, 500);
|
||||
$this->info("{$head}管理津贴初始化完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}管理津贴结算...");
|
||||
$this->settleManageSubsidies($startAt, $endAt);
|
||||
$this->info("{$head}管理津贴结算完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}Done! 总耗时: ".$this->formatDuration($tz->diffInMilliseconds(now(), false)));
|
||||
$this->info("{$head}------------[结束]管理津贴结算------------".PHP_EOL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化管理津贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function initializeManageSubsidies(Carbon $startAt, Carbon $endAt, $count = 200): void
|
||||
{
|
||||
$feeRate = app_settings('dealer.fee_rate');
|
||||
|
||||
$lastId = $this->getLastDealerId($startAt, $endAt);
|
||||
|
||||
do {
|
||||
$dealers = Dealer::where('lvl', '>=', DealerLvl::Secondary)
|
||||
->where('contracted_lvl_at', '<=', $endAt)
|
||||
->forPageAfterId($count, $lastId, 'id')
|
||||
->get();
|
||||
|
||||
$dealersCount = $dealers->count();
|
||||
|
||||
if ($dealersCount == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tz = now()->toDateTimeString();
|
||||
$manageSubsidies = [];
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
$manageSubsidies[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'total_amount' => 0,
|
||||
'real_amount' => 0,
|
||||
'fee' => 0,
|
||||
'fee_rate' => $feeRate,
|
||||
'start_at' => $startAt,
|
||||
'end_at' => $endAt,
|
||||
'lvl' => $dealer->lvl,
|
||||
'is_manager' => $dealer->is_manager,
|
||||
'status' => DealerManageSubsidyStatus::Pending,
|
||||
'is_settle' => false,
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
|
||||
$lastId = $dealer->id;
|
||||
}
|
||||
|
||||
DealerManageSubsidy::insert($manageSubsidies);
|
||||
|
||||
unset($dealers, $manageSubsidies);
|
||||
} while ($dealersCount == $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算管理津贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @return void
|
||||
*/
|
||||
protected function settleManageSubsidies(Carbon $startAt, Carbon $endAt)
|
||||
{
|
||||
DealerManageSubsidy::where('start_at', $startAt)->where('end_at', $endAt)->where('is_settle', false)->chunkById(500, function ($subsidies) {
|
||||
foreach ($subsidies as $subsidy) {
|
||||
DB::transaction(function () use ($subsidy) {
|
||||
$this->settleManageSubsidy($subsidy);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算单挑管理津贴
|
||||
*
|
||||
* @param \App\Models\DealerManageSubsidy
|
||||
* @return void
|
||||
*/
|
||||
protected function settleManageSubsidy(DealerManageSubsidy $subsidy)
|
||||
{
|
||||
[$totalAmount, $remark] = $this->calculateTotalAmount($subsidy);
|
||||
|
||||
$feeRate = bcdiv($subsidy->fee_rate, '100', 5);
|
||||
|
||||
$fee = bcmul($totalAmount, $feeRate, 3);
|
||||
$fee = round($fee, 2);
|
||||
|
||||
if (bccomp($totalAmount, '0', 2) === 0) {
|
||||
$subsidy->status = DealerManageSubsidyStatus::Completed;
|
||||
}
|
||||
|
||||
$subsidy->total_amount = $totalAmount;
|
||||
$subsidy->real_amount = bcsub($totalAmount, $fee, 2);
|
||||
$subsidy->fee = $fee;
|
||||
$subsidy->remark = $remark;
|
||||
$subsidy->is_settle = true;
|
||||
$subsidy->save();
|
||||
|
||||
if (! $subsidy->isCompleted()) {
|
||||
$subsidy->earning()->create([
|
||||
'user_id' => $subsidy->user_id,
|
||||
'lvl' => $subsidy->lvl,
|
||||
'total_amount' => $subsidy->total_amount,
|
||||
'total_earnings' => $subsidy->real_amount,
|
||||
'fee' => $subsidy->fee,
|
||||
'fee_rate' => $subsidy->fee_rate,
|
||||
'settle_at' => now(),
|
||||
'status' => DealerEarningStatus::Pending,
|
||||
'remark' => sprintf(
|
||||
"%s - %s\n%s",
|
||||
$subsidy->start_at->format('Y/m/d'),
|
||||
$subsidy->end_at->format('Y/m/d'),
|
||||
$remark
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算补贴总金额
|
||||
*
|
||||
* @param \App\Models\DealerManageSubsidy
|
||||
* @return void
|
||||
*/
|
||||
protected function calculateTotalAmount(DealerManageSubsidy $subsidy): array
|
||||
{
|
||||
$subsidyLogs = DealerManageSubsidyLog::select([
|
||||
'product_id',
|
||||
DB::raw('sum(sales_volume) as sales_volume'),
|
||||
DB::raw('sum(total_amount) as total_amount'),
|
||||
])->where(
|
||||
'user_id', $subsidy->user_id
|
||||
)->whereBetween(
|
||||
'order_completed_at', [$subsidy->start_at, $subsidy->end_at]
|
||||
)->groupBy('product_id')->get();
|
||||
|
||||
// 补贴总金额
|
||||
$totalAmount = 0;
|
||||
// 备注信息
|
||||
$remark = '';
|
||||
|
||||
foreach ($subsidyLogs as $subsidyLog) {
|
||||
$totalAmount = bcadd($totalAmount, $subsidyLog->total_amount, 2);
|
||||
|
||||
if ($remark !== '') {
|
||||
$remark .= "\n";
|
||||
}
|
||||
|
||||
$remark .= "{$subsidyLog->product->name}\n销量: {$subsidyLog->sales_volume}\n补贴金额: {$subsidyLog->total_amount}";
|
||||
}
|
||||
|
||||
return [$totalAmount, $remark];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取给定时间端内的最后一个经销商补贴所属经销商的ID
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getLastDealerId(Carbon $startAt, Carbon $endAt): ?int
|
||||
{
|
||||
$lastManageSubsidy = DealerManageSubsidy::where('start_at', $startAt)
|
||||
->where('end_at', $endAt)
|
||||
->latest('id')
|
||||
->first();
|
||||
|
||||
return $lastManageSubsidy?->dealer?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间
|
||||
*
|
||||
* @param float $milliseconds
|
||||
* @return string
|
||||
*/
|
||||
protected function formatDuration($milliseconds): string
|
||||
{
|
||||
if ($milliseconds < 0.01) {
|
||||
return round($milliseconds * 1000) . 'μs';
|
||||
} elseif ($milliseconds >= 1000) {
|
||||
return round($milliseconds / 1000, 2) . 's';
|
||||
}
|
||||
|
||||
return $milliseconds . 'ms';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerManagerSubsidyStatus;
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerManagerSalesLog;
|
||||
use App\Models\DealerManagerSubsidy;
|
||||
use App\Models\DealerOrder;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManagerSubsidySettleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:manager-subsidy-settle';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '结算上个月的管理者津贴';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tz = now();
|
||||
|
||||
$startAt = $tz->copy()->subMonthNoOverflow()->startOfMonth();
|
||||
$endAt = $startAt->copy()->endOfMonth();
|
||||
|
||||
$head = '【'.$startAt->format('Y/m/d').'-'.$endAt->format('Y/m/d').'】';
|
||||
|
||||
$ordersCount = DealerOrder::onlyPaidSuccessfully()
|
||||
->where('settle_state', '!=', DealerOrderSettleState::Completed)
|
||||
->whereNotNull('paied_time')
|
||||
->where('paied_time', '<=', $endAt)
|
||||
->count();
|
||||
|
||||
if ($ordersCount > 0) {
|
||||
return $this->warn("{$head} 订单还没有结算完成!");
|
||||
}
|
||||
|
||||
$this->info("{$head}------------[开始]管理者津贴结算------------".PHP_EOL);
|
||||
|
||||
$this->info("{$head}管理者津贴初始化...");
|
||||
$this->initializeManagerSubsidies($startAt, $endAt, 500);
|
||||
$this->info("{$head}管理者津贴初始化完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}管理者津贴结算...");
|
||||
$this->settleManagerSubsidies($startAt, $endAt);
|
||||
$this->info("{$head}管理者津贴结算完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}Done! 总耗时: ".$this->formatDuration($tz->diffInMilliseconds(now(), false)));
|
||||
$this->info("{$head}------------[结束]管理者津贴结算------------".PHP_EOL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化管理者津贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function initializeManagerSubsidies(Carbon $startAt, Carbon $endAt, $count = 200): void
|
||||
{
|
||||
$feeRate = app_settings('dealer.fee_rate');
|
||||
|
||||
$lastId = $this->getLastDealerId($startAt, $endAt);
|
||||
|
||||
do {
|
||||
$dealers = Dealer::where('is_manager', true)
|
||||
->forPageAfterId($count, $lastId, 'id')
|
||||
->get();
|
||||
|
||||
$dealersCount = $dealers->count();
|
||||
|
||||
if ($dealersCount == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$tz = now()->toDateTimeString();
|
||||
$managerSubsidies = [];
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
$managerSubsidies[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'total_amount' => 0,
|
||||
'real_amount' => 0,
|
||||
'fee' => 0,
|
||||
'fee_rate' => $feeRate,
|
||||
'start_at' => $startAt,
|
||||
'end_at' => $endAt,
|
||||
'lvl' => $dealer->lvl,
|
||||
'is_manager' => $dealer->is_manager,
|
||||
'status' => DealerManagerSubsidyStatus::Pending,
|
||||
'is_settle' => false,
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
|
||||
$lastId = $dealer->id;
|
||||
}
|
||||
|
||||
DealerManagerSubsidy::insert($managerSubsidies);
|
||||
|
||||
unset($dealers, $managerSubsidies);
|
||||
} while ($dealersCount == $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算管理者津贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @return void
|
||||
*/
|
||||
protected function settleManagerSubsidies(Carbon $startAt, Carbon $endAt)
|
||||
{
|
||||
DealerManagerSubsidy::where('start_at', $startAt)->where('end_at', $endAt)->where('is_settle', false)->chunkById(500, function ($subsidies) {
|
||||
foreach ($subsidies as $subsidy) {
|
||||
DB::transaction(function () use ($subsidy) {
|
||||
$this->settleManagerSubsidy($subsidy);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算管理者津贴
|
||||
*
|
||||
* @param \App\Models\DealerManagerSubsidy
|
||||
* @return void
|
||||
*/
|
||||
protected function settleManagerSubsidy(DealerManagerSubsidy $subsidy)
|
||||
{
|
||||
[$totalAmount, $remark] = $this->calculateTotalAmount($subsidy);
|
||||
|
||||
$feeRate = bcdiv($subsidy->fee_rate, '100', 5);
|
||||
|
||||
$fee = bcmul($totalAmount, $feeRate, 3);
|
||||
$fee = round($fee, 2);
|
||||
|
||||
if (bccomp($totalAmount, '0', 2) === 0) {
|
||||
$subsidy->status = DealerManagerSubsidyStatus::Completed;
|
||||
}
|
||||
|
||||
$subsidy->total_amount = $totalAmount;
|
||||
$subsidy->real_amount = bcsub($totalAmount, $fee, 2);
|
||||
$subsidy->fee = $fee;
|
||||
$subsidy->remark = $remark;
|
||||
$subsidy->is_settle = true;
|
||||
$subsidy->save();
|
||||
|
||||
if (! $subsidy->isCompleted()) {
|
||||
$subsidy->earning()->create([
|
||||
'user_id' => $subsidy->user_id,
|
||||
'lvl' => $subsidy->lvl,
|
||||
'total_amount' => $subsidy->total_amount,
|
||||
'total_earnings' => $subsidy->real_amount,
|
||||
'fee' => $subsidy->fee,
|
||||
'fee_rate' => $subsidy->fee_rate,
|
||||
'settle_at' => now(),
|
||||
'status' => DealerEarningStatus::Pending,
|
||||
'remark' => sprintf(
|
||||
"%s - %s\n%s",
|
||||
$subsidy->start_at->format('Y/m/d'),
|
||||
$subsidy->end_at->format('Y/m/d'),
|
||||
$remark
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算补贴总金额
|
||||
*
|
||||
* @param \App\Models\Dealer
|
||||
* @return array
|
||||
*/
|
||||
protected function calculateTotalAmount(DealerManagerSubsidy $subsidy): array
|
||||
{
|
||||
$salesLogs = DealerManagerSalesLog::with(['product'])
|
||||
->select(['product_id', DB::raw('sum(sales_volume) as sales_volume')])
|
||||
->where('user_id', $subsidy->user_id)
|
||||
->whereBetween('order_completed_at', [$subsidy->start_at, $subsidy->end_at])
|
||||
->groupBy('product_id')
|
||||
->get();
|
||||
|
||||
// 补贴总额
|
||||
$totalAmount = 0;
|
||||
// 备注信息
|
||||
$remark = '';
|
||||
|
||||
foreach ($salesLogs as $salesLog) {
|
||||
$amount = bcmul($salesLog->sales_volume, $salesLog->product->manager_subsidy, 2);
|
||||
$totalAmount = bcadd($totalAmount, $amount, 2);
|
||||
|
||||
if ($remark !== '') {
|
||||
$remark .= "\n";
|
||||
}
|
||||
|
||||
$remark .= "{$salesLog->product->name}\n销量: {$salesLog->sales_volume}\n补贴金额: {$amount}";
|
||||
}
|
||||
return [$totalAmount, $remark];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取给定时间端内的最后一个经销商补贴所属经销商的ID
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getLastDealerId(Carbon $startAt, Carbon $endAt): ?int
|
||||
{
|
||||
$lastManagerSubsidy = DealerManagerSubsidy::where('start_at', $startAt)
|
||||
->where('end_at', $endAt)
|
||||
->latest('id')
|
||||
->first();
|
||||
|
||||
return $lastManagerSubsidy?->dealer?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间
|
||||
*
|
||||
* @param float $milliseconds
|
||||
* @return string
|
||||
*/
|
||||
protected function formatDuration($milliseconds): string
|
||||
{
|
||||
if ($milliseconds < 0.01) {
|
||||
return round($milliseconds * 1000) . 'μs';
|
||||
} elseif ($milliseconds >= 1000) {
|
||||
return round($milliseconds / 1000, 2) . 's';
|
||||
}
|
||||
|
||||
return $milliseconds . 'ms';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\DealerOrderStatus;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Services\Dealer\OrderService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderAutoAllocate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:order-auto-allocate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '自动分配订单';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
while (true) {
|
||||
$page = 0;
|
||||
|
||||
DealerOrder::where('status', DealerOrderStatus::Pending)
|
||||
->where('consignor_id', '>', 1) // 到1用户或者公司的订单不需要再分配
|
||||
->where('allocated_at', '<', now()->subMinutes(app_settings('dealer.order_auto_allocate_times')))
|
||||
->chunkById(200, function ($orders) use (&$page) {
|
||||
$orders->load([
|
||||
'consignor',
|
||||
]);
|
||||
$orderService = new OrderService();
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->updateOrderConsignor($order);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
});
|
||||
|
||||
if ($page === 0) {
|
||||
sleep(60);
|
||||
} elseif ($page === 1) {
|
||||
sleep(30);
|
||||
} else {
|
||||
sleep(15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,556 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerManagerSalesLog;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerPurchaseLog;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderProcessCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:order-process';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '处理结算状态是待处理的已付款经销商订单';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
while (true) {
|
||||
$page = 0;
|
||||
|
||||
DealerOrder::settlePending()->chunkById(200, function ($orders) use (&$page) {
|
||||
$orders->load([
|
||||
'userInfo',
|
||||
'dealer.userInfo',
|
||||
'products.productManageSubsidyRules',
|
||||
]);
|
||||
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
DB::transaction(function () use ($order) {
|
||||
$this->handleDealerOrder($order);
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
$page += 1;
|
||||
}, 'paied_time');
|
||||
|
||||
if ($page === 0) {
|
||||
sleep(60);
|
||||
} else {
|
||||
sleep(5);
|
||||
}
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理经销商订单
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @return void
|
||||
*/
|
||||
protected function handleDealerOrder(DealerOrder $dealerOrder)
|
||||
{
|
||||
$tz = now()->toDateTimeString();
|
||||
|
||||
// 上级经销商
|
||||
$ancestors = $dealerOrder->dealer->getDealers();
|
||||
|
||||
// 签约经销商的进货日志
|
||||
$this->handlePurchaseLogsOfContractedDealer($dealerOrder, $tz);
|
||||
|
||||
// 一级签约经销商和二级经销商的管理津贴
|
||||
$this->handleManageSubsidyLogs($dealerOrder, $ancestors, $tz);
|
||||
|
||||
// 管理者的销售业绩
|
||||
$this->handleManagerSalesLogs($dealerOrder, $ancestors, $tz);
|
||||
|
||||
// 渠道补贴
|
||||
$this->handleChannelSubsidy($dealerOrder);
|
||||
|
||||
if ($dealerOrder->dealer->wasChanged('lvl')) {
|
||||
$dealers = [
|
||||
$dealerOrder->dealer,
|
||||
...$ancestors,
|
||||
];
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
$dealer->attemptUpgrade();
|
||||
}
|
||||
}
|
||||
|
||||
// 将订单标记为已处理
|
||||
$dealerOrder->forceFill([
|
||||
'settle_state' => DealerOrderSettleState::Processed,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算渠道补贴
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @return void
|
||||
*/
|
||||
protected function handleChannelSubsidy(DealerOrder $dealerOrder)
|
||||
{
|
||||
$lvl = $dealerOrder->dealer->lvl;
|
||||
|
||||
if ($dealerOrder->total_amount >= app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value)) {
|
||||
// 升级为签约
|
||||
if ($lvl->value < DealerLvl::Contracted->value) {
|
||||
$lvl = DealerLvl::Contracted;
|
||||
}
|
||||
} elseif ($dealerOrder->total_amount >= app_settings('dealer.upgrade_amount_'.DealerLvl::Special->value)) {
|
||||
// 升级为特约
|
||||
if ($lvl->value < DealerLvl::Special->value) {
|
||||
$lvl = DealerLvl::Special;
|
||||
}
|
||||
} elseif ($dealerOrder->total_amount >= app_settings('dealer.upgrade_amount_'.DealerLvl::Gold->value)) {
|
||||
// 升级为金牌
|
||||
if ($lvl->value < DealerLvl::Gold->value) {
|
||||
$lvl = DealerLvl::Gold;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果经销商等级小于金牌,则没有渠道补贴
|
||||
if ($lvl->value < DealerLvl::Gold->value) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$dealers, $rule] = $this->mapDealersAndRuleOfChannel($dealerOrder->dealer, $lvl);
|
||||
|
||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||
$upgradeAmount = app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value);
|
||||
} else {
|
||||
$upgradeAmount = app_settings('dealer.upgrade_amount_'.$lvl->value);
|
||||
}
|
||||
|
||||
// 手续费比例
|
||||
$feeRate = app_settings('dealer.fee_rate');
|
||||
|
||||
foreach ($dealers as $key => $dealer) {
|
||||
$ruleKey = $dealer->lvl->value.'_'.$key;
|
||||
|
||||
if ($dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
$ruleKey = DealerLvl::Contracted->value.'_'.$key;
|
||||
}
|
||||
|
||||
// 补贴金额
|
||||
$subsidyAmount = $rule[$ruleKey];
|
||||
|
||||
$totalAmount = bcmul($subsidyAmount, $dealerOrder->total_amount, 10);
|
||||
$totalAmount = bcdiv($totalAmount, $upgradeAmount, 3);
|
||||
$totalAmount = round($totalAmount, 2);
|
||||
|
||||
$channelSubsidyLog = DealerChannelSubsidyLog::create([
|
||||
'user_id' => $dealer->user_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'total_amount' => $totalAmount,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'remark' => "补贴总额={$dealerOrder->total_amount}/{$upgradeAmount}*{$subsidyAmount}",
|
||||
]);
|
||||
|
||||
$fee = bcmul($channelSubsidyLog->total_amount, bcdiv($feeRate, '100', 5), 3);
|
||||
$fee = round($fee, 2);
|
||||
|
||||
$channelSubsidyLog->earning()->create([
|
||||
'user_id' => $channelSubsidyLog->user_id,
|
||||
'lvl' => $channelSubsidyLog->lvl,
|
||||
'total_amount' => $channelSubsidyLog->total_amount,
|
||||
'total_earnings' => bcsub($channelSubsidyLog->total_amount, $fee, 2),
|
||||
'fee' => $fee,
|
||||
'fee_rate' => $feeRate,
|
||||
'payer_id' => $dealerOrder->consignor_id,
|
||||
'status' => DealerEarningStatus::Pending,
|
||||
'remark' => "订单号: {$dealerOrder->sn}",
|
||||
]);
|
||||
}
|
||||
|
||||
$dealerOrder->dealer->upgrade($lvl, '进货升级');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取渠道补贴经销商和补贴规则
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @param \App\Enums\DealerLvl $lvl
|
||||
* @return array
|
||||
*/
|
||||
protected function mapDealersAndRuleOfChannel(Dealer $dealer, DealerLvl $lvl): array
|
||||
{
|
||||
// 渠道补贴经销商
|
||||
$dealers = [];
|
||||
// 渠道补贴规则
|
||||
$rule = null;
|
||||
// 是否升级
|
||||
$isUp = $lvl->value > $dealer->lvl->value;
|
||||
// 最后参与渠道补贴的经销商
|
||||
$last = null;
|
||||
// 前一个直属邀请人
|
||||
$previous = null;
|
||||
|
||||
while (true) {
|
||||
if ($previous) {
|
||||
$_dealer = $previous->userInfo->realInviterInfo?->dealer;
|
||||
$_dealer?->setRelation('userInfo', $previous->userInfo->realInviterInfo);
|
||||
} else {
|
||||
$_dealer = $dealer->userInfo->realInviterInfo?->dealer;
|
||||
$_dealer?->setRelation('userInfo', $dealer->userInfo->realInviterInfo);
|
||||
}
|
||||
|
||||
$previous = $_dealer;
|
||||
|
||||
if ($_dealer === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 如果经销商等级小于金牌, 那么跳过
|
||||
if ($_dealer->lvl->value < DealerLvl::Gold->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||
if ($last === null) {
|
||||
if ($_dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
// 渠道补贴规则: 签约 -> 签约 -> 签约
|
||||
$rule = app_settings(sprintf(
|
||||
'dealer.channel_rules.%s_%s',
|
||||
DealerLvl::Contracted->value,
|
||||
DealerLvl::Contracted->value
|
||||
));
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
} elseif ($isUp && $_dealer->isSpecialDealer()) {
|
||||
// 渠道补贴规则: 签约 -> 特邀 -> 签约 -> 签约
|
||||
$rule = app_settings(sprintf(
|
||||
'dealer.channel_rules.%s_%s',
|
||||
DealerLvl::Contracted->value,
|
||||
DealerLvl::Special->value
|
||||
));
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($_dealer->lvl->value >= DealerLvl::Contracted->value) {
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
// 如果最后参与渠道补贴的经销商是签约, 那么已经找到所有参与渠道补贴的经销商
|
||||
if ($last->lvl->value >= DealerLvl::Contracted->value) {
|
||||
break;
|
||||
}
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($lvl === DealerLvl::Special) {
|
||||
if ($_dealer->lvl->value > DealerLvl::Special->value) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($last === null) {
|
||||
if ($_dealer->isSpecialDealer()) {
|
||||
// 渠道补贴规则: 特邀 -> 特邀 -> 特邀
|
||||
$rule = app_settings(sprintf(
|
||||
'dealer.channel_rules.%s_%s',
|
||||
DealerLvl::Special->value,
|
||||
DealerLvl::Special->value
|
||||
));
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
} elseif ($isUp && $_dealer->isGoldDealer()) {
|
||||
// 渠道补贴规则: 特邀 -> 金牌 -> 特邀 -> 特邀
|
||||
$rule = app_settings(sprintf(
|
||||
'dealer.channel_rules.%s_%s',
|
||||
DealerLvl::Special->value,
|
||||
DealerLvl::Gold->value
|
||||
));
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($_dealer->isSpecialDealer()) {
|
||||
$dealers[] = $_dealer;
|
||||
|
||||
if ($last->isSpecialDealer()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$last = $_dealer;
|
||||
}
|
||||
} elseif ($lvl === DealerLvl::Gold) {
|
||||
if ($_dealer->lvl->value >= DealerLvl::Gold->value) {
|
||||
if ($_dealer->isGoldDealer()) {
|
||||
// 渠道补贴规则: 金牌 -> 金牌
|
||||
$rule = app_settings(sprintf(
|
||||
'dealer.channel_rules.%s_%s',
|
||||
DealerLvl::Gold->value,
|
||||
DealerLvl::Gold->value
|
||||
));
|
||||
|
||||
$dealers[] = $_dealer;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$dealers, $rule];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签约经销商的进货日志
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handlePurchaseLogsOfContractedDealer(DealerOrder $dealerOrder, string $tz)
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dealer = $dealerOrder->userInfo->dealer;
|
||||
|
||||
// 采购业绩是否算自己的业绩
|
||||
$valid = $dealer->lvl->value >= DealerLvl::Contracted->value;
|
||||
|
||||
$log = new DealerPurchaseLog([
|
||||
'user_id' => $dealer->user_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'order_id' => $dealerOrder->id,
|
||||
'total_amount' => $dealerOrder->total_amount,
|
||||
'path' => $valid ? $dealerOrder->userInfo->full_path : $dealerOrder->userInfo->path,
|
||||
'remark' => $valid ? null : '升级签约',
|
||||
]);
|
||||
$log->setCreatedAt($tz);
|
||||
$log->setUpdatedAt($tz);
|
||||
$log->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配一级签约经销商和二级经销商的管理津贴
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handleManageSubsidyLogs(DealerOrder $dealerOrder, array $dealers, string $tz)
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = [];
|
||||
|
||||
foreach ($dealerOrder->products as $product) {
|
||||
if ($product->productManageSubsidyRules->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 管理津贴分配规则
|
||||
$rules = $product->productManageSubsidyRules->keyBy('lvl');
|
||||
|
||||
$last = null;
|
||||
$ranking = 0;
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
if (! in_array($dealer->lvl, [DealerLvl::Secondary, DealerLvl::Top])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果当前经销商等级没有对应的管理津贴分配规则,则忽略
|
||||
if (is_null($rule = $rules->get($dealer->lvl->value))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$qty = $product->qty + $product->deposit_qty;
|
||||
|
||||
// 同等级管理津贴最多给三次
|
||||
if ($last === null || $dealer->lvl->value > $last->lvl->value) {
|
||||
if ($ranking < 3 && $dealer->lvl === DealerLvl::Top) {
|
||||
if ($secondarySubsidyRule = $rules->get(DealerLvl::Secondary->value)) {
|
||||
$key = 'price_'.(1 + $ranking).'st';
|
||||
|
||||
$secondarySubsidy = $secondarySubsidyRule->{$key};
|
||||
|
||||
if (bccomp($secondarySubsidy, '0') === 1) {
|
||||
$logs[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'sales_volume' => $qty,
|
||||
'total_amount' => bcmul($qty, $secondarySubsidy, 2),
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ranking = 1;
|
||||
} elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) {
|
||||
$ranking++;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$subsidy = $rule->{"price_{$ranking}st"};
|
||||
|
||||
if (bccomp($subsidy, '0') === 1) {
|
||||
$logs[] = [
|
||||
'user_id' => $dealer->user_id,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'sales_volume' => $qty,
|
||||
'total_amount' => bcmul($qty, $subsidy, 2),
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
|
||||
$last = $dealer;
|
||||
}
|
||||
}
|
||||
|
||||
DealerManageSubsidyLog::insert($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤出可能会享受管理津贴的经销商(每个等级最多3人)
|
||||
*
|
||||
* @param array $dealers
|
||||
* @return array
|
||||
*/
|
||||
protected function mapManageSubsidyDealers(array $dealers): array
|
||||
{
|
||||
$map = [];
|
||||
$last = null;
|
||||
$ranking = 1;
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
if ($last === null || $dealer->lvl->value > $last->lvl->value) {
|
||||
$last = $dealer;
|
||||
$map[] = $last;
|
||||
$ranking = 1;
|
||||
} elseif ($ranking < 3 && $dealer->lvl->value === $last->lvl->value) {
|
||||
$last = $dealer;
|
||||
$map[] = $last;
|
||||
$ranking++;
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成管理者的销售业绩
|
||||
*
|
||||
* @param \App\Models\DealerOrder $dealerOrder
|
||||
* @param array $dealers
|
||||
* @param string $tz
|
||||
* @return void
|
||||
*/
|
||||
protected function handleManagerSalesLogs(DealerOrder $dealerOrder, array $dealers, string $tz): void
|
||||
{
|
||||
if (! $this->isContractedDealerToPurchase($dealerOrder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($manager = $this->firstManager($dealers))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logs = [];
|
||||
|
||||
foreach ($dealerOrder->products as $product) {
|
||||
$qty = $product->qty + $product->deposit_qty;
|
||||
|
||||
$logs[] = [
|
||||
'user_id' => $manager->user_id,
|
||||
'lvl' => $manager->lvl,
|
||||
'order_id' => $product->order_id,
|
||||
'product_id' => $product->product_id,
|
||||
'sales_volume' => $qty,
|
||||
'created_at' => $tz,
|
||||
'updated_at' => $tz,
|
||||
];
|
||||
}
|
||||
|
||||
DealerManagerSalesLog::insert($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从给定的经销商中获取第一个管理者
|
||||
*
|
||||
* @param array $dealers
|
||||
* @return \App\Models\Dealer|null
|
||||
*/
|
||||
protected function firstManager(array $dealers): ?Dealer
|
||||
{
|
||||
foreach ($dealers as $dealer) {
|
||||
if ($dealer->is_manager) {
|
||||
return $dealer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认是否是签约经销商进货
|
||||
*
|
||||
* @param DealerOrder $dealerOrder
|
||||
* @return bool
|
||||
*/
|
||||
protected function isContractedDealerToPurchase(DealerOrder $dealerOrder): bool
|
||||
{
|
||||
$dealer = $dealerOrder->userInfo->dealer;
|
||||
|
||||
if ($dealer->lvl->value < DealerLvl::Contracted->value) {
|
||||
if ($dealerOrder->total_amount < app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Enums\DealerSalesValueLogType;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerEarning;
|
||||
use App\Models\DealerManagerSalesLog;
|
||||
use App\Models\DealerManageSubsidyLog;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerPurchaseLog;
|
||||
use App\Models\DealerSalesValueLog;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderSettleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:order-settle';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '结算已完成的订单';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
while (true) {
|
||||
$page = 0;
|
||||
|
||||
DealerOrder::onlyPaidSuccessfully()
|
||||
->where('settle_state', DealerOrderSettleState::Processed)
|
||||
->whereNotNull('paied_time')
|
||||
->chunkById(200, function ($orders) use (&$page) {
|
||||
$orders->load('dealer.userInfo');
|
||||
|
||||
foreach ($orders as $order) {
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$this->handleDealerOrder($order);
|
||||
|
||||
DB::commit();
|
||||
} catch (Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
$page++;
|
||||
});
|
||||
|
||||
if ($page === 0) {
|
||||
sleep(60);
|
||||
} else {
|
||||
sleep(30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理经销商订单
|
||||
*
|
||||
* @param \App\Models\DealerOrder $order
|
||||
* @return void
|
||||
*/
|
||||
protected function handleDealerOrder(DealerOrder $order)
|
||||
{
|
||||
$this->handleManagerSalesLogs($order);
|
||||
|
||||
$this->handleManageSubsidyLogs($order);
|
||||
|
||||
$this->handleChannelSubsidyLogs($order);
|
||||
|
||||
$this->handlePurchaseLogs($order);
|
||||
|
||||
$this->handleOrder($order);
|
||||
}
|
||||
|
||||
protected function handleManagerSalesLogs(DealerOrder $order)
|
||||
{
|
||||
DealerManagerSalesLog::where('order_id', $order->id)->update([
|
||||
'order_completed_at' => $this->getOrderCompletedAt($order),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleManageSubsidyLogs(DealerOrder $order)
|
||||
{
|
||||
DealerManageSubsidyLog::where('order_id', $order->id)->update([
|
||||
'order_completed_at' => $this->getOrderCompletedAt($order),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleChannelSubsidyLogs(DealerOrder $order)
|
||||
{
|
||||
$channelSubsidyLogIds = DealerChannelSubsidyLog::where('order_id', $order->id)->get('id')->toArray();
|
||||
|
||||
DealerChannelSubsidyLog::whereIn('id', $channelSubsidyLogIds)->update([
|
||||
'order_completed_at' => $this->getOrderCompletedAt($order),
|
||||
]);
|
||||
|
||||
if ($order->consignor_id !== null) {
|
||||
DealerEarning::where('earningable_type', 'dealer_channel_subsidy_log')->whereIn('earningable_id', $channelSubsidyLogIds)->update([
|
||||
'settle_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handlePurchaseLogs(DealerOrder $order)
|
||||
{
|
||||
DealerPurchaseLog::where('order_id', $order->id)->update([
|
||||
'order_completed_at' => $this->getOrderCompletedAt($order),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleOrder(DealerOrder $order)
|
||||
{
|
||||
$salesValue = $order->total_amount;
|
||||
|
||||
if (bccomp($salesValue, '0', 2) < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$salesValueLogs = [];
|
||||
|
||||
if (bccomp($salesValue, '0', 2) === 1) {
|
||||
$ts = now()->toDateTimeString();
|
||||
|
||||
$order->dealer->update([
|
||||
'self_sales_value' => DB::raw("self_sales_value+{$salesValue}"),
|
||||
]);
|
||||
|
||||
$salesValueLogs[] = [
|
||||
'user_id' => $order->user_id,
|
||||
'loggable_type' => $order->getMorphClass(),
|
||||
'loggable_id' => $order->id,
|
||||
'type' => DealerSalesValueLogType::Personal,
|
||||
'change_sales_value' => $salesValue,
|
||||
'remark' => '个人进货',
|
||||
'created_at' => $ts,
|
||||
'updated_at' => $ts,
|
||||
];
|
||||
|
||||
if (count($pids = $order->dealer->userInfo->parent_ids) > 0) {
|
||||
foreach ($order->dealer->userInfo->parent_ids as $pid) {
|
||||
$salesValueLogs[] = [
|
||||
'user_id' => $pid,
|
||||
'loggable_type' => $order->getMorphClass(),
|
||||
'loggable_id' => $order->id,
|
||||
'type' => DealerSalesValueLogType::Team,
|
||||
'change_sales_value' => $salesValue,
|
||||
'remarks' => '团队成员进货',
|
||||
'created_at' => $ts,
|
||||
'updated_at' => $ts,
|
||||
];
|
||||
}
|
||||
|
||||
// 更新上级的团队团队业绩
|
||||
Dealer::whereIn('user_id', $pids)->update([
|
||||
'team_sales_value' => DB::raw("team_sales_value + {$salesValue}"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 保存销售值日志
|
||||
DealerSalesValueLog::insert($salesValueLogs);
|
||||
|
||||
// 将订单标记未已结算
|
||||
$order->forceFill([
|
||||
'settle_state' => DealerOrderSettleState::Completed,
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单完成时间
|
||||
*
|
||||
* @param DealerOrder $order
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function getOrderCompletedAt(DealerOrder $order): Carbon
|
||||
{
|
||||
if ($order->paied_time->lt('2022-04-19 11:00:00')) {
|
||||
return now();
|
||||
}
|
||||
|
||||
return $order->paied_time;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,401 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Actions\Dealer\CalculatePurchaseAmount;
|
||||
use App\Enums\DealerEarningStatus;
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Enums\DealerOrderSettleState;
|
||||
use App\Enums\DealerPurchaseSubsidySettleState;
|
||||
use App\Enums\DealerPurchaseSubsidyStatus;
|
||||
use App\Models\Dealer;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerPurchaseSubsidy;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PurchaseSubsidySettleCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:purchase-subsidy-settle';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '结算签约经销商的进货补贴';
|
||||
|
||||
/**
|
||||
* @var \App\Actions\Dealer\CalculatePurchaseAmount
|
||||
*/
|
||||
protected $calculatePurchaseAmount;
|
||||
|
||||
/**
|
||||
* @param \App\Actions\Dealer\CalculatePurchaseAmount $calculatePurchaseAmount
|
||||
*/
|
||||
public function __construct(CalculatePurchaseAmount $calculatePurchaseAmount)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->calculatePurchaseAmount = $calculatePurchaseAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tz = now();
|
||||
|
||||
if ($tz->day >= 20) {
|
||||
// 上月20号-当月19号的进货业绩
|
||||
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
|
||||
$endAt = $tz->copy()->setDay(19)->endOfDay();
|
||||
} else {
|
||||
// 上上月20号-上月19号的进货业绩
|
||||
$startAt = $tz->copy()->subMonthsNoOverflow(2)->setDay(20)->startOfDay();
|
||||
$endAt = $tz->copy()->subMonthNoOverflow()->setDay(19)->endOfDay();
|
||||
}
|
||||
|
||||
$head = '【'.$startAt->format('Y/m/d').'-'.$endAt->format('Y/m/d').'】';
|
||||
|
||||
$ordersCount = DealerOrder::onlyPaidSuccessfully()
|
||||
->where('settle_state', '!=', DealerOrderSettleState::Completed)
|
||||
->whereNotNull('paied_time')
|
||||
->where('paied_time', '<=', $endAt)
|
||||
->count();
|
||||
|
||||
if ($ordersCount > 0) {
|
||||
return $this->warn("{$head} 订单还没有结算完成!");
|
||||
}
|
||||
|
||||
$this->info("{$head}------------[开始]进货补贴结算------------");
|
||||
|
||||
$this->info("{$head}进货补贴初始化...");
|
||||
$this->initializePurchaseSubsidies($startAt, $endAt, 200);
|
||||
$this->info("{$head}进货补贴初始化完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}扣除上级的进货补贴...");
|
||||
$this->deductPurchaseSubsidies($startAt, $endAt, 200);
|
||||
$this->info("{$head}扣除上级的进货补贴完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}计算手续费...");
|
||||
$this->calculateFeeOfPurchaseSubsidies($startAt, $endAt, 200);
|
||||
$this->info("{$head}计算手续费完成".PHP_EOL);
|
||||
|
||||
$this->info("{$head}Done! 总耗时: ".$this->formatDuration($tz->diffInMilliseconds(now(), false)));
|
||||
|
||||
$this->info("{$head}------------[结束]进货补贴结算------------".PHP_EOL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算进货补贴手续费
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function calculateFeeOfPurchaseSubsidies(Carbon $startAt, Carbon $endAt, int $count = 200): void
|
||||
{
|
||||
DealerPurchaseSubsidy::where([
|
||||
'start_at' => $startAt,
|
||||
'end_at' => $endAt,
|
||||
'settle_state' => DealerPurchaseSubsidySettleState::Processed,
|
||||
])->chunkById($count, function ($purchaseSubsidies) {
|
||||
foreach ($purchaseSubsidies as $purchaseSubsidy) {
|
||||
DB::transaction(function () use ($purchaseSubsidy) {
|
||||
$this->calculateFeeOfPurchaseSubsidy($purchaseSubsidy);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算进货补贴手续费
|
||||
*
|
||||
* @param \App\Models\DealerPurchaseSubsidy $purchaseSubsidy
|
||||
* @return void
|
||||
*/
|
||||
protected function calculateFeeOfPurchaseSubsidy(DealerPurchaseSubsidy $purchaseSubsidy)
|
||||
{
|
||||
if (bccomp($purchaseSubsidy->total_amount, '0') === 1) {
|
||||
$feeRate = bcdiv($purchaseSubsidy->fee_rate, '100', 5);
|
||||
|
||||
$fee = bcmul($purchaseSubsidy->total_amount, $feeRate, 3);
|
||||
$fee = round($fee, 2);
|
||||
|
||||
$purchaseSubsidy->fee = $fee;
|
||||
$purchaseSubsidy->real_amount = bcsub($purchaseSubsidy->total_amount, $fee, 2);
|
||||
} else {
|
||||
$purchaseSubsidy->status = DealerPurchaseSubsidyStatus::Completed;
|
||||
}
|
||||
$purchaseSubsidy->settle_state = DealerPurchaseSubsidySettleState::Completed;
|
||||
$purchaseSubsidy->save();
|
||||
|
||||
if (! $purchaseSubsidy->isCompleted()) {
|
||||
$remark = sprintf(
|
||||
"%s - %s\n销售业绩: %s\n补贴比例: %s%%",
|
||||
$purchaseSubsidy->start_at->format('Y/m/d'),
|
||||
$purchaseSubsidy->end_at->format('Y/m/d'),
|
||||
$purchaseSubsidy->total_purchase_amount,
|
||||
$purchaseSubsidy->subsidy_rate
|
||||
);
|
||||
|
||||
$purchaseSubsidy->earning()->create([
|
||||
'user_id' => $purchaseSubsidy->user_id,
|
||||
'lvl' => $purchaseSubsidy->lvl,
|
||||
'total_amount' => $purchaseSubsidy->total_amount,
|
||||
'total_earnings' => $purchaseSubsidy->real_amount,
|
||||
'fee' => $purchaseSubsidy->fee,
|
||||
'fee_rate' => $purchaseSubsidy->fee_rate,
|
||||
'settle_at' => now(),
|
||||
'status' => DealerEarningStatus::Pending,
|
||||
'remark' => $remark,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扣除上级的进货补贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function deductPurchaseSubsidies(Carbon $startAt, Carbon $endAt, int $count = 200): void
|
||||
{
|
||||
DealerPurchaseSubsidy::where([
|
||||
'start_at' => $startAt,
|
||||
'end_at' => $endAt,
|
||||
'settle_state' => DealerPurchaseSubsidySettleState::Pending,
|
||||
])->chunkById($count, function ($purchaseSubsidies) {
|
||||
foreach ($purchaseSubsidies as $purchaseSubsidy) {
|
||||
DB::transaction(function () use ($purchaseSubsidy) {
|
||||
$this->deductPurchaseSubsidy($purchaseSubsidy);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 扣除上级的采购补贴总额
|
||||
*
|
||||
* @param \AppModels\DealerPurchaseSubsidy $purchaseSubsidy
|
||||
* @return void
|
||||
*/
|
||||
protected function deductPurchaseSubsidy(DealerPurchaseSubsidy $purchaseSubsidy)
|
||||
{
|
||||
// 扣除上级的进货补贴
|
||||
if ($purchaseSubsidy->payer_id && bccomp($purchaseSubsidy->total_subsidy, '0', 2) === 1) {
|
||||
$payerPurchaseSubsidy = DealerPurchaseSubsidy::where([
|
||||
'user_id' => $purchaseSubsidy->payer_id,
|
||||
'start_at' => $purchaseSubsidy->start_at,
|
||||
'end_at' => $purchaseSubsidy->end_at,
|
||||
])->first();
|
||||
|
||||
if ($payerPurchaseSubsidy) {
|
||||
$payerPurchaseSubsidy->decrement('total_amount', $purchaseSubsidy->total_subsidy);
|
||||
|
||||
$payerPurchaseSubsidy->logs()->create([
|
||||
'purchase_subsidy_id' => $payerPurchaseSubsidy->id,
|
||||
'change_from_purchase_subsidy_id' => $purchaseSubsidy->id,
|
||||
'change_amount' => bcmul($purchaseSubsidy->total_subsidy, '-1', 2),
|
||||
'remark' => '扣除下级的进货补贴',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$purchaseSubsidy->update([
|
||||
'settle_state' => DealerPurchaseSubsidySettleState::Processed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进货补贴
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @param int $count
|
||||
* @return void
|
||||
*/
|
||||
protected function initializePurchaseSubsidies(Carbon $startAt, Carbon $endAt, int $count = 200)
|
||||
{
|
||||
// 手续费比例
|
||||
$feeRate = app_settings('dealer.fee_rate');
|
||||
// 采购补贴规则
|
||||
$purchaseRules = (array) app_settings('dealer.purchase_rules');
|
||||
|
||||
$lastId = $this->getLastDealerId($startAt, $endAt);
|
||||
|
||||
do {
|
||||
$dealers = Dealer::with(['userInfo'])
|
||||
->where('contracted_lvl_at', '<=', $endAt)
|
||||
->where('lvl', '>=', DealerLvl::Contracted->value)
|
||||
->forPageAfterId($count, $lastId, 'id')
|
||||
->get();
|
||||
|
||||
$dealersCount = $dealers->count();
|
||||
|
||||
if ($dealersCount == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($dealers as $dealer) {
|
||||
DB::transaction(function () use ($dealer, $startAt, $endAt, $feeRate, $purchaseRules) {
|
||||
$this->initializePurchaseSubsidy($dealer, $startAt, $endAt, $feeRate, $purchaseRules);
|
||||
});
|
||||
|
||||
$lastId = $dealer->id;
|
||||
}
|
||||
|
||||
unset($dealers);
|
||||
} while ($dealersCount == $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化进货补贴
|
||||
*
|
||||
* @param Dealer $dealer
|
||||
* @param Carbon $startAt
|
||||
* @param Carbon $endAt
|
||||
* @param float $feeRate
|
||||
* @param array $purchaseRules
|
||||
* @return void
|
||||
*/
|
||||
protected function initializePurchaseSubsidy(Dealer $dealer, Carbon $startAt, Carbon $endAt, $feeRate, array $purchaseRules)
|
||||
{
|
||||
// 进货总额
|
||||
$totalPurchaseAmount = $this->calculatePurchaseAmount->handle($dealer, $startAt, $endAt);
|
||||
|
||||
// 如果没有进货总额,则返回
|
||||
if (bccomp($totalPurchaseAmount, '0', 2) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 进货补贴比例
|
||||
$subsidyRate = $this->filterSubsidyRate($totalPurchaseAmount, $purchaseRules);
|
||||
|
||||
// 补贴总额
|
||||
$totalSubsidy = bcmul($totalPurchaseAmount, bcdiv($subsidyRate, '100', 5), 3);
|
||||
$totalSubsidy = round($totalSubsidy, 2);
|
||||
|
||||
$purchaseSubsidy = DealerPurchaseSubsidy::create([
|
||||
'user_id' => $dealer->user_id,
|
||||
'payer_id' => $this->nearestContractedDealer($dealer, $endAt)?->user_id,
|
||||
'lvl' => $dealer->lvl,
|
||||
'total_purchase_amount' => $totalPurchaseAmount,
|
||||
'subsidy_rate' => $subsidyRate,
|
||||
'total_subsidy' => $totalSubsidy,
|
||||
'total_amount' => $totalSubsidy,
|
||||
'real_amount' => 0,
|
||||
'fee' => 0,
|
||||
'fee_rate' => $feeRate,
|
||||
'start_at' => $startAt,
|
||||
'end_at' => $endAt,
|
||||
'settle_state' => DealerPurchaseSubsidySettleState::Pending,
|
||||
'status' => DealerPurchaseSubsidyStatus::Pending,
|
||||
]);
|
||||
|
||||
if (bccomp($purchaseSubsidy->total_subsidy, '0', 2) === 1) {
|
||||
$purchaseSubsidy->logs()->create([
|
||||
'purchase_subsidy_id' => $purchaseSubsidy->id,
|
||||
'change_from_purchase_subsidy_id' => null,
|
||||
'change_amount' => $purchaseSubsidy->total_subsidy,
|
||||
'remark' => '进货补贴总额',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 进货补贴比例
|
||||
*
|
||||
* @param float $totalPurchaseAmount
|
||||
* @param array $purchaseRules
|
||||
* @return float
|
||||
*/
|
||||
protected function filterSubsidyRate($totalPurchaseAmount, array $purchaseRules)
|
||||
{
|
||||
$rate = '0';
|
||||
|
||||
foreach ($purchaseRules as $rule) {
|
||||
if (bccomp($totalPurchaseAmount, bcmul($rule['price'], '10000'), 2) === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bccomp($rule['rate'], $rate, 5) === 1) {
|
||||
$rate = $rule['rate'];
|
||||
}
|
||||
}
|
||||
|
||||
return $rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的上级签约经销商
|
||||
*
|
||||
* @param \App\Models\Dealer $dealer
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @return \App\Models\Dealer|null
|
||||
*/
|
||||
protected function nearestContractedDealer(Dealer $dealer, Carbon $endAt): ?Dealer
|
||||
{
|
||||
foreach ($dealer->getDealers() as $_dealer) {
|
||||
// 如果当前经销商等级小于签约,则跳过
|
||||
if ($_dealer->lvl->value < DealerLvl::Contracted->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($_dealer->contracted_lvl_at?->lte($endAt)) {
|
||||
return $_dealer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取给定时间端内的最后一个进货补贴所属经销商的ID
|
||||
*
|
||||
* @param \Illuminate\Support\Carbon $startAt
|
||||
* @param \Illuminate\Support\Carbon $endAt
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getLastDealerId(Carbon $startAt, Carbon $endAt): ?int
|
||||
{
|
||||
$lastPurchaseSubsidy = DealerPurchaseSubsidy::where('start_at', $startAt)
|
||||
->where('end_at', $endAt)
|
||||
->latest('id')
|
||||
->first();
|
||||
|
||||
return $lastPurchaseSubsidy?->dealer?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化时间
|
||||
*
|
||||
* @param float $milliseconds
|
||||
* @return string
|
||||
*/
|
||||
protected function formatDuration($milliseconds): string
|
||||
{
|
||||
if ($milliseconds < 0.01) {
|
||||
return round($milliseconds * 1000) . 'μs';
|
||||
} elseif ($milliseconds >= 1000) {
|
||||
return round($milliseconds / 1000, 2) . 's';
|
||||
}
|
||||
|
||||
return $milliseconds . 'ms';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Dealer;
|
||||
|
||||
use App\Enums\Bank;
|
||||
use App\Enums\DealerWalletToBankLogStatus;
|
||||
use App\Exceptions\YeePayException;
|
||||
use App\Models\DealerWalletToBankLog;
|
||||
use App\Services\YeePayService;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
class WalletToBankCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'dealer:wallet-to-bank';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '批零提现';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$yeePayService = new YeePayService(config('services.yeepay'));
|
||||
|
||||
while (true) {
|
||||
DealerWalletToBankLog::where('status', DealerWalletToBankLogStatus::Passed)->chunkById(1, function ($logs) use ($yeePayService) {
|
||||
foreach ($logs as $log) {
|
||||
try {
|
||||
$result = $yeePayService->request('accountpay.behalf.Pay', [
|
||||
'payerOutUserId' => '21102510220227100003' ?: config('services.yeepay.partner_id'),
|
||||
'merchOrderNo' => $log->pay_sn,
|
||||
'tradeName' => '批零提现',
|
||||
'payeeUserName' => data_get($log->pay_info, 'bank.user_name'),
|
||||
'bankCardNo' => data_get($log->pay_info, 'bank.bank_number'),
|
||||
'bankCode' => Bank::tryFromBankName(data_get($log->pay_info, 'bank.bank_name'))?->name,
|
||||
'bankCardType' => 'DEBIT_CARD',
|
||||
'amount' => $log->account_amount,
|
||||
'feeRole' => 'PAYER',
|
||||
'tradeMemo' => '批零提现',
|
||||
'context' => json_encode(['type' => 'dealer_wallet_to_bank']),
|
||||
]);
|
||||
|
||||
// 如果交易超时,重新发起支付
|
||||
if ($result['resultCode'] === 'TIME_OUT') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($result['orderStatus'] === 'SUCCESS') {
|
||||
$log->update([
|
||||
'status' => DealerWalletToBankLogStatus::Success,
|
||||
'pay_at' => now(),
|
||||
'failed_reason' => null,
|
||||
]);
|
||||
} elseif ($result['orderStatus'] === 'FAIL') {
|
||||
$log->update([
|
||||
'status' => DealerWalletToBankLogStatus::Failed,
|
||||
'failed_reason' => '交易失败',
|
||||
]);
|
||||
} else {
|
||||
$log->update([
|
||||
'status' => DealerWalletToBankLogStatus::Paying,
|
||||
'failed_reason' => null,
|
||||
]);
|
||||
}
|
||||
} catch (YeePayException $e) {
|
||||
$log->update([
|
||||
'status' => DealerWalletToBankLogStatus::Failed,
|
||||
'failed_reason' => $e->getMessage(),
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sleep(60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,17 +24,6 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('dealer:manage-subsidy-settle')
|
||||
->twiceMonthly(5, 20, '2:00')
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command('dealer:purchase-subsidy-settle')
|
||||
->monthlyOn(20, '3:00')
|
||||
->runInBackground();
|
||||
|
||||
$schedule->command('dealer:manager-subsidy-settle')
|
||||
->monthlyOn(1, '3:00')
|
||||
->runInBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,7 +9,4 @@ class Device
|
|||
|
||||
// 商户端
|
||||
public const MERCHANT = 'merchant';
|
||||
|
||||
// 经销商端
|
||||
public const DEALER = 'dealer';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Filters;
|
||||
|
||||
use App\Enums\DealerDeliveryBillStatus;
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class DealerDeliveryBillFilter extends ModelFilter
|
||||
{
|
||||
public function status($status)
|
||||
{
|
||||
switch ($status) {
|
||||
case 'pending':
|
||||
$this->where('status', DealerDeliveryBillStatus::Pending);
|
||||
break;
|
||||
|
||||
case 'paid':
|
||||
$this->where('status', DealerDeliveryBillStatus::Paid);
|
||||
break;
|
||||
|
||||
case 'cancelled':
|
||||
$this->where('status', DealerDeliveryBillStatus::Cancelled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Filters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class DealerOrderFilter extends ModelFilter
|
||||
{
|
||||
public function status($status)
|
||||
{
|
||||
switch ($status) {
|
||||
case 'pending'://待确认
|
||||
$this->onlyPending();
|
||||
break;
|
||||
case 'wait_pay'://待付款
|
||||
$this->onlyPendinged();
|
||||
break;
|
||||
case 'wait_paid'://待收款
|
||||
$this->onlyPaid();
|
||||
break;
|
||||
case 'wait_shipping'://待发货
|
||||
$this->onlyShipping();
|
||||
break;
|
||||
case 'wait_shippinged'://待收货
|
||||
$this->onlyShippinged();
|
||||
break;
|
||||
case 'completed'://已完成
|
||||
$this->onlyCompleted();
|
||||
break;
|
||||
case 'cancelled'://已取消
|
||||
$this->onlyCancelled();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Filters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class DealerUserProductLogFilter extends ModelFilter
|
||||
{
|
||||
public function productId($productId)
|
||||
{
|
||||
$this->where('product_id', $productId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Filters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class DealerWalletLogFilter extends ModelFilter
|
||||
{
|
||||
public function action($action)
|
||||
{
|
||||
switch ($action) {
|
||||
case 'wallet-transfer'://余额转账明细
|
||||
$this->onlyTransfer();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,16 +60,6 @@ class LoginController extends Controller
|
|||
throw new BizException('账户没有权限');
|
||||
}
|
||||
|
||||
// 清理此用户的商户端令牌
|
||||
$user->tokens()->where('name', $device)->delete();
|
||||
// 颁发新的商户端令牌
|
||||
$token = $user->createToken($device);
|
||||
break;
|
||||
case Device::DEALER:
|
||||
if (!$user->isDealer()) {
|
||||
throw new BizException('账户没有权限');
|
||||
}
|
||||
|
||||
// 清理此用户的商户端令牌
|
||||
$user->tokens()->where('name', $device)->delete();
|
||||
// 颁发新的商户端令牌
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ class LogoutController extends Controller
|
|||
'm_cid' => null,
|
||||
]);
|
||||
break;
|
||||
case Device::DEALER:
|
||||
break;
|
||||
default:
|
||||
// 解绑用户商城端cid
|
||||
$cid->update([
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue