From 94fbe336353d61b80d66250e023a000bd739b1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Fri, 25 Mar 2022 12:49:29 +0800 Subject: [PATCH 01/15] Update --- app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php index 330cfc28..05e0d184 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php @@ -18,6 +18,8 @@ class OrderSimpleResource extends JsonResource 'id' => $this->id, 'sn' =>$this->sn, 'total_amount' => $this->total_amount, + 'paied_time' => $this->paied_time?->toDateTimeString(), + 'shippinged_time' => $this->shippinged_time?->toDateTimeString(), 'created_at' => $this->created_at->toDateTimeString(), 'status' => $this->status, 'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份 From b2ef9cbc3f13fe3fd76efdba98446b6fbf60b250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Fri, 25 Mar 2022 14:35:15 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E8=BF=9B=E8=B4=A7=E8=A1=A5=E8=B4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/DealerEarningController.php | 1 + app/Admin/Controllers/DealerPurchaseSubsidyController.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/Admin/Controllers/DealerEarningController.php b/app/Admin/Controllers/DealerEarningController.php index 4d194f45..9f937172 100644 --- a/app/Admin/Controllers/DealerEarningController.php +++ b/app/Admin/Controllers/DealerEarningController.php @@ -120,6 +120,7 @@ class DealerEarningController extends AdminController $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')); }); }); diff --git a/app/Admin/Controllers/DealerPurchaseSubsidyController.php b/app/Admin/Controllers/DealerPurchaseSubsidyController.php index c15f12ee..7b738f88 100644 --- a/app/Admin/Controllers/DealerPurchaseSubsidyController.php +++ b/app/Admin/Controllers/DealerPurchaseSubsidyController.php @@ -99,6 +99,8 @@ class DealerPurchaseSubsidyController extends AdminController }); $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')); }); }); From 161478fdcafe5bccac93701609c0aafb4e1cb2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Fri, 25 Mar 2022 15:20:44 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E8=BF=9B=E8=B4=A7=E4=B8=9A=E7=BB=A9?= =?UTF-8?q?=E6=AF=8F=E6=9C=8820=E5=8F=B7=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dealer/PurchaseSubsidySettleCommand.php | 14 +++++--------- app/Console/Kernel.php | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/Dealer/PurchaseSubsidySettleCommand.php b/app/Console/Commands/Dealer/PurchaseSubsidySettleCommand.php index d9270b2a..3c83ae0d 100644 --- a/app/Console/Commands/Dealer/PurchaseSubsidySettleCommand.php +++ b/app/Console/Commands/Dealer/PurchaseSubsidySettleCommand.php @@ -56,17 +56,13 @@ class PurchaseSubsidySettleCommand extends Command $tz = now(); if ($tz->day >= 20) { - // 结算当月5号-19号的管理津贴 - $startAt = $tz->copy()->setDay(5)->startOfDay(); + // 上月20号-当月19号的进货业绩 + $startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay(); $endAt = $tz->copy()->setDay(19)->endOfDay(); - } elseif ($tz->day >= 5) { - // 结算上月20号-到当月4号的管理津贴 - $startAt = $tz->copy()->subMonthNoOverflow()->set('day', 20)->startOfDay(); - $endAt = $tz->copy()->set('day', 4)->endOfDay(); } else { - // 结算上月5号-到19号的管理津贴 - $startAt = $tz->copy()->subMonthNoOverflow()->setDay(5)->startOfDay(); - $endAt = $startAt->copy()->setDay(19)->endOfDay(); + // 上上月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').'】'; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index eaac9232..bd8371a0 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -29,7 +29,7 @@ class Kernel extends ConsoleKernel ->runInBackground(); $schedule->command('dealer:purchase-subsidy-settle') - ->twiceMonthly(5, 20, '3:00') + ->twiceMonthly(20, '3:00') ->runInBackground(); $schedule->command('dealer:manager-subsidy-settle') From a08bdab76cbf718a5b2abf6d41f3047d1563633b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 09:51:27 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=B4=A5=E8=B4=B4?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=A2=9E=E5=8A=A0=E4=B8=8B=E5=8D=95=E4=BA=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dealer/ManageSubsidyLogController.php | 2 +- .../Resources/Dealer/OrderSimpleResource.php | 3 +-- .../Http/Resources/Dealer/UserResource.php | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 app/Endpoint/Api/Http/Resources/Dealer/UserResource.php diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/ManageSubsidyLogController.php b/app/Endpoint/Api/Http/Controllers/Dealer/ManageSubsidyLogController.php index 098742fe..b4b3dbbc 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/ManageSubsidyLogController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/ManageSubsidyLogController.php @@ -22,7 +22,7 @@ class ManageSubsidyLogController extends Controller $perPage = Paginator::resolvePerPage('per_page', 20, 50); - $manageSubsidyLogs = DealerManageSubsidyLog::with(['product', 'order']) + $manageSubsidyLogs = DealerManageSubsidyLog::with(['product', 'order.user']) ->when($isComplted, function ($query) { $tz = now(); diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php index 05e0d184..ae509660 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php @@ -18,12 +18,11 @@ class OrderSimpleResource extends JsonResource 'id' => $this->id, 'sn' =>$this->sn, 'total_amount' => $this->total_amount, - 'paied_time' => $this->paied_time?->toDateTimeString(), - 'shippinged_time' => $this->shippinged_time?->toDateTimeString(), 'created_at' => $this->created_at->toDateTimeString(), 'status' => $this->status, 'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份 'products' => OrderProductResource::collection($this->whenLoaded('products')), + 'user' => UserResource::make($this->whenLoaded('user')), ]; } } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/UserResource.php b/app/Endpoint/Api/Http/Resources/Dealer/UserResource.php new file mode 100644 index 00000000..fd30cf4f --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/Dealer/UserResource.php @@ -0,0 +1,26 @@ + $this->id, + 'phone' => $this->phone, + 'nickname' => (string) $this->userInfo->nickname, + 'avatar' => (string) $this->userInfo->avatar, + 'gender' => (string) $this->userInfo->gender, + 'code' => (string) $this->userInfo->code, + ]; + } +} From c8da24009ecbafcbc96534e9e5304887bd800641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 10:44:09 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E7=AD=BE=E7=BA=A6=E7=BB=8F=E9=94=80?= =?UTF-8?q?=E5=95=86=E7=9A=84=E6=B8=A0=E9=81=93=E8=A1=A5=E8=B4=B4=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DealerChannelSubsidyController.php | 63 ++---- .../Dealer/ChannelSubsidySettleCommand.php | 192 ++++++++++++++++++ .../Commands/Dealer/OrderSettleCommand.php | 8 +- 3 files changed, 219 insertions(+), 44 deletions(-) create mode 100644 app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php diff --git a/app/Admin/Controllers/DealerChannelSubsidyController.php b/app/Admin/Controllers/DealerChannelSubsidyController.php index fa9b2ecd..1bec7053 100644 --- a/app/Admin/Controllers/DealerChannelSubsidyController.php +++ b/app/Admin/Controllers/DealerChannelSubsidyController.php @@ -59,10 +59,6 @@ class DealerChannelSubsidyController extends AdminController return $this->settle_at?->toDateTimeString(); })->sortable(); $grid->column('status', '状态')->display(function ($v) { - if (! $this->isSettled()) { - return "  待结算"; - } - return "  {$v->text()}"; }); $grid->column('pay_at', '付款时间')->display(function () { @@ -72,50 +68,35 @@ class DealerChannelSubsidyController extends AdminController return $this->created_at?->toDateTimeString(); }); - $grid->showRowSelector(); + // $grid->showRowSelector(); + // $grid->tools(function ($tools) { + // $tools->batch(function ($batch) { + // $batch->disableDelete(); - $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()); + // } + // }); + // }); - if (Admin::user()->can('dcat.admin.dealer_channel_subsidies.batch_pay')) { - $batch->add(new DealerChannelSubsidyBatchPay()); - } - }); - }); - - $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->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->where('status', function ($query) { - switch ($this->input) { - case 'pending': - $query->whereNull('settle_at')->where('status', DealerEarningStatus::Pending); - break; - - case 'paying': - $query->whereNotNull('settle_at')->where('status', DealerEarningStatus::Pending); - break; - - case 'completed': - $query->where('status', DealerEarningStatus::Completed); - break; - } - }, '状态')->select([ - 'pending' => '待结算', - 'paying' => '待付款', - 'completed' => '已完成', + $filter->equal('status', '状态')->select([ + DealerEarningStatus::Pending->value => '待付款', + DealerEarningStatus::Completed->value => '已完成', ])->width(3); $filter->between('settle_at', '结算时间')->datetime()->width(6); }); diff --git a/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php b/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php new file mode 100644 index 00000000..0eac0b73 --- /dev/null +++ b/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php @@ -0,0 +1,192 @@ +withoutPayer()->onlyPending()->chunkById(200, function ($earnings) use (&$page) { + $earnings->load('dealer.userInfo'); + + 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); + } elseif ($page === 1) { + sleep(30); + } else { + sleep(15); + } + } + } + + /** + * 处理经销商订单 + * + * @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' => $order->shippinged_time, + ]); + } + + protected function handleManageSubsidyLogs(DealerOrder $order) + { + DealerManageSubsidyLog::where('order_id', $order->id)->update([ + 'order_completed_at' => $order->shippinged_time, + ]); + } + + protected function handleChannelSubsidyLogs(DealerOrder $order) + { + $channelSubsidyLogIds = DealerChannelSubsidyLog::where('order_id', $order->id)->get('id')->toArray(); + + DealerChannelSubsidyLog::whereIn('id', $channelSubsidyLogIds)->update([ + 'order_completed_at' => $order->shippinged_time, + ]); + + 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' => $order->shippinged_time, + ]); + } + + 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(); + } +} diff --git a/app/Console/Commands/Dealer/OrderSettleCommand.php b/app/Console/Commands/Dealer/OrderSettleCommand.php index 709d4cf8..7e3a46f8 100644 --- a/app/Console/Commands/Dealer/OrderSettleCommand.php +++ b/app/Console/Commands/Dealer/OrderSettleCommand.php @@ -117,9 +117,11 @@ class OrderSettleCommand extends Command 'order_completed_at' => $order->shippinged_time, ]); - DealerEarning::where('earningable_type', 'dealer_channel_subsidy_log')->whereIn('earningable_id', $channelSubsidyLogIds)->update([ - 'settle_at' => now(), - ]); + 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) From e298e35fc2bfaf8a45225eacc021e7bb3a573d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 10:49:48 +0800 Subject: [PATCH 06/15] Fix --- app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php b/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php index 0eac0b73..607afe68 100644 --- a/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php +++ b/app/Console/Commands/Dealer/ChannelSubsidySettleCommand.php @@ -44,7 +44,7 @@ class ChannelSubsidySettleCommand extends Command $page = 0; DealerEarning::channelSubsidy()->withoutPayer()->onlyPending()->chunkById(200, function ($earnings) use (&$page) { - $earnings->load('dealer.userInfo'); + $earnings->load(['earningable', 'user']); foreach ($earnings as $earning) { try { From 6b7e59147a7cc9ea3221e7e36a4910d98578a05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 10:59:48 +0800 Subject: [PATCH 07/15] Fix --- app/Admin/Actions/Show/DealerEarningPay.php | 2 +- app/Admin/Forms/DealerEarningPay.php | 2 +- .../Renderable/DealerEarningSimpleTable.php | 21 +++++++++---------- .../Dealer/DealerEarningSimpleResource.php | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/Admin/Actions/Show/DealerEarningPay.php b/app/Admin/Actions/Show/DealerEarningPay.php index 6ab63a0b..913bf386 100644 --- a/app/Admin/Actions/Show/DealerEarningPay.php +++ b/app/Admin/Actions/Show/DealerEarningPay.php @@ -70,7 +70,7 @@ class DealerEarningPay extends AbstractTool $action = DealerWalletAction::PurchaseSubsidyIn; break; } - $walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->type_name, $earning); + $walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->earningable_type_text, $earning); DB::commit(); } catch (Throwable $th) { DB::rollBack(); diff --git a/app/Admin/Forms/DealerEarningPay.php b/app/Admin/Forms/DealerEarningPay.php index 960fe899..cd670344 100644 --- a/app/Admin/Forms/DealerEarningPay.php +++ b/app/Admin/Forms/DealerEarningPay.php @@ -68,7 +68,7 @@ class DealerEarningPay extends Form implements LazyRenderable break; } - $walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->type_name, $earning); + $walletService->changeBalance($earning->user, $earning->total_earnings, $action, '收入-'.$earning->earningable_type_text, $earning); DB::commit(); } catch (Throwable $th) { DB::rollBack(); diff --git a/app/Admin/Renderable/DealerEarningSimpleTable.php b/app/Admin/Renderable/DealerEarningSimpleTable.php index 6a43dd4b..81258914 100644 --- a/app/Admin/Renderable/DealerEarningSimpleTable.php +++ b/app/Admin/Renderable/DealerEarningSimpleTable.php @@ -11,7 +11,7 @@ class DealerEarningSimpleTable extends LazyRenderable { public function grid(): Grid { - $userId = $this->payload['id']??0; + $userId = $this->payload['id'] ?? 0; $builder = DealerEarning::query(); // dd($userId); $builder->with(['user', 'payer'])->where(function ($q) use ($userId) { @@ -22,8 +22,8 @@ class DealerEarningSimpleTable extends LazyRenderable $grid->column('payer_id', '付款人')->display(function () { return $this->payer_id ? $this->payer?->phone : '公司'; }); - $grid->column('type_name', '资金类型')->display(function () { - return $this->type_name; + $grid->column('earningable_type_text', '资金类型')->display(function () { + return $this->earningable_type_text; })->label(); $grid->column('remark', '备注')->display('详情') // 设置按钮名称 ->expand(function () { @@ -39,14 +39,13 @@ class DealerEarningSimpleTable extends LazyRenderable // $grid->column('fee_rate', '手续费率')->append('%'); // $grid->column('fee', '手续费')->prepend('¥'); $grid->column('total_earnings', '实际金额')->prepend('¥'); - $grid->column('status_format', '状态')->display(function ($value) { - return $this->status_format; - })->using([ - -1=> '待结算', - 0 => '待打款', - 1 => '待收款', - 2 => '已完成', - ])->dot(); + $grid->column('status', '状态')->display(function ($v) { + if (! $this->isSettled()) { + return "  待结算"; + } + + return "  {$v->text()}"; + }); $grid->column('created_at', '创建时间'); $grid->column('id', '操作')->display('查看')->link(function ($value) { return admin_route('dealer_earnings.show', ['dealer_earning' => $this->id]); diff --git a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php index 29517787..9427bf80 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/DealerEarningSimpleResource.php @@ -16,7 +16,7 @@ class DealerEarningSimpleResource extends JsonResource { return [ 'id' => $this->id, - 'type' => $this->type_name, + 'type' => $this->earningable_type_text, 'created_at' => $this->created_at->toDateTimeString(), 'total_earnings'=> $this->total_earnings, 'status' => $this->status_format, From b9c86da3f926213d34c46379bb6a751958dcc9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 11:02:56 +0800 Subject: [PATCH 08/15] WIP --- .../Renderable/DealerEarningSimpleTable.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Admin/Renderable/DealerEarningSimpleTable.php b/app/Admin/Renderable/DealerEarningSimpleTable.php index 81258914..e3849ab6 100644 --- a/app/Admin/Renderable/DealerEarningSimpleTable.php +++ b/app/Admin/Renderable/DealerEarningSimpleTable.php @@ -2,7 +2,11 @@ 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; @@ -22,9 +26,19 @@ class DealerEarningSimpleTable extends LazyRenderable $grid->column('payer_id', '付款人')->display(function () { return $this->payer_id ? $this->payer?->phone : '公司'; }); - $grid->column('earningable_type_text', '资金类型')->display(function () { + $grid->column('earningable_type', '资金类型')->display(function () { return $this->earningable_type_text; - })->label(); + })->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('remark', '备注')->display('详情') // 设置按钮名称 ->expand(function () { // 这里返回 content 字段内容,并用 Card 包裹起来 From 9b28685e3523e0ed6f0b76b190f4e530e8fdf917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 11:04:05 +0800 Subject: [PATCH 09/15] WIP --- app/Admin/Renderable/DealerEarningSimpleTable.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/Admin/Renderable/DealerEarningSimpleTable.php b/app/Admin/Renderable/DealerEarningSimpleTable.php index e3849ab6..85b628b8 100644 --- a/app/Admin/Renderable/DealerEarningSimpleTable.php +++ b/app/Admin/Renderable/DealerEarningSimpleTable.php @@ -33,12 +33,7 @@ class DealerEarningSimpleTable extends LazyRenderable (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('remark', '备注')->display('详情') // 设置按钮名称 ->expand(function () { // 这里返回 content 字段内容,并用 Card 包裹起来 From db092125dab12eeb693becc455db9d7bc9b6e4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 28 Mar 2022 14:17:43 +0800 Subject: [PATCH 10/15] Fix --- app/Models/Dealer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Dealer.php b/app/Models/Dealer.php index e7c0a696..8ab571d1 100644 --- a/app/Models/Dealer.php +++ b/app/Models/Dealer.php @@ -323,8 +323,8 @@ class Dealer extends Model */ public function getArchivedPurchaseAmountAttribute() { - return Cache::remember('dealer_archived_purchase_amount:'.$this->user_id, 3600, function () { - return $this->purchaseSubsidies()->sum('total_purchase_amount'); + return Cache::remember('dealer_archived_purchase_amount_v2:'.$this->user_id, 3600, function () { + return bcmul($this->purchaseSubsidies()->sum('total_purchase_amount'), '1', 2); }); } From 8f3d3929c9bb0dd224e80c4638547d1d1ac0b618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 29 Mar 2022 14:55:08 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Product/ProductSkuController.php | 27 +++++++++++++++++++ app/Endpoint/Api/routes.php | 2 ++ 2 files changed, 29 insertions(+) diff --git a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php index ef8c3e35..d80e227a 100644 --- a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php +++ b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php @@ -11,6 +11,7 @@ use App\Helpers\Paginator; use App\Models\ProductSku; use App\Models\ProductSkuFavorite; use App\Models\ProductSpu; +use EasyWeChat\Factory as EasyWeChat; use Illuminate\Http\Request; class ProductSkuController extends Controller @@ -152,4 +153,30 @@ class ProductSkuController extends Controller return response()->noContent(); } + + /** + * 分享商品 + * + * @param int $id + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function share($id, Request $request) + { + $user = $request->user(); + + $sku = ProductSku::findOrFail($id); + + $app = EasyWeChat::miniProgram(config('wechat.mini_program.default')); + + $scene = http_build_query([ + 'product' => $sku->id, + 'code' => $user->userInfo->code, + ]); + + return $app->app_code->getUnlimit($scene, [ + 'page' => 'pages/index/index', + 'width' => $request->query('width', 200), + ]); + } } diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 85e53985..c4b351f4 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -122,6 +122,8 @@ Route::group([ Route::put('user-bank', [UserBankController::class, 'update']); Route::get('banks-options', [UserBankController::class, 'options']); + // 商品分销 + Route::get('product/products/{product}/share', [ProductSkuController::class, 'share']); // 收藏商品 Route::post('product/products/{product}/collect', [ProductSkuController::class, 'collect']); // 取消商品收藏 From b4dae3373bfbb95befa8e28c6433e1887fdded60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 29 Mar 2022 17:41:03 +0800 Subject: [PATCH 12/15] Update --- .../Controllers/Product/ProductSkuController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php index d80e227a..fa411309 100644 --- a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php +++ b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php @@ -7,11 +7,13 @@ use App\Endpoint\Api\Http\Resources\ProduckSkuResource; use App\Endpoint\Api\Http\Resources\ProductFeatureResource; use App\Endpoint\Api\Http\Resources\ProductSkuTinyResource; use App\Events\ProductSkuViewed; +use App\Exceptions\BizException; use App\Helpers\Paginator; use App\Models\ProductSku; use App\Models\ProductSkuFavorite; use App\Models\ProductSpu; use EasyWeChat\Factory as EasyWeChat; +use EasyWeChat\Kernel\Http\StreamResponse; use Illuminate\Http\Request; class ProductSkuController extends Controller @@ -174,9 +176,17 @@ class ProductSkuController extends Controller 'code' => $user->userInfo->code, ]); - return $app->app_code->getUnlimit($scene, [ + $response = $app->app_code->getUnlimit($scene, [ 'page' => 'pages/index/index', 'width' => $request->query('width', 200), ]); + + if ($response instanceof StreamResponse) { + return response()->json([ + 'image' => 'data:image/png;base64,'.base64_encode($response->getBody()), + ]); + } + + throw new BizException('分享失败'); } } From 745ba98708753a382d3a3e6542f05dca5412ba02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Wed, 30 Mar 2022 11:35:17 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/Auth/LoginController.php | 67 ++++++++++++++++--- app/Models/SmsCode.php | 2 + app/Services/SmsCodeService.php | 1 + 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php b/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php index 7845e2a3..b26e995e 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php @@ -5,9 +5,12 @@ namespace App\Endpoint\Api\Http\Controllers\Auth; use App\Constants\Device; use App\Endpoint\Api\Http\Controllers\Controller; use App\Exceptions\BizException; +use App\Models\SmsCode; use App\Models\User; use App\Models\UserInfo; +use App\Services\SmsCodeService; use Illuminate\Http\Request; +use Illuminate\Support\Str; class LoginController extends Controller { @@ -19,21 +22,29 @@ class LoginController extends Controller */ public function __invoke(Request $request) { - $validated = $request->validate([ - 'phone' => ['bail', 'required', 'string'], - 'password' => ['bail', 'required', 'string'], + $request->validate([ + 'type' => ['bail', 'filled'], + ], [], [ + 'type' => '登录类型', ]); - $user = User::where('phone', $validated['phone'])->first(); + $type = strtolower($request->input('type', 'password')); - if (! $user?->verifyPassword($validated['password'])) { - throw new BizException(__('Incorrect account or password')); + $method = 'loginUsing'.Str::studly($type); + + if (! method_exists($this, $method)) { + throw new BizException('登录类型 非法'); } - if ($user->old_password) { - $user->password = $validated['password']; - $user->old_password = null; + $user = $this->{$method}($request); + + if ($type === 'password') { + if ($user->old_password) { + $user->password = $request->input('password'); + $user->old_password = null; + } } + $user->last_login_at = now(); $user->last_login_ip = $request->realIp(); $user->save(); @@ -75,4 +86,42 @@ class LoginController extends Controller 'token' => $token->plainTextToken, ]); } + + protected function loginUsingPassword(Request $request) + { + $validated = $request->validate([ + 'phone' => ['bail', 'required', 'string'], + 'password' => ['bail', 'required', 'string'], + ], [], [ + 'phone' => '手机号', + 'password' => '密码', + ]); + + $user = User::where('phone', $validated['phone'])->first(); + + if (! $user?->verifyPassword($validated['password'])) { + throw new BizException(__('Incorrect account or password')); + } + + return $user; + } + + protected function loginUsingVerifyCode(Request $request) + { + $validated = $request->validate([ + 'phone' => ['bail', 'required', 'string'], + 'verify_code' => ['bail', 'required', 'string'], + ], [], [ + 'phone' => '手机号', + 'verify_code' => '验证码', + ]); + + app(SmsCodeService::class)->validate( + $validated['phone'], + SmsCode::TYPE_LOGIN, + $validated['verify_code'] + ); + + return User::where('phone', $validated['phone'])->firstOrFail(); + } } diff --git a/app/Models/SmsCode.php b/app/Models/SmsCode.php index 73d030ba..d42c333d 100644 --- a/app/Models/SmsCode.php +++ b/app/Models/SmsCode.php @@ -15,6 +15,7 @@ class SmsCode extends Model public const TYPE_REGISTER = 1; public const TYPE_RESET_PASSWORD = 2; public const TYPE_SET_WALLET_PASSWORD = 3; + public const TYPE_LOGIN = 4; /** * @var array @@ -53,6 +54,7 @@ class SmsCode extends Model self::TYPE_REGISTER, self::TYPE_RESET_PASSWORD, self::TYPE_SET_WALLET_PASSWORD, + self::TYPE_LOGIN, ]; /** diff --git a/app/Services/SmsCodeService.php b/app/Services/SmsCodeService.php index e97130e8..33e4d789 100644 --- a/app/Services/SmsCodeService.php +++ b/app/Services/SmsCodeService.php @@ -53,6 +53,7 @@ class SmsCodeService break; + case SmsCode::TYPE_LOGIN: case SmsCode::TYPE_RESET_PASSWORD: case SmsCode::TYPE_SET_WALLET_PASSWORD: if ($user === null) { From 567b23c0434dae50eaca11bf3f825835f5b6b73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Wed, 30 Mar 2022 13:53:27 +0800 Subject: [PATCH 14/15] Fix --- .../Api/Http/Controllers/Product/ProductSkuController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php index fa411309..858e36c0 100644 --- a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php +++ b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php @@ -177,7 +177,8 @@ class ProductSkuController extends Controller ]); $response = $app->app_code->getUnlimit($scene, [ - 'page' => 'pages/index/index', + 'page' => 'pages/welcome/index', + 'check_path' => false, 'width' => $request->query('width', 200), ]); From 79aaa1bd79b1b864010de0f640dd1f2d71652874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Wed, 30 Mar 2022 14:01:45 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=A0=81?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Product/ProductSkuController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php index 858e36c0..2d0ecddf 100644 --- a/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php +++ b/app/Endpoint/Api/Http/Controllers/Product/ProductSkuController.php @@ -179,6 +179,7 @@ class ProductSkuController extends Controller $response = $app->app_code->getUnlimit($scene, [ 'page' => 'pages/welcome/index', 'check_path' => false, + 'env_version' => app()->isProduction() ? 'release' : 'trial', 'width' => $request->query('width', 200), ]);