You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
<?php
|
|
/*
|
|
* @Descripttion:
|
|
* @version:
|
|
* @Author: GuaPi
|
|
* @Date: 2021-07-29 10:40:49
|
|
* @LastEditors: GuaPi
|
|
* @LastEditTime: 2021-08-09 17:46:33
|
|
*/
|
|
|
|
namespace App\Admin\Forms\User;
|
|
|
|
use App\Models\User;
|
|
use App\Models\UserWallet;
|
|
use App\Services\UserWalletService;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class AddPromotionUser extends Form
|
|
{
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
|
|
$acc_list = $input['PromoteAccount'];
|
|
$var=explode(",",$acc_list);
|
|
$aa = array_unique($var);
|
|
foreach($aa as $val){
|
|
DB::beginTransaction();
|
|
try {
|
|
|
|
$data['account_type'] = $input['account_type'];
|
|
if ($data['account_type'] == 1) {
|
|
$data['account'] = $input['account'];
|
|
$data['username'] = $input['account'];
|
|
$data['phone'] = $input['account'];
|
|
$data['phone_status'] = 1;
|
|
} else {
|
|
$data['account'] = $val;
|
|
$data['username'] = $val;
|
|
$data['email'] = $val;
|
|
$data['email_status'] = 1;
|
|
}
|
|
$data['reg_ip'] = request()->getClientIp();
|
|
$data['invite_code'] = User::gen_invite_code();
|
|
$data['password'] = (new User())->passwordHash($input['password']);
|
|
$loginCode = User::gen_login_code(6);
|
|
$data['login_code'] = $loginCode;
|
|
$data['last_login_time'] = Carbon::now()->toDateTimeString();
|
|
$data['last_login_ip'] = $data['reg_ip'];
|
|
|
|
$data['country_id'] = 1;
|
|
$data['country_code'] = 86;
|
|
$data['referrer'] = 0;
|
|
$data['user_auth_level'] = 2;
|
|
$data['pid'] = $input['pid'];
|
|
$data['deep'] = 1;
|
|
$data['whethertopromote'] = 1;
|
|
$data['is_system'] = 0;
|
|
$data['contract_deal'] = 1;
|
|
|
|
//创建用户
|
|
$user = User::query()->create($data);
|
|
// 创建用户钱包
|
|
$result3 = (new UserWalletService())->createWallet($user);
|
|
//给该用户充值
|
|
$result5 = UserWallet::query()->where('user_id',$user['user_id'])->where('coin_id',1)->update(['usable_balance'=>$input['InitializeUSDT']]);
|
|
|
|
DB::commit();
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
|
|
return $this->success('添加成功');
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
//$this->radio('account_type')->options([1 => '手机', 2 => '邮箱'])->default(1)->required();
|
|
$this->radio('account_type')->options([2 => '邮箱'])->default(2)->required();
|
|
$this->text('PromoteAccount')->required();
|
|
$this->text('password')->required();
|
|
$this->text('InitializeUSDT', '初始化USDT')->default(0);
|
|
$this->text('pid', '邀请人UID')->default(11);
|
|
$this->text('referrer', '代理商UID')->default(11)->help('为空时默认与上级ID相等');
|
|
//$this->text('password')->required();
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
|