From 210413542bea8753eab4a45f2ac98bc019204b0f Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Mon, 9 May 2022 10:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=BB=91=E5=AE=9A=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Show/UserEditVip.php | 32 +++++++++ app/Admin/Controllers/SettingController.php | 2 - app/Admin/Controllers/UserController.php | 29 ++++---- app/Admin/Controllers/VipController.php | 27 +++++--- app/Admin/Forms/Settings/Distribution.php | 68 ------------------- app/Admin/Forms/UserEditVip.php | 62 +++++++++++++++++ .../Auth/MiniprogramController.php | 17 +++-- app/Services/DistributeService.php | 22 ------ database/seeders/AdminPermissionSeeder.php | 1 + database/seeders/DatabaseSeeder.php | 1 + database/seeders/VipSeeder.php | 9 ++- resources/lang/zh_CN/vip.php | 2 + 12 files changed, 150 insertions(+), 122 deletions(-) create mode 100644 app/Admin/Actions/Show/UserEditVip.php delete mode 100644 app/Admin/Forms/Settings/Distribution.php create mode 100644 app/Admin/Forms/UserEditVip.php diff --git a/app/Admin/Actions/Show/UserEditVip.php b/app/Admin/Actions/Show/UserEditVip.php new file mode 100644 index 00000000..c51bfccc --- /dev/null +++ b/app/Admin/Actions/Show/UserEditVip.php @@ -0,0 +1,32 @@ + 设置代理'; + + /** + * 按钮样式定义,默认 btn btn-white waves-effect + * + * @var string + */ + protected $style = 'btn-warning'; + + public function render() + { + $form = UserEditPhoneForm::make()->payload(['id'=>$this->getKey()]); + return Modal::make() + ->lg() + ->title($this->title) + ->body($form) + ->button("style}\">{$this->title}  "); + } +} diff --git a/app/Admin/Controllers/SettingController.php b/app/Admin/Controllers/SettingController.php index e54250a2..070ebf77 100644 --- a/app/Admin/Controllers/SettingController.php +++ b/app/Admin/Controllers/SettingController.php @@ -9,7 +9,6 @@ use App\Admin\Forms\Settings\Ios; use App\Admin\Forms\Settings\Kuaidi100; use App\Admin\Forms\Settings\Unipush; use App\Admin\Forms\Settings\Withdraw; -use App\Admin\Forms\Settings\Distribution; use App\Admin\Repositories\Setting; use Dcat\Admin\Admin; use Dcat\Admin\Form; @@ -115,7 +114,6 @@ class SettingController extends AdminController 'android' => ['name' => 'Android配置', 'form' => new Android(), 'route' => admin_route('settings.index', ['type'=>'android'])], 'kuaidi100' => ['name' => '快递100配置', 'form' => new Kuaidi100(), 'route' => admin_route('settings.index', ['type'=>'kuaidi100'])], 'unipush' => ['name' => 'Uni-push配置', 'form' => new Unipush(), 'route' => admin_route('settings.index', ['type'=>'unipush'])], - 'distribution' => ['name' => '分销配置', 'form' => new Distribution(), 'route' => admin_route('settings.index', ['type'=>'distribution'])], 'custom' => ['name' => '自定义配置', 'form' => new Custom(), 'route' => admin_route('settings.index', ['type'=>'custom'])], ]; if (isset($tabs[$type])) { diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php index 2dcbcd0b..5c1dbb3a 100644 --- a/app/Admin/Controllers/UserController.php +++ b/app/Admin/Controllers/UserController.php @@ -9,6 +9,7 @@ use App\Admin\Actions\Grid\UserResetAccountPassword; use App\Admin\Actions\Grid\UserResetPassword; use App\Admin\Actions\Show\UserEditBank; use App\Admin\Actions\Show\UserEditPhone; +use App\Admin\Actions\Show\UserEditVip; use App\Admin\Renderable\Grid\Filter\PriceBetween; use App\Admin\Renderable\UserBalanceLogSimpleTable; use App\Admin\Renderable\UserFansSimpleTable; @@ -160,15 +161,15 @@ class UserController extends AdminController $show->field('user_info.growth_value'); - $show->field('wallet.balance')->as(function ($value) { - $value = bcdiv($value, 100, 2); - return $value; - })->prepend('¥'); - $show->field('balance.balance')->as(function ($value) { - $value = bcdiv($value, 100, 2); - return $value; - })->prepend('¥'); - $show->field('user_info.points'); + // $show->field('wallet.balance')->as(function ($value) { + // $value = bcdiv($value, 100, 2); + // return $value; + // })->prepend('¥'); + // $show->field('balance.balance')->as(function ($value) { + // $value = bcdiv($value, 100, 2); + // return $value; + // })->prepend('¥'); + // $show->field('user_info.points'); }); $show->row(function (Show\Row $show) { $show->width(6)->field('last_login_ip'); @@ -189,17 +190,21 @@ class UserController extends AdminController if (Admin::user()->can('dcat.admin.users.edit_bank')) { $tools->append(new UserEditBank()); } + // 设置代理等级 + if (Admin::user()->can('dcat.admin.users.edit_vip')) { + $tools->append(new UserEditVip()); + } }); })); }); $row->column(7, function ($column) use ($id) { $tab = Tab::make(); // 可提明细 - $tab->add('可提明细', UserWalletLogSimpleTable::make(['id'=>$id])); + // $tab->add('可提明细', UserWalletLogSimpleTable::make(['id'=>$id])); // 余额明细 - $tab->add('余额明细', UserBalanceLogSimpleTable::make(['id'=>$id])); + // $tab->add('余额明细', UserBalanceLogSimpleTable::make(['id'=>$id])); // 粉丝列表 - $tab->add('粉丝列表', UserFansSimpleTable::make(['id'=>$id])); + // $tab->add('粉丝列表', UserFansSimpleTable::make(['id'=>$id])); // 上级列表 $tab->add('上级列表', UserInviterSimpleTable::make(['id'=>$id])); $column->row(Box::make('用户记录', $tab)); diff --git a/app/Admin/Controllers/VipController.php b/app/Admin/Controllers/VipController.php index 182b31f3..3123088c 100644 --- a/app/Admin/Controllers/VipController.php +++ b/app/Admin/Controllers/VipController.php @@ -21,24 +21,27 @@ class VipController extends AdminController protected function grid() { return Grid::make(new Vip(), function (Grid $grid) { - $grid->column('id')->sortable(); + $grid->column('sort'); $grid->column('name'); - $grid->column('growth_value')->sortable(); + $grid->column('ratio')->display(function ($value) { + return $value . '%'; + }); + $grid->column('growth_value'); - $grid->model()->orderBy('growth_value', 'asc'); + $grid->model()->orderBy('sort', 'asc'); /** 操作 **/ //新增 - if (Admin::user()->can('dcat.admin.vips.create')) { - $grid->disableCreateButton(false); - $grid->enableDialogCreate(); - } + // if (Admin::user()->can('dcat.admin.vips.create')) { + // $grid->disableCreateButton(false); + // $grid->enableDialogCreate(); + // } //修改 $grid->showQuickEditButton(Admin::user()->can('dcat.admin.vips.edit')); //删除以及自定义操作 - $grid->actions(function (Grid\Displayers\Actions $actions) { - $actions->disableDelete(Admin::user()->cannot('dcat.admin.vips.destroy')); - }); + // $grid->actions(function (Grid\Displayers\Actions $actions) { + // $actions->disableDelete(Admin::user()->cannot('dcat.admin.vips.destroy')); + // }); $grid->filter(function (Grid\Filter $filter) { $filter->panel(false); @@ -59,6 +62,9 @@ class VipController extends AdminController return Show::make($id, new Vip(), function (Show $show) { $show->field('id'); $show->field('name'); + $show->column('ratio')->as(function ($value) { + return $value . '%'; + }); $show->field('growth_value'); $show->field('created_at'); $show->field('updated_at'); @@ -75,6 +81,7 @@ class VipController extends AdminController return Form::make(new Vip(), function (Form $form) { $form->display('id'); $form->text('name')->required(); + $form->number('ratio')->min(0)->max(100)->help('例如: 60%, 填写 60 即可'); $form->number('growth_value')->min(0)->default(0); $form->display('created_at'); diff --git a/app/Admin/Forms/Settings/Distribution.php b/app/Admin/Forms/Settings/Distribution.php deleted file mode 100644 index 2f0b484c..00000000 --- a/app/Admin/Forms/Settings/Distribution.php +++ /dev/null @@ -1,68 +0,0 @@ -updateOrCreate([ - 'key' => 'distribution', - ], ['value' => $input]); - - //清配置缓存 - app(SettingService::class)->cleanCache('distribution'); - - return $this - ->response() - ->success('配置更新成功!') - ->refresh(); - } - - /** - * Build a form here. - */ - public function form() - { - $values = Setting::where('key', 'distribution')->value('value'); - $levels = DistributeService::$levels; - $favoite = $levels['favoite']; - $agent = $levels['agent']; - $this->fieldset('爱好者-返利', function (Form $form) use ($favoite) { - foreach($favoite as $item) { - $form->number('favoite-profit-' . $item['level'], $item['name'])->min(0)->max(100)->help('例如: 40, 即表示: 40%'); - } - }); - $this->fieldset('爱好者-升级', function (Form $form) use ($favoite) { - foreach($favoite as $item) { - $form->number('favoite-level-' . $item['level'], $item['name'])->min(0)->help('例如: 1000'); - } - })->collapsed(); - $this->fieldset('代理-返利', function (Form $form) use ($agent) { - foreach($agent as $item) { - $form->number('agent-profit-' . $item['level'], $item['name'])->min(0)->max(100)->help('例如: 40, 即表示: 40%'); - } - })->collapsed(); - } - - public function default() - { - $values = Setting::where('key', 'distribution')->value('value'); - return $values; - } -} diff --git a/app/Admin/Forms/UserEditVip.php b/app/Admin/Forms/UserEditVip.php new file mode 100644 index 00000000..65aed84c --- /dev/null +++ b/app/Admin/Forms/UserEditVip.php @@ -0,0 +1,62 @@ +can('dcat.admin.users.edit_vip'); + } + + /** + * Handle the form request. + * + * @param array $input + * + * @return mixed + */ + public function handle(array $input) + { + $id = $this->payload['id'] ?? 0; + $user = User::findOrFail($id); + try { + DB::beginTransaction(); + $user->update($input); + 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() + { + $id = $this->payload['id'] ?? 0; + $user = User::findOrFail($id); + + $this->text('old_phone', '旧手机号')->value($user->phone)->disable(); + + $this->mobile('phone')->rules('unique:users,phone', ['unique'=>'该手机号已存在'])->required(); + } +} diff --git a/app/Endpoint/Api/Http/Controllers/Auth/MiniprogramController.php b/app/Endpoint/Api/Http/Controllers/Auth/MiniprogramController.php index 8ce9059c..4d2ac672 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/MiniprogramController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/MiniprogramController.php @@ -100,23 +100,26 @@ class MiniprogramController extends Controller // 检测手机号是否已经注册 $old_user = User::where('phone', $phone)->where('status', User::STATUS_ACTIVE)->where('id', '!=', $user->id)->first(); if ($old_user) { - // 禁用老用户 - $old_user->update([ + // 禁用新用户 + $user->update([ 'phone' => '', 'status' => User::STATUS_DISABLED, 'status_remark' => '手机号重复: ' . $phone ]); - } - - if ($user->phone !== $phone) { + } else { $user->update([ 'phone' => $phone, 'phone_verified_at' => now(), ]); } - + + $token = $old_user->createToken(SocialiteType::WechatMiniProgram->value); + DB::commit(); - return response()->noContent(); + + return response()->json([ + 'token' => $token->plainTextToken + ]); } catch (Throwable $e) { DB::rollBack(); diff --git a/app/Services/DistributeService.php b/app/Services/DistributeService.php index ef23e4a6..eeb7db61 100644 --- a/app/Services/DistributeService.php +++ b/app/Services/DistributeService.php @@ -9,19 +9,6 @@ use App\Models\{User, Order, SalesValueLog}; */ class DistributeService { - public static $levels = [ - 'favoite' => [ - ['name' => '金', 'level' => 'v3'], - ['name' => '银', 'level' => 'v2'], - ['name' => '铜', 'level' => 'v1'], - ], - 'agent' => [ - ['name' => '省', 'level' => 'v3'], - ['name' => '市', 'level' => 'v2'], - ['name' => '区', 'level' => 'v1'], - ] - ]; - /** * 用户下单后, 更新成长值, 添加返现记录 * @@ -54,14 +41,5 @@ class DistributeService if ($parents->count() === 0) { return false; } - - $setting = new SettingService(); - $conf = $setting->get('distribution'); - foreach($parents as $item) { - $slug = explode('-', $item->userInfo->role); - $role = $slug[0]; - $level = $slug[1]; - $ratio = data_get($conf, $role . '-profit-' . $level); - } } } diff --git a/database/seeders/AdminPermissionSeeder.php b/database/seeders/AdminPermissionSeeder.php index cc382b92..44fc680b 100644 --- a/database/seeders/AdminPermissionSeeder.php +++ b/database/seeders/AdminPermissionSeeder.php @@ -84,6 +84,7 @@ class AdminPermissionSeeder extends Seeder 'reset_account_password'=>['name' =>'修改安全密码'], 'edit_phone'=>['name' =>'修改手机号'], 'edit_bank'=>['name'=>'修改银行卡'], + 'edit_vip'=>['name'=>'设置代理'], ], ], 'article_categories' =>[ diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 27905e4d..25c50238 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,6 +17,7 @@ class DatabaseSeeder extends Seeder $this->call([ AdminSeeder::class, AppSettingSeeder::class, + VipSeeder::class, ]); if (! App::isProduction()) { diff --git a/database/seeders/VipSeeder.php b/database/seeders/VipSeeder.php index 311a9712..96aaaf53 100644 --- a/database/seeders/VipSeeder.php +++ b/database/seeders/VipSeeder.php @@ -14,8 +14,15 @@ class VipSeeder extends Seeder */ public function run() { + $time = now(); $list = [ - ['name' => '省级代理', 'slug' => 'agent', 'sort' => 1] + ['name' => '省级代理', 'slug' => 'agent', 'growth_value' => 90000, 'ratio' => 60, 'sort' => 1, 'created_at' => $time, 'updated_at' => $time], + ['name' => '市级代理', 'slug' => 'agent', 'growth_value' => 80000, 'ratio' => 50, 'sort' => 2, 'created_at' => $time, 'updated_at' => $time], + ['name' => '区级代理', 'slug' => 'agent', 'growth_value' => 70000, 'ratio' => 40, 'sort' => 3, 'created_at' => $time, 'updated_at' => $time], + ['name' => '金级爱好者', 'slug' => 'favoite', 'growth_value' => 50000, 'ratio' => 30, 'sort' => 4, 'created_at' => $time, 'updated_at' => $time], + ['name' => '银级爱好者', 'slug' => 'favoite', 'growth_value' => 50000, 'ratio' => 20, 'sort' => 5, 'created_at' => $time, 'updated_at' => $time], + ['name' => '铜级爱好者', 'slug' => 'favoite', 'growth_value' => 5000, 'ratio' => 10, 'sort' => 6, 'created_at' => $time, 'updated_at' => $time], ]; + Vip::insert($list); } } diff --git a/resources/lang/zh_CN/vip.php b/resources/lang/zh_CN/vip.php index 0aa4c053..33314ebf 100644 --- a/resources/lang/zh_CN/vip.php +++ b/resources/lang/zh_CN/vip.php @@ -8,6 +8,8 @@ return [ 'fields' => [ 'name' => '等级名称', 'growth_value' => '等级成长值', + 'sort' => '排序', + 'ratio' => '比例' ], 'options' => [ 'deny' => '删除失败',