6
0
Fork 0

微信绑定手机号

release
panliang 2022-05-09 10:13:18 +08:00
parent f93753fd7d
commit 210413542b
12 changed files with 150 additions and 122 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\UserEditPhone as UserEditPhoneForm;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
class UserEditVip extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-box"></i>&nbsp;设置代理';
/**
* 按钮样式定义,默认 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("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>&nbsp;&nbsp;");
}
}

View File

@ -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])) {

View File

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

View File

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

View File

@ -1,68 +0,0 @@
<?php
namespace App\Admin\Forms\Settings;
use App\Models\Setting;
use App\Services\{SettingService, DistributeService};
use Dcat\Admin\Widgets\Form;
/**
* 分销设置
*/
class Distribution extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
Setting::where('key', 'distribution')->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;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Admin\Forms;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class UserEditVip extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->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();
}
}

View File

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

View File

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

View File

@ -84,6 +84,7 @@ class AdminPermissionSeeder extends Seeder
'reset_account_password'=>['name' =>'修改安全密码'],
'edit_phone'=>['name' =>'修改手机号'],
'edit_bank'=>['name'=>'修改银行卡'],
'edit_vip'=>['name'=>'设置代理'],
],
],
'article_categories' =>[

View File

@ -17,6 +17,7 @@ class DatabaseSeeder extends Seeder
$this->call([
AdminSeeder::class,
AppSettingSeeder::class,
VipSeeder::class,
]);
if (! App::isProduction()) {

View File

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

View File

@ -8,6 +8,8 @@ return [
'fields' => [
'name' => '等级名称',
'growth_value' => '等级成长值',
'sort' => '排序',
'ratio' => '比例'
],
'options' => [
'deny' => '删除失败',