From b1378b39233ff6b3e4716f036855df04b6cde560 Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Thu, 20 Jan 2022 10:52:28 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=8F=E9=94=80=E5=95=86?=
=?UTF-8?q?=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Actions/Grid/DealerSignManager.php | 63 --------
.../Actions/Grid/DealerUnsignManager.php | 63 --------
app/Admin/Controllers/DealerController.php | 146 +++++++++++++++---
.../Controllers/DealerEarningController.php | 26 +++-
app/Admin/routes.php | 5 +-
app/Models/Dealer.php | 36 +++--
app/Providers/AppServiceProvider.php | 2 +
app/Services/Dealer/OrderService.php | 2 +-
database/seeders/AdminMenuSeeder.php | 7 +-
9 files changed, 177 insertions(+), 173 deletions(-)
delete mode 100644 app/Admin/Actions/Grid/DealerSignManager.php
delete mode 100644 app/Admin/Actions/Grid/DealerUnsignManager.php
diff --git a/app/Admin/Actions/Grid/DealerSignManager.php b/app/Admin/Actions/Grid/DealerSignManager.php
deleted file mode 100644
index d3ceb6fb..00000000
--- a/app/Admin/Actions/Grid/DealerSignManager.php
+++ /dev/null
@@ -1,63 +0,0 @@
-title) {
- return $this->title;
- }
- return ' 标记管理员 ';
- }
-
- /**
- * @param Model|Authenticatable|HasPermissions|null $user
- *
- * @return bool
- */
- protected function authorize($user): bool
- {
- return $user->can('dcat.admin.dealers.sign_manager');
- }
-
- /**
- * Handle the action request.
- *
- * @param Request $request
- *
- * @return Response
- */
- public function handle(Request $request)
- {
- $dealer = Dealer::findOrFail($this->getKey());
- try {
- DB::beginTransaction();
- $dealer->update([
- 'is_manager'=>true,
- ]);
- 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 ['确认标记当前用户为管理者?'];
- }
-}
diff --git a/app/Admin/Actions/Grid/DealerUnsignManager.php b/app/Admin/Actions/Grid/DealerUnsignManager.php
deleted file mode 100644
index 61a3a7c4..00000000
--- a/app/Admin/Actions/Grid/DealerUnsignManager.php
+++ /dev/null
@@ -1,63 +0,0 @@
-title) {
- return $this->title;
- }
- return ' 取消管理员 ';
- }
-
- /**
- * @param Model|Authenticatable|HasPermissions|null $user
- *
- * @return bool
- */
- protected function authorize($user): bool
- {
- return $user->can('dcat.admin.dealers.unsign_manager');
- }
-
- /**
- * Handle the action request.
- *
- * @param Request $request
- *
- * @return Response
- */
- public function handle(Request $request)
- {
- $dealer = Dealer::findOrFail($this->getKey());
- try {
- DB::beginTransaction();
- $dealer->update([
- 'is_manager'=>false,
- ]);
- 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 ['确认取消标记当前用户为管理者?'];
- }
-}
diff --git a/app/Admin/Controllers/DealerController.php b/app/Admin/Controllers/DealerController.php
index a0394c36..a131a536 100644
--- a/app/Admin/Controllers/DealerController.php
+++ b/app/Admin/Controllers/DealerController.php
@@ -4,15 +4,17 @@ namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\DealerBonds;
use App\Admin\Actions\Grid\DealerEditLvl;
-use App\Admin\Actions\Grid\DealerSignManager;
-use App\Admin\Actions\Grid\DealerUnsignManager;
use App\Admin\Repositories\Dealer;
use App\Enums\DealerLvl;
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
{
@@ -25,7 +27,7 @@ class DealerController extends AdminController
{
$builder = Dealer::with(['user', 'userInfo', 'userInfo.inviterInfo.user']);
return Grid::make($builder, function (Grid $grid) {
- $grid->column('id')->sortable();
+ // $grid->column('id')->sortable();
$grid->column('user.phone')->copyable();
$grid->column('userInfo.nickname');
$grid->column('userInfo.inviterInfo.user.phone')->copyable();
@@ -33,23 +35,38 @@ class DealerController extends AdminController
$grid->column('lvl')->display(function () {
return $this->lvl_text;
});
- $grid->column('is_sale');
- $grid->column('is_manager')->bool();
+ $grid->column('is_sale')
+ ->if(function () {
+ return Admin::user()->can('dcat.admin.dealers.edit');
+ })
+ ->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.edit');
+ })
+ ->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(' 显示 ');
+ }
if (Admin::user()->can('dcat.admin.dealers.edit_lvl')) {
$actions->append(new DealerEditLvl());
}
- if (!$actions->row->is_manager && Admin::user()->can('dcat.admin.dealers.sign_manager')) {
- $actions->append(new DealerSignManager());
- }
- if ($actions->row->is_manager && Admin::user()->can('dcat.admin.dealers.unsign_manager')) {
- $actions->append(new DealerUnsignManager());
- }
if ($actions->row->lvl->value >= DealerLvl::Special->value && Admin::user()->can('dcat.admin.dealers.bonds')) {
$actions->append(new DealerBonds());
}
@@ -72,16 +89,97 @@ class DealerController extends AdminController
*/
protected function detail($id)
{
- return Show::make($id, new Dealer(), function (Show $show) {
- $show->field('id');
- $show->field('user_id');
- $show->field('lvl');
- $show->field('is_sale');
- $show->field('is_manager');
- $show->field('pay_info');
- $show->field('created_at');
- $show->field('updated_at');
- });
+ 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('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) {
+ $tab = Tab::make();
+ // 预收益明细
+ $tab->add('剩余库存', '');
+ // 可提明细
+ $tab->add('资金记录', '');
+ // 上级列表
+ $tab->add('上级列表', '');
+ $column->row(Box::make('用户记录', $tab));
+ });
+ };
+
+ // return Show::make($id, new Dealer(), function (Show $show) {
+ // $show->field('id');
+ // $show->field('user_id');
+ // $show->field('lvl');
+ // $show->field('is_sale');
+ // $show->field('is_manager');
+ // // $show->field('pay_info');
+ // $show->field('created_at');
+ // $show->field('updated_at');
+ // });
}
/**
@@ -93,11 +191,11 @@ class DealerController extends AdminController
{
return Form::make(new Dealer(), function (Form $form) {
$form->display('id');
- $form->text('user_id');
- $form->text('lvl');
+ // $form->text('user_id');
+ // $form->text('lvl');
$form->text('is_sale');
$form->text('is_manager');
- $form->text('pay_info');
+ // $form->text('pay_info');
$form->display('created_at');
$form->display('updated_at');
diff --git a/app/Admin/Controllers/DealerEarningController.php b/app/Admin/Controllers/DealerEarningController.php
index 969b6367..92836a02 100644
--- a/app/Admin/Controllers/DealerEarningController.php
+++ b/app/Admin/Controllers/DealerEarningController.php
@@ -3,6 +3,10 @@
namespace App\Admin\Controllers;
use App\Admin\Repositories\DealerEarning;
+use App\Models\DealerChannelSubsidyLog;
+use App\Models\DealerManagerSubsidy;
+use App\Models\DealerManageSubsidy;
+use App\Models\DealerPurchaseSubsidy;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
@@ -19,11 +23,17 @@ class DealerEarningController extends AdminController
{
$earning = DealerEarning::with('user');
return Grid::make($earning, function (Grid $grid) {
+ $grid->setResource('dealer-earnings');
$grid->column('id')->sortable();
$grid->column('user.phone');
$grid->column('type_name')->display(function () {
return $this->type_name;
- })->label();
+ })->label()->filter(Grid\Column\Filter\In::make([
+ (new DealerManagerSubsidy())->getMorphClass() =>'管理者补贴',
+ (new DealerManageSubsidy())->getMorphClass() =>'管理补贴',
+ (new DealerChannelSubsidyLog())->getMorphClass() =>'渠道补贴',
+ (new DealerPurchaseSubsidy())->getMorphClass() =>'进货补贴',
+ ])->setColumnName('earningable_type'));
// $grid->column('earningable_type');
// $grid->column('earningable_id');
$grid->column('lvl')->display(function () {
@@ -41,15 +51,21 @@ class DealerEarningController extends AdminController
$grid->column('status_format')->display(function ($value) {
return $this->status_format;
})->using([
- -1=>'待结算',
- 0=>'待打款',
- 1=>'待收款',
- 2=>'已完成',
+ -1=> '待结算',
+ 0 => '待打款',
+ 1 => '待收款',
+ 2 => '已完成',
])->dot();
$grid->column('remark');
// $grid->column('pay_image');
$grid->column('created_at')->sortable();
+ $grid->actions(function (Grid\Displayers\Actions $actions) {
+ //如果不是渠道补贴添加详情显示
+ if ($actions->row->earningable_type != (new DealerChannelSubsidyLog())->getMorphClass()) {
+ $actions->append(' 显示 ');
+ }
+ });
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
diff --git a/app/Admin/routes.php b/app/Admin/routes.php
index e0256abc..f342ed75 100644
--- a/app/Admin/routes.php
+++ b/app/Admin/routes.php
@@ -169,10 +169,13 @@ Route::group([
])->names('dealer_orders');
$router->get('dealer-manager-orders', 'DealerOrderController@index')->name('dealer_orders.manager');
$router->resource('dealer-users', 'DealerController')->only([
- 'index',
+ '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');
/** api接口 **/
diff --git a/app/Models/Dealer.php b/app/Models/Dealer.php
index 9a9a0a3b..ef89c8aa 100644
--- a/app/Models/Dealer.php
+++ b/app/Models/Dealer.php
@@ -13,7 +13,7 @@ class Dealer extends Model
protected $attributes = [
'lvl' => DealerLvl::None,
- 'is_sale' => false,
+ 'is_sale' => true,
'is_manager' => false,
'self_sales_value' => 0,
'team_sales_value' => 0,
@@ -88,24 +88,30 @@ class Dealer extends Model
*/
public function getSaleValuesAttribute()
{
- $tz = now();
+ return $this->self_sales_value + $this->team_sales_value;
+ // $tz = now();
- if ($tz->day >= 20) {
- // 结算当月20号开始的业绩
- $startAt = $tz->copy()->setDay(20)->startOfDay();
- } elseif ($tz->day >= 5) {
- // 结算当月5号开始的的业绩
- $startAt = $tz->copy()->setDay(5)->startOfDay();
- } else {
- // 结算上月20号开始的业绩
- $startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
- }
+ // if ($tz->day >= 20) {
+ // // 结算当月20号开始的业绩
+ // $startAt = $tz->copy()->setDay(20)->startOfDay();
+ // } elseif ($tz->day >= 5) {
+ // // 结算当月5号开始的的业绩
+ // $startAt = $tz->copy()->setDay(5)->startOfDay();
+ // } else {
+ // // 结算上月20号开始的业绩
+ // $startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
+ // }
- return DealerPurchaseLog::query()->where('order_completed_at', '>=', $startAt)
- ->where('path', 'like', "{$this->userInfo->full_path}%")
- ->sum('total_amount');
+ // return DealerPurchaseLog::query()->where('order_completed_at', '>=', $startAt)
+ // ->where('path', 'like', "{$this->userInfo->full_path}%")
+ // ->sum('total_amount');
}
+ /**
+ * 实时管理津贴
+ *
+ * @return void
+ */
public function getCalculateTotalAmountAttribute()
{
$tz = now();
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 09dbb1ec..22548093 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -9,6 +9,7 @@ use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
+use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Overtrue\EasySms\EasySms;
@@ -21,6 +22,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
+ // Schema::defaultStringLength(191);
$this->registerEasySms();
$this->registerEasyWeChat();
$this->registerRequestRealIp();
diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php
index 2b057876..9a2805e0 100644
--- a/app/Services/Dealer/OrderService.php
+++ b/app/Services/Dealer/OrderService.php
@@ -334,7 +334,7 @@ class OrderService
$query->whereIn('user_id', $user->userInfo->real_parent_ids);//自己的上级
}
$consignor = $query->whereHas('dealer', function ($q) use ($lvl) {
- return $q->where('lvl', '>', $lvl);//经销商身份大于自己的
+ return $q->where('is_sale', true)->where('lvl', '>', $lvl);//可销售的经销商,且身份大于自己的
})->orderBy('depth', 'desc')->first();//深度逆序第一个
if (!$consignor) {
$consignor = $lastConsignor;
diff --git a/database/seeders/AdminMenuSeeder.php b/database/seeders/AdminMenuSeeder.php
index 6e615323..beb53df6 100644
--- a/database/seeders/AdminMenuSeeder.php
+++ b/database/seeders/AdminMenuSeeder.php
@@ -309,10 +309,15 @@ class AdminMenuSeeder extends Seeder
'icon' => '',
'uri' => 'dealer-manager-orders?type=manager',
],
+ [
+ 'title' =>'用户资金',
+ 'icon'=>'',
+ 'uri' => 'dealer-earnings',
+ ],
[
'title' =>'渠道补贴',
'icon'=>'',
- 'uri' => 'dealer-earnings-channel?type=channel',
+ 'uri' => 'dealer-earnings-channel?filter-earningable_type[]=dealer_channel_subsidy_log',
],
[
'title' =>'进货补贴',