<?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 app\api\logic\UserCollect as LogicUserCollect;
|
use app\api\logic\Homemenu as LogicHomemenu;
|
use app\common\model\user\Third as ModelThird;
|
use app\api\logic\UserBrowse as LogicUserBrowse;
|
use app\admin\model\Feedback as ModelFeedback;
|
use app\common\model\User as ModelUser;
|
use app\api\logic\User as LogicUser;
|
use app\common\model\UserLevel as ModelUserLevel;
|
use app\api\logic\UserWithdrawal as LogicUserWithdrawal;
|
use app\api\logic\SettlementRecord as LogicSettlementRecord;
|
use app\api\logic\UserMoneyLog as LogicUserMoneyLog;
|
use think\log;
|
use app\api\logic\ActivityInfo as InfoActivityInfo;
|
use app\common\model\UserExtend as ModelUserExtend;
|
use think\Db;
|
use EasyWeChat\Kernel\Support\AES;
|
/**
|
* 会员接口
|
*/
|
class User extends Api
|
{
|
protected $noNeedLogin = ['GetDfgToken','GetRecomInviter','login', 'mobilelogin', 'resetpwd', 'changemobile', 'wxapplogin','bind_mobile_login','register'];
|
protected $noNeedRight = '*';
|
|
public function _initialize()
|
{
|
parent::_initialize();
|
|
}
|
|
/**
|
* 获取用户信息
|
*
|
* @return void
|
*/
|
public function info(){
|
$ModelUser = new ModelUser();
|
$LogicUser = new LogicUser();
|
$userInfo = $ModelUser->with('user_level')->field('id,username,money,password,mobile,nickname,avatar,level,invitation_code,pdd_authority_ios,pdd_authority_android,t_relation_id,tb_account,true_name,zfb_account,createtime')->where(['id'=>USERID])->find();
|
if(empty($userInfo)) $this->error('用户不存在');
|
$userInfo->hidden(['password']);
|
$userInfo['bindingWechat'] = $LogicUser->getWxBind(USERID,'wechat');
|
$userInfo['token'] = $this->auth->getToken();
|
$data = ['userinfo' => $userInfo];
|
$this->success('获取成功', $data);
|
}
|
|
|
public function GetDfgToken()
|
{
|
$userId=$this->request->post('userid');
|
if (!$userId) {
|
$this->error(__('Invalid parameters'));
|
}
|
//aes加密
|
$enKey="wp4hs3bvu7wq2mud";
|
$iv = 'fedcba9876543210';
|
$decrypted = base64_encode(AES::encrypt($userId,$enKey, $iv));
|
$this->success($decrypted);
|
}
|
|
|
|
/**
|
* 更新appclientid
|
*/
|
public function UpdateClientId()
|
{
|
$pushCid=$this->request->post('pushcid');
|
$ModelUser = new ModelUser();
|
$userInfo = $ModelUser->where(['id'=>USERID]);
|
if(empty($userInfo)) $this->success('成功',true);
|
$userInfo->update(['push_cid'=>$pushCid]);
|
$this->success('成功', true);
|
}
|
|
/**
|
* 会员登录
|
*
|
* @ApiMethod (POST)
|
* @param string $account 账号
|
* @param string $password 密码
|
*/
|
public function login()
|
{
|
$account = $this->request->post('account');
|
$password = $this->request->post('password');
|
if (!$account || !$password) {
|
$this->error(__('Invalid parameters'));
|
}
|
$ret = $this->auth->login($account, $password);
|
if ($ret) {
|
$data = ['userinfo' => $this->auth->getUserinfo()];
|
$this->success(__('Logged in successful'), $data);
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
/**
|
* 手机验证码登录
|
*
|
* @ApiMethod (POST)
|
* @param string $mobile 手机号
|
* @param string $captcha 验证码
|
*/
|
public function mobilelogin()
|
{
|
$mobile = $this->request->post('mobile');
|
$captcha = $this->request->post('captcha');
|
$ismobouth=$this->request->post('ismobouth',false);
|
$pushCid=$this->request->post('pushCid',false);
|
if (!$mobile || !$captcha) {
|
$this->error(__('Invalid parameters'));
|
}
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
$this->error(__('Mobile is incorrect'));
|
}
|
if (!$ismobouth&&!Sms::check($mobile, $captcha, 'login')) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
$user = \app\common\model\User::getByMobile($mobile);
|
if ($user) {
|
if ($user->status != 'normal') {
|
$this->error(__('Account is locked'));
|
}
|
//如果已经有账号则直接登录
|
$ret = $this->auth->direct($user->id);
|
} else {
|
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, [],'',[],$pushCid);
|
}
|
if ($ret) {
|
Sms::flush($mobile, 'login');
|
$data = ['userinfo' => $this->auth->getUserinfo()];
|
$this->success(__('Logged in successful'), $data);
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
/**
|
* 用户注册
|
*
|
* @return void
|
*/
|
public function register()
|
{
|
$mobile = $this->request->post('mobile');
|
$captcha = $this->request->post('captcha');
|
$invitation_code = $this->request->post('invitation_code');
|
if (!$mobile || !$captcha || !$invitation_code) {
|
$this->error(__('Invalid parameters'));
|
}
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
$this->error(__('Mobile is incorrect'));
|
}
|
if (!Sms::check($mobile, $captcha, 'register')) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
$user = \app\common\model\User::getByMobile($mobile);
|
if ($user) {
|
if ($user->status != 'normal') {
|
$this->error(__('Account is locked'));
|
}
|
//如果已经有账号则直接登录
|
$this->error(__('该手机号已注册,请直接登录'));
|
} else {
|
$f_user = \app\common\model\User::where(['invitation_code'=>$invitation_code])->find();
|
if(empty($f_user))$this->error('上级用户信息不存在');
|
$extend = [
|
'invitation_id' => $f_user['id'],
|
'invite_bind_time' => time(),
|
'invitation_code' => createInviteCode()
|
];
|
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
|
}
|
if ($ret) {
|
Sms::flush($mobile, 'register');
|
$this->success(__('注册成功'), []);
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
/**
|
* 退出登录
|
* @ApiMethod (POST)
|
*/
|
public function logout()
|
{
|
if (!$this->request->isPost()) {
|
$this->error(__('Invalid parameters'));
|
}
|
$this->auth->logout();
|
$this->success(__('Logout successful'));
|
}
|
|
/**
|
* 修改会员个人信息
|
*
|
* @ApiMethod (POST)
|
* @param string $avatar 头像地址
|
* @param string $username 用户名
|
* @param string $nickname 昵称
|
* @param string $bio 个人简介
|
*/
|
public function profile()
|
{
|
$user = $this->auth->getUser();
|
$nickname = $this->request->post('nickname');
|
$avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
|
if ($nickname) {
|
$exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
|
if ($exists) {
|
$this->error(__('Nickname already exists'));
|
}
|
$user->nickname = $nickname;
|
}
|
if ($avatar) {
|
$user->avatar = $avatar;
|
}
|
$user->save();
|
$this->success();
|
}
|
|
|
|
/**
|
* 修改手机号
|
*
|
* @ApiMethod (POST)
|
* @param string $mobile 手机号
|
* @param string $captcha 验证码
|
*/
|
public function changemobile()
|
{
|
$user = $this->auth->getUser();
|
$mobile = $this->request->post('mobile');
|
$captcha = $this->request->post('captcha');
|
$isyj=$this->request->post('isyj',false);
|
if (!$mobile || (!$isyj&&!$captcha)) {
|
$this->error(__('Invalid parameters'));
|
}
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
$this->error('请输入正确手机号');
|
}
|
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
|
$this->error('手机号码已存在');
|
}
|
$result = Sms::check($mobile, $captcha, 'changemobile');
|
if (!$result) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
$verification = $user->verification;
|
$verification->mobile = 1;
|
$user->verification = $verification;
|
$user->mobile = $mobile;
|
$user->username = $mobile;
|
$user->save();
|
|
Sms::flush($mobile, 'changemobile');
|
$this->success();
|
}
|
|
/**
|
* 微信app登录
|
*
|
* @ApiMethod (POST)
|
* @param string $code Code码
|
*/
|
public function wxapplogin()
|
{
|
$openid = request()->param('openid');
|
$access_token = request()->param('access_token');
|
$LogicUser = new LogicUser();
|
$userId = $LogicUser->getUserByOpenId($openid);
|
if ($userId) {
|
$user = $LogicUser->getUser($userId);
|
if(empty($user)) $this->error("用户信息获取失败");
|
if ($user['status'] != 'normal') {
|
$this->error(__('Account is locked'));
|
}
|
//如果已经有账号则直接登录
|
$ret = $this->auth->direct($user['id']);
|
} else {
|
$wxUser = $LogicUser->getWxUserByOpenId($openid,$access_token);
|
if(!$wxUser || empty($wxUser)) $this->error('微信授权失败,请重试');
|
$this->success(__('授权成功'), ['type'=>'bindMobile','info'=>$wxUser]);
|
// $ret = $this->auth->register('', Random::alnum(), '', '', [],'wechat',$wxUser);
|
}
|
if ($ret) {
|
$data = ['type'=>'goUser','userinfo' => $this->auth->getUserinfo()];
|
$this->success(__('Logged in successful'), $data);
|
} else {
|
$this->error($this->auth->getError());
|
}
|
|
}
|
|
/**
|
* 微信授权绑定手机号登录
|
*
|
* @return void
|
*/
|
public function bind_mobile_login()
|
{
|
$wxUser = request()->param('wxUser','','urldecode');
|
$pushCid= request()->param('pushCid','');
|
$wxUser = json_decode($wxUser,true);
|
if(empty($wxUser)) $this->error('微信授权信息获取失败');
|
$mobile = $this->request->post('mobile');
|
$captcha = $this->request->post('captcha');
|
$isyj=$this->request->post('isyj',false);
|
if (!$mobile || (!$isyj&&!$captcha)) {
|
$this->error(__('Invalid parameters'));
|
}
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
$this->error('请输入正确手机号');
|
}
|
if(!$isyj)
|
{
|
$result = Sms::check($mobile, $captcha, 'changemobile');
|
if (!$result) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
}
|
|
$ModelThird = new ModelThird();
|
$LogicUser = new LogicUser();
|
//判断当前手机号是否已经绑定微信
|
$ModelUser = new ModelUser();
|
$is_phone_bind = $ModelUser->where(['mobile'=> $mobile])->find();
|
if(!empty($is_phone_bind)){
|
$LogicUser->bindWechat($is_phone_bind['id'],$wxUser['headimgurl'],$wxUser['sex'],$wxUser['nickname'],$wxUser['openid']);
|
$ret = $this->auth->direct($is_phone_bind['id'],$pushCid);
|
}else{ //判断微信是否已经绑定
|
$find_third = $ModelThird->where(['openid'=>$wxUser['openid']])->find();
|
if(!empty($find_third)) $this->error('当前微信号已绑定其他账号');
|
$ret = $this->auth->register('', Random::alnum(), '', $mobile, [],'wechat',$wxUser,$pushCid);
|
}
|
Sms::flush($mobile, 'changemobile');
|
if ($ret) {
|
$data = ['userinfo' => $this->auth->getUserinfo()];
|
$this->success(__('Logged in successful'), $data);
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
/**
|
* 重置密码
|
*
|
* @ApiMethod (POST)
|
* @param string $mobile 手机号
|
* @param string $newpassword 新密码
|
* @param string $captcha 验证码
|
*/
|
public function resetpwd()
|
{
|
$type = $this->request->post("type");
|
$mobile = $this->request->post("mobile");
|
$email = $this->request->post("email");
|
$newpassword = $this->request->post("newpassword");
|
$captcha = $this->request->post("captcha");
|
if (!$newpassword || !$captcha) {
|
$this->error(__('Invalid parameters'));
|
}
|
//验证Token
|
if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
$this->error(__('Password must be 6 to 30 characters'));
|
}
|
if ($type == 'mobile') {
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
$this->error(__('Mobile is incorrect'));
|
}
|
$user = \app\common\model\User::getByMobile($mobile);
|
if (!$user) {
|
$this->error(__('User not found'));
|
}
|
$ret = Sms::check($mobile, $captcha, 'resetpwd');
|
if (!$ret) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
Sms::flush($mobile, 'resetpwd');
|
} else {
|
if (!Validate::is($email, "email")) {
|
$this->error(__('Email is incorrect'));
|
}
|
$user = \app\common\model\User::getByEmail($email);
|
if (!$user) {
|
$this->error(__('User not found'));
|
}
|
$ret = Ems::check($email, $captcha, 'resetpwd');
|
if (!$ret) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
Ems::flush($email, 'resetpwd');
|
}
|
//模拟一次登录
|
$this->auth->direct($user->id);
|
$ret = $this->auth->changepwd($newpassword, '', true);
|
if ($ret) {
|
$this->success(__('Reset password successful'));
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
/**
|
* 第一次设置密码
|
*
|
* @return void
|
*/
|
public function setpwd(){
|
$new_pwd = request()->param('pwd');
|
if(empty($new_pwd)) $this->error('参数错误');
|
$ret = $this->auth->setpwd($new_pwd);
|
if ($ret) {
|
$this->success(__('密码设置成功'));
|
} else {
|
$this->error($this->auth->getError());
|
}
|
}
|
|
|
|
/**
|
* 用户浏览记录
|
*
|
* @return void
|
*/
|
public function browse_log()
|
{
|
$page = request()->param('page',1);
|
|
$page_size = request()->param('pageSize',10);
|
|
$LogicUserBrowse = new LogicUserBrowse();
|
|
$list = $LogicUserBrowse->getList($page,$page_size);
|
|
if($list === false) $this->error($LogicUserBrowse->getError());
|
|
$this->success('获取成功',['list'=>$list]);
|
}
|
|
|
/**
|
* 删除浏览记录
|
*
|
* @return void
|
*/
|
public function delete_browse()
|
{
|
$ids = request()->param('ids','');
|
|
$LogicUserBrowse = new LogicUserBrowse();
|
|
$res = $LogicUserBrowse->deleteLog(USERID,$ids);
|
|
if($res === false) $this->error($LogicUserBrowse->getError());
|
|
$this->success([],'删除成功');
|
}
|
|
|
/**
|
* 标记浏览0元购商品记录
|
*
|
* @return void
|
*/
|
public function update_first_free_browse()
|
{
|
$ids = request()->param('goodsid','');
|
|
$new_goodsId = request()->param('new_goodsId','');
|
|
$plateform= request()->param('plateform','');
|
|
$LogicUserBrowse = new LogicUserBrowse();
|
|
$res = $LogicUserBrowse->updatefirstfreelog(USERID,$ids,$new_goodsId,$plateform);
|
|
if($res === false) $this->error($LogicUserBrowse->getError());
|
|
$this->success([],'添加成功');
|
}
|
|
/**
|
* 检测是否首单
|
*
|
* @return void
|
*/
|
|
public function check_isfirst_free()
|
{
|
|
$LogicUserBrowse = new LogicUserBrowse();
|
|
$res = $LogicUserBrowse->checkIsFirstFree(USERID);
|
|
if($res === false) $this->error($LogicUserBrowse->getError());
|
Log::write('检测是否首单:'.json_encode($res));
|
if(empty($res)) $this->success(['info'=>1],'首单客户');
|
$this->success(['info'=>0],'非首单客户');
|
}
|
|
|
/**
|
* 用户收藏记录
|
*
|
* @return void
|
*/
|
public function user_collect()
|
{
|
$page = request()->param('page',1);
|
|
$LogicUserCollect = new LogicUserCollect();
|
|
$list = $LogicUserCollect->getList($page,10);
|
|
if($list === false) $this->error($LogicUserCollect->getError());
|
|
$this->success('获取成功',['list'=>$list]);
|
}
|
|
|
|
/**
|
* 添加商品收藏
|
*
|
* @return void
|
*/
|
public function add_collect()
|
{
|
$goods = request()->param('goods','','urldecode');
|
|
$goods = json_decode($goods,true);
|
|
if(empty($goods) || $goods['goodsId'] == "") $this->error('商品信息错误');
|
|
$LogicUserCollect = new LogicUserCollect();
|
|
$res = $LogicUserCollect->addCollect(USERID,$goods);
|
|
if($res === false) $this->error($LogicUserCollect->getError());
|
|
$this->success('收藏成功',['info' => $res ? 1 : 0]);
|
}
|
|
|
|
/**
|
* 删除收藏记录
|
*
|
* @return void
|
*/
|
public function del_Collect()
|
{
|
$goodsId = request()->param('goodsId','');
|
|
if(empty($goodsId)) $this->error('参数错误');
|
|
$LogicUserCollect = new LogicUserCollect();
|
|
$res = $LogicUserCollect->delCollect(USERID,$goodsId);
|
|
if($res === false) $this->error($LogicUserCollect->getError());
|
|
$this->success('操作成功',['info' => 0]);
|
}
|
|
|
/**
|
* 获取个人中心金刚区
|
*
|
* @return void
|
*/
|
public function user_homemenu()
|
{
|
$LogicHomemenu = new LogicHomemenu();
|
$list = $LogicHomemenu->getList('2','');
|
$return_data = [
|
'cygnList' => [],
|
'gongJuList' => [],
|
'xstgList' => [],
|
'dingdanList' => [],
|
'wuLiaoList' => []
|
];
|
if(!empty($list)){
|
foreach($list as $key => $value){
|
if($value['group'] == 2)$return_data['cygnList'][] = $value;
|
if($value['group'] == 3)$return_data['gongJuList'][] = $value;
|
if($value['group'] == 4)$return_data['xstgList'][] = $value;
|
if($value['group'] == 5)$return_data['dingdanList'][] = $value;
|
if($value['group'] == 6)$return_data['wuLiaoList'][] = $value;
|
}
|
}
|
$this->success('操作成功',['list' => $return_data]);
|
}
|
|
|
/**
|
* 意见反馈
|
*
|
* @return void
|
*/
|
public function feedback()
|
{
|
$content = request()->param('content','','trim');
|
|
if(empty($content)) $this->error('请输入反馈内容');
|
|
$data = [
|
'user_id' => USERID,
|
'content' => $content,
|
'create_time' => time()
|
];
|
|
$ModelFeedback = new ModelFeedback();
|
|
$res = $ModelFeedback->save($data);
|
|
if(!$res) $this->error('提交失败');
|
|
$this->success('提交成功,感谢您的反馈',[]);
|
|
}
|
|
|
/**
|
* 用户注销
|
*
|
* @return void
|
*/
|
public function cancel()
|
{
|
$code = request()->param('validateCode');
|
|
$userInfo = $this->auth->getUserinfo();
|
|
if (!Sms::check($userInfo['mobile'], $code, 'cancel')) {
|
$this->error(__('Captcha is incorrect'));
|
}
|
|
$ModelUser = new ModelUser();
|
|
$res = $ModelUser->where(['id'=>$userInfo['id']])->update(['status'=>'cancel','updatetime'=>time(),'cancel_time'=>time(),'common_relation_id'=>$userInfo['common_relation_id']."-cancel"]);
|
if(!$res) $this->error('注销失败');
|
ModelThird::where(['user_id'=>$userInfo['id']])->delete(); //删除关联三方信息
|
$this->success('注销成功',[]);
|
}
|
|
|
/**
|
* 邀请码获取对应信息
|
*/
|
public function invitation_info()
|
{
|
$invite_code = request()->param('invite_code','');
|
if(empty($invite_code)) $this->error('邀请码不能为空');
|
$is_official = false;
|
$isOpenOfficialCode = config('site.isOpenOfficialCode');
|
if($isOpenOfficialCode == 1 && $invite_code == config('site.invite_code'))$is_official = true;
|
$inviterInfo = [];
|
if($is_official){
|
$inviterInfo = [
|
'avatar' => cdnurl(config('site.logo')),
|
'nickname' => '官方平台',
|
'account' => '官方账号',
|
'inviteCode' => config('site.invite_code')
|
];
|
}else{
|
$ModelUser = new ModelUser();
|
$f_user = $ModelUser->where(['invitation_code'=>$invite_code])->find();
|
if(empty($f_user))$this->error('邀请人不存在');
|
if($f_user['status'] != 'normal')$this->error('邀请人帐号已被锁定,暂时无法邀请');
|
$account = $f_user['username'];
|
$search = '/^0?1[3|4|5|6|7|8][0-9]\d{8}$/';
|
if (preg_match( $search, $account ) ) {
|
$account = substr_replace($account,'****',3,4);
|
}
|
$inviterInfo = [
|
'avatar' => cdnurl($f_user['avatar']),
|
'nickname' => $f_user['nickname'],
|
'account' => $account,
|
'inviteCode' => $f_user['invitation_code']
|
];
|
}
|
$this->success('获取成功',$inviterInfo);
|
}
|
|
|
|
/**
|
* 绑定用户关系
|
*
|
* @return void
|
*/
|
public function bind_invitation()
|
{
|
$invite_code = request()->param('invite_code','');
|
$deviceid=request()->param('deviceid','');
|
if(empty($invite_code)) $this->error('邀请码不能为空');
|
$is_official = false;
|
$isOpenOfficialCode = config('site.isOpenOfficialCode');
|
if($isOpenOfficialCode == 1 && $invite_code == config('site.invite_code'))$is_official = true;
|
$save_data = [
|
'updatetime' => time(),
|
'invitation_code' => createInviteCode(),
|
'invite_bind_time' => time()
|
];
|
$user = $this->auth->getUser();
|
if(!empty($user['invitation_code'])) $this->error('请勿重复绑定');
|
if(config('site.agent_mode') == 2 && $user['level'] == 0) $save_data['level'] = 1;
|
$ModelUser = new ModelUser();
|
$ModelUser->startTrans();
|
if(!$is_official){ //不是官方邀请
|
$f_user = $ModelUser->where(['invitation_code'=>$invite_code])->find();
|
if(empty($f_user))$this->error('邀请人不存在');
|
if($f_user['status'] != 'normal')$this->error('邀请人帐号已被锁定,暂时无法邀请');
|
if($user['invitation_id'] != 0)$this->error('当前已绑定上级用户');
|
$save_data['invitation_id'] = $f_user['id'];
|
if(!empty($deviceid))
|
{//设备id
|
$save_data['login_deviceid'] = $deviceid;
|
}
|
else{
|
$save_data['login_deviceid'] = 'cus'.self::guid();
|
}
|
if($f_user['invitation_id'] != 0)$save_data['f_invitation_id'] = $f_user['invitation_id'];
|
$res2 = $ModelUser->where(['id'=>$f_user['id']])->setInc('fans',1);
|
if(!$res2){
|
$ModelUser->rollback();
|
$this->error('绑定失败');
|
}
|
}
|
$res = $ModelUser->where(['id'=>$user['id']])->update($save_data);
|
if(!$res){
|
$ModelUser->rollback();
|
$this->error('绑定失败');
|
}
|
$ModelUser->commit();
|
//更新招募活动信息
|
$activityInfo=new InfoActivityInfo();
|
$activityInfo->updateRecruitCount($save_data['invitation_id'] );
|
$this->success('绑定成功',[]);
|
}
|
|
public function guid()
|
{
|
|
if (function_exists('com_create_guid')) {
|
|
return com_create_guid();
|
|
} else {
|
|
mt_srand((double)microtime() * 10000);
|
$charid = strtoupper(md5(uniqid(rand(), true)));
|
$uuid = substr($charid, 0, 8)
|
. substr($charid, 8, 4)
|
. substr($charid, 12, 4)
|
. substr($charid, 16, 4)
|
. substr($charid, 20, 12);
|
return $uuid;
|
|
}
|
}
|
|
/**
|
* 获取用户预估金额
|
*
|
* @return void
|
*/
|
public function get_estimate_amount()
|
{
|
$LogicUser = new LogicUser();
|
$toDayMoney = $LogicUser->getProfit(USERID,'0',true);
|
$yesterDayMoney = $LogicUser->getProfit(USERID,'1',true);
|
$monthMoney = $LogicUser->getProfit(USERID,'2',true);
|
$lastMonth = $LogicUser->getProfit(USERID,'3',true);
|
$teamToDayMoney = $LogicUser->getProfit(USERID,'0',false);
|
$teamYesterDayMoney = $LogicUser->getProfit(USERID,'1',false);
|
$teamMonthMoney = $LogicUser->getProfit(USERID,'2',false);
|
$teamLastMonth = $LogicUser->getProfit(USERID,'3',false);
|
$data = [
|
'lastMonth' => bcadd($lastMonth['my']['money'],$teamLastMonth['team']['money'],2),
|
'monthMoney' => bcadd($monthMoney['my']['money'],$teamMonthMoney['team']['money'],2),
|
'toDayMoney' => bcadd($toDayMoney['my']['money'],$teamToDayMoney['team']['money'],2),
|
'yesterDayMoney' => bcadd($yesterDayMoney['my']['money'],$teamYesterDayMoney['team']['money'],2),
|
];
|
$this->success('获取成功',$data);
|
}
|
|
/**
|
* 获取粉丝列表
|
*
|
* @return void
|
*/
|
public function fans_list()
|
{
|
$type = request()->param('type',1);
|
$page = request()->param('page',1);
|
$pageSize = request()->param('pageSize',10);
|
$memberId = request()->param('memberId','');
|
$ModelUser = new ModelUser();
|
$user_id = empty($memberId) ? USERID : $memberId;
|
if($type == 0){
|
$where = ['invitation_id|f_invitation_id'=>$user_id];
|
}else if($type == 1){
|
$where = ['invitation_id'=>$user_id];
|
}else if($type == 2){
|
$where = ['f_invitation_id'=>$user_id];
|
}else{
|
$this->error('获取类型错误');
|
}
|
$list = $ModelUser->with('user_level')->field('id,avatar,level,nickname,username,invite_bind_time,fans')->where($where)->page($page,$pageSize)->select();
|
$this->success('获取成功',['list'=>$list]);
|
}
|
|
/**
|
* 获取粉丝统计
|
*/
|
public function get_fans_count()
|
{
|
$user = $this->auth->getUser();
|
$ModelUser = new ModelUser();
|
$return_data = [
|
'allCount' => $user['fans'],
|
'toDayMember' => $ModelUser->whereTime('invite_bind_time','today')->where(['invitation_id'=>$user['id']])->count(),
|
'yesterdayMember' => $ModelUser->whereTime('invite_bind_time','yesterday')->where(['invitation_id'=>$user['id']])->count()
|
];
|
$this->success('获取成功',['info'=>$return_data]);
|
}
|
|
/**
|
* 获取升级规则
|
*
|
* @return void
|
*/
|
public function get_upgrade_info()
|
{
|
$user = $this->auth->getUser();
|
$ModelUserLevel = new ModelUserLevel();
|
$list = $ModelUserLevel->field('level_name,direct_primary_count,indirect_primary_count,own_monthly_commission,direct_intermediate_count,indirect_intermediate_count')->where(['status'=>1,'level'=>['>',0]])->select();
|
//查询当前用户对应粉丝人数
|
$ModelUser = new ModelUser();
|
$user_zscj_num = $ModelUser->where(['invitation_id'=>USERID,'level'=>1])->count(); //直属初级人数
|
$user_jjcj_num = $ModelUser->where(['f_invitation_id'=>USERID,'level'=>1])->count(); //间接初级人数
|
$user_zszj_num = $ModelUser->where(['invitation_id'=>USERID,'level'=>2])->count(); //直属中级人数
|
$user_jjzj_num = $ModelUser->where(['f_invitation_id'=>USERID,'level'=>2])->count(); //间接中级人数
|
$user_zong_num = $ModelUser->where(['invitation_id'=>USERID])->count(); //总邀请人数
|
$user_monthly_commission = LogicUser::getUserCommission($user['id'],'month'); //获取近30佣金
|
$user_total_commission = LogicUser::getUserCommission($user['id'],'total'); //获取累计佣金
|
$data = [
|
'info' => [
|
'user_zscj_num' => $user_zscj_num,
|
'user_jjcj_num' => $user_jjcj_num,
|
'user_zszj_num' => $user_zszj_num,
|
'user_jjzj_num' => $user_jjzj_num,
|
'user_zong_num'=>$user_zong_num,
|
'user_monthly_commission' => $user_monthly_commission,
|
'total_commission' => $user_total_commission
|
],
|
'list' => $list
|
];
|
$this->success('获取成功',$data);
|
}
|
|
|
/**
|
* 权益对比
|
*/
|
public function get_equity_card()
|
{
|
$ModelUserLevel = new ModelUserLevel();
|
$list = $ModelUserLevel->where(['status'=>1])->select();
|
$user_level = array_column($list,NULL,'level');
|
$data = [
|
'zeroName' => $user_level[0]['level_name'],
|
'zeroRate' => floor((($user_level[0]['own_commission_rate']/$user_level[1]['own_commission_rate']))*100)."%",
|
'zeroShouYi' => $user_level[0]['own_commission_rate'],
|
'oneName' => $user_level[1]['level_name'],
|
'oneRate' => floor((($user_level[1]['own_commission_rate']/$user_level[1]['own_commission_rate']))*100)."%",
|
'oneShouYi' => $user_level[1]['own_commission_rate'],
|
'twoName' => $user_level[2]['level_name'],
|
'twoRate' => floor((($user_level[2]['own_commission_rate']/$user_level[1]['own_commission_rate']))*100)."%",
|
'twoShouYi' => $user_level[2]['own_commission_rate'],
|
'twoZS' => floor(($user_level[2]['direct_commission_rate'] - $user_level[1]['direct_commission_rate'])/$user_level[1]['direct_commission_rate']).'%',
|
'twoJJ' => floor(($user_level[2]['indirect_commission_rate'] - $user_level[1]['indirect_commission_rate'])/$user_level[1]['indirect_commission_rate']).'%',
|
'twoZJ' => floor(($user_level[2]['direct_intermediate_rate'] - $user_level[1]['direct_intermediate_rate'])/$user_level[1]['direct_intermediate_rate']).'%',
|
'threeName' => $user_level[3]['level_name'],
|
'threeRate' => floor((($user_level[3]['own_commission_rate']/$user_level[1]['own_commission_rate']))*100)."%",
|
'threeShouYi' => $user_level[3]['own_commission_rate'],
|
'threeZS' => floor(($user_level[3]['direct_commission_rate'] - $user_level[1]['direct_commission_rate'])/$user_level[1]['direct_commission_rate']).'%',
|
'threeJJ' => floor(($user_level[3]['indirect_commission_rate'] - $user_level[1]['indirect_commission_rate'])/$user_level[1]['indirect_commission_rate']).'%',
|
'threeZJ' => floor(($user_level[3]['direct_intermediate_rate'] - $user_level[1]['direct_intermediate_rate'])/$user_level[1]['direct_intermediate_rate']).'%',
|
];
|
$this->success('获取成功',['info'=>$data]);
|
}
|
|
|
/**
|
* 用户升级申请
|
*
|
* @return void
|
*/
|
public function level_apply()
|
{
|
$LogicUser = new LogicUser();
|
$res = $LogicUser->levelApply(USERID);
|
if(!$res) $this->error('申请失败');
|
$this->success('升级成功',[]);
|
}
|
|
|
|
/**
|
* 用户收益
|
*
|
* @return void
|
*/
|
public function user_profit()
|
{
|
$type = request()->param('type',0);
|
|
$LogicUser = new LogicUser();
|
|
$info = $LogicUser->getProfit(USERID,$type);
|
|
if($info === false) $this->error('收益获取失败');
|
|
$this->success('获取成功',$info);
|
|
}
|
|
|
/**
|
* 绑定支付宝
|
*
|
* @return void
|
*/
|
public function bind_zfb()
|
{
|
$zfbAccount = request()->param('zfbAccount','');
|
if(empty($zfbAccount)) $this->error('支付宝账号不能为空');
|
$truename = request()->param('truename','');
|
if(empty($truename)) $this->error('真实姓名不能为空');
|
$ModelUser = new ModelUser();
|
$save_data = [
|
'true_name' => $truename,
|
'zfb_account' => $zfbAccount,
|
'updatetime' => time()
|
];
|
$res = $ModelUser->where(['id'=>USERID])->update($save_data);
|
if(!$res)$this->error('绑定失败');
|
$this->success('绑定成功',[]);
|
}
|
|
|
/**
|
* 用户提现
|
*/
|
public function withdraw()
|
{
|
$amount = request()->param('amount','0');
|
if($amount < 1)$this->error('最低提现金额为1元');
|
$user = $this->auth->getUser();
|
if(empty($user['true_name']) || empty($user['zfb_account']))$this->error('请先绑定支付宝');
|
if($amount > $user['money']) $this->error("可提现余额不足");
|
$LogicUserWithdrawal = new LogicUserWithdrawal();
|
$res = $LogicUserWithdrawal->doWithdrawal($user['id'],$amount,$user['true_name'],$user['zfb_account']);
|
if(!$res)$this->error('提现失败');
|
$this->success('提交成功,请等待审核',[]);
|
}
|
|
|
/**
|
* 获取相关日志
|
*
|
* @return void
|
*/
|
public function get_balance_log()
|
{
|
$page = request()->param('page',1);
|
$pageSize = request()->param('pageSize',10);
|
$type = request()->param('type',1);
|
$list = [];
|
switch($type){
|
case 0: //结算记录
|
$LogicSettlementRecord = new LogicSettlementRecord();
|
$list = $LogicSettlementRecord->getList(USERID,$page,$pageSize);
|
break;
|
case 1: //提现记录
|
$LogicUserWithdrawal = new LogicUserWithdrawal();
|
$list = $LogicUserWithdrawal->getList(USERID,$page,$pageSize);
|
break;
|
case 2: //余额记录
|
$LogicUserMoneyLog = new LogicUserMoneyLog();
|
$list = $LogicUserMoneyLog->getList(USERID,$page,$pageSize);
|
break;
|
}
|
$this->success('获取成功',$list);
|
}
|
|
|
/**
|
* 绑定微信
|
*/
|
public function bind_wechat()
|
{
|
$avatar = request()->param('avatar','');
|
$gender = request()->param('gender','');
|
$nickName = request()->param('nickName','');
|
$openId = request()->param('openId','');
|
if(empty($openId)) $this->error('绑定参数错误');
|
$LogicUser = new LogicUser();
|
$res = $LogicUser->bindWechat(USERID,$avatar,$gender,$nickName,$openId);
|
$this->success('绑定成功',[]);
|
}
|
|
|
/**
|
* 解绑微信
|
*
|
* @return void
|
*/
|
public function unbound_wechat()
|
{
|
$LogicUser = new LogicUser();
|
$res = $LogicUser->unboundWechat(USERID);
|
$this->success('解绑成功',[]);
|
}
|
|
/**
|
* 修改邀请码
|
*
|
* @return void
|
*/
|
public function changecode(){
|
$user = $this->auth->getUser();
|
if($user->level<2){
|
$this->error('当前等级不能修改邀请码');
|
}
|
//判断是否有修改记录
|
if (\app\common\model\user\CodeChangeHistory::getByUserId($user->id)) {
|
$this->error('邀请码只能修改一次哦');
|
}
|
$invitation_code = request()->param('invite_code','');
|
if (!$invitation_code ) {
|
$this->error(__('请输入邀请码'));
|
}
|
if(strlen($invitation_code)<4){
|
$this->error('邀请码不能少于4位');
|
}
|
if(strlen($invitation_code)>9){
|
$this->error('邀请码不能超过8位');
|
|
}
|
if (\app\common\model\User::where('invitation_code', $invitation_code)->where('id', '<>', $user->id)->find()) {
|
$this->error('邀请码已存在');
|
}
|
$user->invitation_code = $invitation_code;
|
$user->save();
|
//保存修改记录
|
\app\common\model\user\CodeChangeHistory::create([
|
'user_id' => $user->id,
|
'before_code' => $user->invitation_code,
|
'after_code' =>$invitation_code,
|
'create_time' => time()
|
]);
|
$this->success();
|
|
}
|
/**
|
*
|
*获取推荐邀请人
|
*/
|
public function getRecomInviter()
|
{
|
$ModelUser=new ModelUser();
|
$user = $ModelUser->join('recommend_inviter', 't_user.id=t_recommend_inviter.user_id')
|
->field('t_user.id,t_user.avatar,t_user.invitation_code,t_user.nickname')
|
->order('recommend_inviter.order_inde asc')
|
->select();
|
$this->success('获取成功',$user);
|
}
|
|
/**
|
* 检测是否有偏好商品
|
*
|
* @return void
|
*/
|
|
public function check_preference_goods()
|
{
|
//获取当前登录人用户信息
|
$user = $this->auth->getUser();
|
$ModelUserExtend=new ModelUserExtend();
|
$preference_goods=$ModelUserExtend->where(['id'=>$user['id']])->field('p_cids,p_platefrom')->find();
|
if(empty($preference_goods)||empty($preference_goods['p_cids'])) $this->error('暂无偏好商品');
|
$this->success('获取成功',$preference_goods);
|
}
|
|
}
|