6
0
Fork 0

调整经销商管理

release
vine_liutk 2022-01-20 10:52:28 +08:00 committed by 李静
parent a3874baa05
commit b1378b3923
9 changed files with 177 additions and 173 deletions

View File

@ -1,63 +0,0 @@
<?php
namespace App\Admin\Actions\Grid;
use App\Models\Dealer;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerSignManager extends RowAction
{
public function title()
{
if ($this->title) {
return $this->title;
}
return '<i class="feather icon-sunrise grid-action-icon"></i> 标记管理员 &nbsp;&nbsp;';
}
/**
* @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 ['确认标记当前用户为管理者?'];
}
}

View File

@ -1,63 +0,0 @@
<?php
namespace App\Admin\Actions\Grid;
use App\Models\Dealer;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerUnsignManager extends RowAction
{
public function title()
{
if ($this->title) {
return $this->title;
}
return '<i class="feather icon-sunset grid-action-icon"></i> 取消管理员 &nbsp;&nbsp;';
}
/**
* @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 ['确认取消标记当前用户为管理者?'];
}
}

View File

@ -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('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealers.show', ['dealer_user'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 &nbsp;&nbsp;</a>');
}
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');

View File

@ -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('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_earnings.show', ['dealer_earning'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 &nbsp;&nbsp;</a>');
}
});
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();

View File

@ -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接口 **/

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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' =>'进货补贴',