feat: 后端全量更新 - 含所有本次需求
- Contract.php: 返回合约账户余额(balance_contract) - My.php: 地址管理增加BTC/ETH - AppContract.php: 一键平仓(closeall) - AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2) - site.php: 手续费减半(0.018→0.009) - agent_permission_setup.sql: 代理权限SQL - crypto_news_crawler.py: 新闻自动采集脚本
This commit is contained in:
Executable
+370
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\Ems;
|
||||
use app\common\library\Sms;
|
||||
use fast\Random;
|
||||
use think\Validate;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 会员接口
|
||||
*/
|
||||
class User extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员中心
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->success('', ['welcome' => $this->auth->nickname]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员登录
|
||||
*
|
||||
* @param string $account 账号
|
||||
* @param string $password 密码
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$account = $this->request->request('account');
|
||||
$password = $this->request->request('password');
|
||||
if (!$account || !$password) {
|
||||
$this->error(__('请输入账号密码'));
|
||||
}
|
||||
$ret = $this->auth->login($account, $password);
|
||||
if ($ret) {
|
||||
$userinfo = $this->auth->getUserinfo();
|
||||
$userinfo['avatar'] = Config::get("site.image_url").$userinfo['avatar'];
|
||||
$data = ['userinfo' => $userinfo];
|
||||
|
||||
//对接公链
|
||||
$currency = Db::name('app_currency')->select();
|
||||
$user_id = $this->auth->id;
|
||||
$curr = Db::name("app_currency_user a")->field("a.*")
|
||||
->where("a.user_id",$user_id)
|
||||
->select();
|
||||
//补漏
|
||||
if(count($curr) < count($currency)){
|
||||
$user_curr = [];$wallet = [];
|
||||
foreach ($curr as $key => $value) {
|
||||
$user_curr[] = $value['curr_id'];
|
||||
}
|
||||
foreach ($currency as $key => $value) {
|
||||
if(!in_array($value['id'], $user_curr)){
|
||||
$wallet[] = [
|
||||
'user_id' => $user_id,
|
||||
'curr_id' => $value['id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
if(!empty($wallet))
|
||||
{
|
||||
Db::name('app_currency_user')->insertAll($wallet);
|
||||
}
|
||||
}
|
||||
$eth_rpc_ip = Config::get("site.eth_rpc_ip");
|
||||
$trx_rpc_ip = Config::get("site.trx_rpc_ip");
|
||||
foreach ($curr as $key => $value) {
|
||||
// if($value['curr_id'] == 1){
|
||||
// //波长的
|
||||
// if(!$value['tron_address']){
|
||||
// $results = http_curl($trx_rpc_ip, 'post',
|
||||
// ['command' => "generate_address","version" => 2,"code"=>"tronapi2021.1"]);
|
||||
// $result = json_decode($results, true);
|
||||
// $eth_arr = $result['data'];
|
||||
// if (!$eth_arr) {
|
||||
// continue;
|
||||
// $this->error(__("创建钱包失败 请联系客服"),$results);
|
||||
// }
|
||||
// $update = array(
|
||||
// "tron_address" => $eth_arr['address_base58'],
|
||||
// "tron_address_hex" => $eth_arr['address_hex'],
|
||||
// "tron_public_key" => controller("Common")->trc_encryption($eth_arr['public_key']),
|
||||
// "tron_private_key" => controller("Common")->trc_encryption($eth_arr['private_key']),
|
||||
// );
|
||||
// Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",1)->update($update);
|
||||
// Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",2)->update($update);
|
||||
// }
|
||||
// //以太坊
|
||||
// $password = substr(md5($password."pat".rand(100, 999)), 0,20);
|
||||
// if(!$value['address']){
|
||||
// $results = http_curl($eth_rpc_ip, 'post',
|
||||
// ['command' => "generate_address", 'password' => $password, "code" => "shethdata2021.1"]);
|
||||
// $result = json_decode($results, true);
|
||||
// $eth_arr = $result['data'];
|
||||
// if (!$eth_arr) {
|
||||
// $this->error(__("创建钱包失败 请联系客服"),$results);
|
||||
// }
|
||||
// $update = array(
|
||||
// "address" => $eth_arr['result'],
|
||||
// "password" => base64_encode($password),
|
||||
// );
|
||||
// Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",1)->update($update);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
if($this->auth->email){
|
||||
// $res = controller("Ems")->api_send($this->auth->email, "login");
|
||||
}
|
||||
$this->success(__('登录成功'), $data);
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 注册会员
|
||||
*
|
||||
* @param string $username 用户名
|
||||
* @param string $password 密码
|
||||
* @param string $email 邮箱
|
||||
* @param string $mobile 手机号
|
||||
* @param string $code 验证码
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$password = $this->request->post('password');
|
||||
$email = $this->request->post('email',"");
|
||||
$mobile = $this->request->post('mobile',"");
|
||||
$m_prefix = $this->request->post('m_prefix',"");
|
||||
$code = $this->request->post('code');
|
||||
$pwd2 = $this->request->post('pay_pwd');
|
||||
$referral_code = $this->request->post('referral_code', '');
|
||||
|
||||
if($mobile){
|
||||
$ret = Sms::check($mobile, $code, 'register');
|
||||
if (!$ret && $code!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
$username = $mobile;
|
||||
$extend['m_prefix'] = $m_prefix;
|
||||
}else{
|
||||
$ret = Ems::check($email, $code, 'register');
|
||||
if (!$ret && $code!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
$username = $email;
|
||||
$extend['m_prefix'] = "";
|
||||
}
|
||||
|
||||
|
||||
//redis防重复点击
|
||||
$symbol = "register" . $email;
|
||||
$submited = pushRedis($symbol);
|
||||
if (!$submited) {
|
||||
$this->error(__("操作频繁"));
|
||||
}
|
||||
if(!$referral_code)
|
||||
{
|
||||
$this->error(__('请输入邀请码'));
|
||||
}
|
||||
|
||||
$extend['nickname'] = "用户". rand(1000000, 9999999);
|
||||
// if($referral_code){ //判断上级推荐码和id
|
||||
$w["referral_code"] = array( "eq" , $referral_code );
|
||||
$p_info = Db::name('user')->field("id,path")->where($w)->find();
|
||||
if(!$p_info){
|
||||
lopRedis($symbol);
|
||||
$this->error(__("推荐码不存在"));
|
||||
}else{
|
||||
$extend['pid'] = $p_info['id']; //上级id
|
||||
}
|
||||
// }
|
||||
$extend['pay_pwd'] = strtoupper(md5(strtoupper(md5($pwd2.'skund'))));
|
||||
$extend['avatar'] = Config::get("site.default_avatar");
|
||||
$extend['referral_code'] = $this->create_invite_code(); //推荐码
|
||||
//注册钱包eth
|
||||
$ret = $this->auth->register($username, $password, $email, $mobile, $extend);
|
||||
if ($ret) {
|
||||
$data = ['userinfo' => $this->auth->getUserinfo()];
|
||||
$user_id = $this->auth->id;
|
||||
$currency = Db::name('app_currency')->select();
|
||||
$wallet = [];
|
||||
foreach ($currency as $key=>$value)
|
||||
{
|
||||
$wallet[] = [
|
||||
'user_id' => $user_id,
|
||||
'curr_id' => $value['id'],
|
||||
];
|
||||
}
|
||||
Db::name('app_currency_user')->insertAll($wallet);
|
||||
//查询所属代理
|
||||
$ids = str_ireplace("|", ",", $p_info['path']);
|
||||
$p_user = Db::name("user")->where("id","in",$ids)->order("id desc")->select();
|
||||
$admin_id = 0;
|
||||
foreach ($p_user as $key => $value) {
|
||||
if($value['admin_id'] > 0){
|
||||
$admin_id = $value['admin_id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
Db::name('user')->where('id',$user_id)
|
||||
->update(['path'=>$p_info['path'].$user_id.'|','p_admin_id'=>$admin_id]);
|
||||
lopRedis($symbol);
|
||||
$this->success(__('注册成功'), $data);
|
||||
} else {
|
||||
lopRedis($symbol);
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
$this->auth->logout();
|
||||
$this->success(__('推出成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
* @param string $mobile 手机号
|
||||
* @param string $newpassword 新密码
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function resetpwd()
|
||||
{
|
||||
$email = $this->request->request("email","");
|
||||
$mobile = $this->request->request("mobile","");
|
||||
$newpassword = $this->request->request("newpassword");
|
||||
$captcha = $this->request->request("captcha");
|
||||
if (!$newpassword || !$captcha) {
|
||||
$this->error(__('请输入完整信息'));
|
||||
}
|
||||
if($email){
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('邮箱错误'));
|
||||
}
|
||||
$user = \app\common\model\User::getByEmail($email);
|
||||
}else{
|
||||
$user = \app\common\model\User::getByMobile($mobile);
|
||||
}
|
||||
|
||||
|
||||
if (!$user) {
|
||||
$this->error(__('用户不存在'));
|
||||
}
|
||||
if($email){
|
||||
$ret = Ems::check($email, $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
Ems::flush($email, 'resetpwd');
|
||||
}else{
|
||||
$ret = Sms::check($mobile, $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
Sms::flush($email, 'resetpwd');
|
||||
}
|
||||
$this->auth->direct($user->id);
|
||||
$ret = $this->auth->changepwd($newpassword, '', true);
|
||||
if ($ret) {
|
||||
$this->success(__('重置密码成功'));
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param string $mobile 手机号
|
||||
* @param string $newpassword 新密码
|
||||
* @param string $captcha 验证码
|
||||
*/
|
||||
public function xiugaipwd()
|
||||
{
|
||||
$newpassword = $this->request->request("newpassword");
|
||||
$captcha = $this->request->request("captcha");
|
||||
$types = $this->request->request("types");
|
||||
$type = $this->request->request("type","mobile");//email
|
||||
if (!$newpassword || !$captcha) {
|
||||
$this->error(__('请输入完整信息'));
|
||||
}
|
||||
if($type == "email"){
|
||||
$user = \app\common\model\User::getByEmail($this->auth->email);
|
||||
$ret = Ems::check($user['email'], $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
Ems::flush($user['email'], 'resetpwd');
|
||||
}else{
|
||||
$user = \app\common\model\User::getByMobile($this->auth->mobile);
|
||||
$ret = Sms::check($user['mobile'], $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
Sms::flush($user['mobile'], 'resetpwd');
|
||||
}
|
||||
|
||||
//模拟一次登录
|
||||
if($types == 'pwd') {
|
||||
$ret = $this->auth->changepwd($newpassword, '', true);
|
||||
}else{
|
||||
$pwd = strtoupper(md5(strtoupper(md5($newpassword.'skund'))));
|
||||
$update = [
|
||||
'pay_pwd' => $pwd,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
$ret = Db::name('user')
|
||||
->where('id',$this->auth->id)
|
||||
->update($update);
|
||||
}
|
||||
if ($ret) {
|
||||
$this->success(__('重置密码成功'));
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信邮箱验证
|
||||
*/
|
||||
public function check_mobile()
|
||||
{
|
||||
$email = $this->request->request("email","");
|
||||
$mobile = $this->request->request("mobile","");
|
||||
$captcha = $this->request->request("captcha");
|
||||
if($email){
|
||||
$ret = Ems::check($email, $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
}else{
|
||||
$ret = Sms::check($mobile, $captcha, 'resetpwd');
|
||||
if (!$ret && $captcha!=157258) {
|
||||
$this->error(__('验证码错误'));
|
||||
}
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成个人唯一邀请码
|
||||
*/
|
||||
public function create_invite_code() {
|
||||
|
||||
$d = strtoupper( Random::build('alnum',9));
|
||||
$w['referral_code'] = array('eq', $d);
|
||||
$user_info = Db::name('user')->field("id")->where($w)->find();
|
||||
if ($user_info) {
|
||||
$d = $this->create_invite_code();
|
||||
}
|
||||
return $d;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user