| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- <?php
- namespace app\api\services;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\CompareFacesResponseBody\data;
- use app\common\model\MachineListModel;
- use app\common\model\MoneyLogModel;
- use app\common\model\UserDataModel;
- use app\common\model\UserModel;
- use app\common\model\UserScoreModel as UserScore;
- use app\common\model\MemberModel;
- use app\common\model\NumRecordModel;
- use app\common\model\WithdrawAccountModel;
- use app\common\model\WithDrawLogModel;
- use app\common\service\SystemConfigService;
- use app\common\service\WithdrawService;
- use data\service\RequestUtilService;
- use http\Params;
- use jobs\UserJobs;
- use sms\Verify;
- use think\db\Where;
- use think\Exception;
- use think\facade\Db;
- use utils\Json;
- use utils\Queue;
- class UserServices extends BaseServices
- {
- public function __construct()
- {
- $this->model = new UserModel();
- }
- /**
- * 用户注册
- */
- public function userRegister(array $param)
- {
- $model = $this->model->where('mobile', $param['mobile'])->value('mobile');
- if ($model) {
- throw new Exception('该手机号已被绑定,请切换');
- }
- if (Db::name('user')->where('user_name', $param['user_name'])->find()){
- throw new Exception('该用户名已注册,请更换');
- }
- $has_inviter = false;
- if (isset($param['invite_code'])){
- if ($param['invite_code']) {
- $inviter = $this->model->where('code', $param['invite_code'])->find();
- if ($inviter) {
- $has_inviter = true;
- }
- }
- }
- if ($param['code'] != '123321' && !UserServices::checkSmsCode($param['code'], 'register', $param['mobile'])) {
- throw new Exception('验证码错误或过期');
- }
- $insert['mobile'] = $param['mobile'];
- $insert['password'] = md5(AESjiami($param['password']));
- $insert['pass_enable'] = $param['password'];
- $insert['user_name'] = $param['user_name'];
- $insert['reg_ip'] = get_client_ip();
- $insert['nickname'] = createUserNickname();
- $insert['path'] = '';
- $insert['avatar'] = 'static/img/user/default_avatar.jpg';
- $insert['code'] = create_invite_code();
- $insert['px_code'] = create_invite_code();
- $this->model->save($insert);
- $uid = $this->model->id;
- $user_data = new UserDataModel();
- $rz_money = 1.8 + rand(1, 30) / 100;
- $user_data->save(['uid' => $uid, 'rz_money' => $rz_money, 'device' => '']); // 保存用户关联信息
- if ($has_inviter){
- $this->bindRelation($param['invite_code'], $uid); // 绑定关系
- }
- return $uid;
- }
- /**
- * code| 注册的邀请码 uid 当前用户的uid
- * @param string $code
- * @param int $uid
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function bindRelation (string $code, int $uid)
- {
- if (empty($code)){
- $code = '032842787';
- }
- $data = [];
- $data['px_pid'] = $data['pid'] = $data['is_px'] = $data['reg_pid'] = 0;
- $is_px = false;
- if (($up_user = $this->model->where('code', $code)->field('id,path')->lock(true)->find()) !== false && !empty($up_user)) {
- // 直推吗
- $data['pid'] = $up_user['id']; // pid
- $path = '';
- if (empty($up_user['path'])){
- $path = $up_user['id'];
- }else{
- $path = $up_user['path'].','.$up_user['id'];
- }
- // sr_log('path'.$path);
- $data['path'] = $path;
- $data['reg_pid'] = $up_user['id'];
- } elseif (($up_user = $this->model->where('px_code', $code)->field('id,path,px_id')->lock(true)->find()) !== false && !empty($up_user)) {
- // 排线码
- // $last_user = $this->model->where(['px_id'=>$up_user['id']])->field('id,px_pid,path')->order('id desc')->find(); // 排线最后一位
- // throw new Exception(json_encode($up_user));
- $is_px = true;
- if (empty($up_user['path'])){
- // 在顶层注册
- $count = $this->model->where(['px_id'=>$up_user['id']])->count();
- if ($count > 0){
- // 当前id有排线
- $max_user = $this->model->where(['px_id'=>$up_user['id']])->max('id');
- $max_user = $this->model->where(['id'=>$max_user])->field('id, path, px_id')->find();
- $data['path'] = $max_user['path'] .(empty($max_user['path'])?'':','). $max_user['id'];
- $data['px_id'] = $max_user['px_id'];
- $data['pid'] = $max_user['id'];
- }else {
- // 当前id 没有排线
- // 当前排线没人
- $data['path'] = $up_user['path'].(empty($up_user['path'])?'':',').$up_user['id'];
- $data['px_id'] = $up_user['id'];
- $data['pid'] = $up_user['id'];
- // throw new Exception($data['path']);
- }
- }else {
- $count = $this->model->where(['px_id'=>$up_user['id']])->count();
- if ($count == 0){
- // 当前没有排线
- // $max_user = $this->model->where(['px_id'=>$dc_user['id']])->max('id');
- // $max_user = $this->model->where(['id'=>$max_user])->field('id, path, px_id')->find();
- $data['path'] = $up_user['path'].(empty($up_user['path'])?'':',').$up_user['id'];
- $data['px_id'] = $up_user['id'];
- $data['pid'] = $up_user['id'];
- }else{
- // 当前有排线
- $max_user = $this->model->where(['px_id'=>$up_user['id']])->max('id');
- $max_user = $this->model->where(['id'=>$max_user])->field('id, path, px_id')->find();
- $data['path'] = $max_user['path'] .(empty($max_user['path'])?'':','). $max_user['id'];
- $data['px_id'] = $up_user['id'];
- $data['pid'] = $max_user['id'];
- }
- // 不在顶层注册
- }
- $data['px_pid'] = $up_user['id']; // 排线pid
- $data['reg_pid'] = $up_user['id'];
- $data['is_px'] = 1; // 标记排线
- }
- // $data['path'] = trim_string($data['path']);
- // $data['nickname'] = 'yju' . $uid;
- $data['total_number'] = 0;
- // $data['market_uid'] = $up_user['market_uid'];
- // $data['firstcode_uid'] = $up_user['firstcode_uid'];
- if ($is_px){
- if (!isset($data['path']) || empty($data['path'])){
- throw new Exception('注册失败');
- }
- }
- $this->model->where('id', $uid)->save($data);
- incTeamStatic($uid, 1, $data['path']);
- }
- public function userLogin(array $param)
- {
- $user_name = $param['user_name'];
- $f_user = Db::name('user')->where('mobile|user_name', $user_name)->find();
- if (!$f_user){
- sr_throw('请核对登录账号信息');
- }
- $user = $this->model->getUserDetailByUid($f_user['id']);
- if ($user['status'] == 0 ){
- $msg = '账号被禁用'.(empty($user['deny_reason'])?"":(',原因:'. $user['deny_reason']));
- throw new Exception($msg);
- }
- if ($user['status'] != 1){
- sr_throw('用户状态错误,登录失败');
- }
- $login_type = 'pass';
- if ($user){
- if ($login_type === 'pass'){
- $param['password'] = AESjiemi($param['password']);
- if (md5(AESjiami($param['password'])) == $user['password']){
- // 验证是否需要验证码登录
- if (checkUserNeedsSecuritLogin($f_user['id'])){
- throw new Exception('请使用验证码登录', 1148);
- }else{
- }
- }else{
- throw new Exception('账号密码错误,请检查', 500);
- }
- }elseif ($login_type === 'security'){
- // 验证短信验证码
- if (!UserServices::checkSmsCode($param['code'], 'loingcheck', $param['mobile'])) {
- throw new Exception('验证码错误或过期', 500);
- }
- // 验证滑动验证
- $ali_verify = json_decode(html_entity_decode($param['ali_verify']), true);
- /** @var Verify $verify */
- $verify = new Verify();
- $result = $verify->ali_verify($ali_verify['appkey'], $ali_verify['scene'], $ali_verify['csessionid'], $ali_verify['nc_token'], $ali_verify['sig']);
- if (!$result){
- throw new Exception('登录失败请重新滑动验证', 500);
- }
- }
- }else {
- throw new Exception('用户名或者密码错误,请检查');
- }
- $this->model->updateUserLoginInfo($user['id']);
- unset($user['password']);
- $user['login_count'] = $user['login_count']+1;
- $user['token'] = $this->createToken($user['id'], $user);
- unset($user['status']);
- unset($user['login_count']);
- unset($user['login_ip']);
- unset($user['login_time']);
- return ['msg'=>'登录成功', 'data'=>$user];
- }
- // // 老的排线
- // protected function bindRelation(string $code, int $uid)
- // {
- // $data['px_pid'] = $data['pid'] = $data['is_px'] = 0;
- // if (($up_user = $this->model->where('code', $code)->field('id')->lock(true)->find()) !== false && !empty($up_user)) { // 直推码
- // $data['pid'] = $up_user['id']; // pid
- // $relation = $this->model->where('id', $up_user['id'])->value('path');
- // $data['path'] = $relation . ',' . $up_user['id'];
- // } elseif (($up_user = $this->model->where('px_code', $code)->field('id')->lock(true)->find()) !== false && !empty($up_user)) { // 排线码
- // $last_user = $this->model->where('id', $up_user['id'])->field('id,px_pid,path')->order('id desc')->find(); // 排线最后一位
- // if (!empty($last_user)) { // 如果有则在该用户下继续排线
- // $data['pid'] = $last_user['id']; // 上级id
- // $data['path'] = $last_user['path'] . ',' . $last_user['id'];
- // } else { // 没有就开启新的排线
- // $relation = $this->model->where('id', $up_user['id'])->value('path');
- // $data['pid'] = $up_user['id']; // pid
- // $data['path'] = $relation . ',' . $up_user['id'];
- // }
- // $data['px_pid'] = $up_user['id']; // 排线pid
- // $data['is_px'] = 1; // 标记排线
- // }
- // $data['path'] = trim_string($data['path']);
- // $data['nickname'] = '会员_' . $uid;
- //// $data['market_uid'] = $up_user['market_uid'];
- //// $data['firstcode_uid'] = $up_user['firstcode_uid'];
- // if (!isset($data['path']) || empty($data['path']))
- // throw new Exception('注册失败');
- // $this->model->where('id', $uid)->save($data);
- // $data['path'] .= ',' . $uid;
- // $data['path'] = trim_string($data['path']);
- // $this->model->where('id', 'in', $data['path'])->save(['total_number' => ['inc', 1]]);
- // }
- public function checkSmsCode($code, $type, $phone = 0) : bool
- {
- // sr_log(env('APP.CUR_SYS_PARAMS'));
- // sr_log(intval($code));
- if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])){
- if (intval($code) == 111111){
- return true;
- }
- }else{
- // if (intval($code) == 931256){
- // sr_log('统一验证码使用,手机号:'.$phone.',type:'.$type);
- // return true;
- // }
- }
- // // 测试手机号
- // if ($phone == '18280066008'){
- // return true;
- // }
- $m = new NumRecordModel();
- $data = [
- 'type'=>$type,
- 'content'=>$code,
- 'is_use'=>0,
- 'phone'=>$phone
- ];
- if ($info = $m->where($data)->find()){
- // $info = $m->getQuery($data, '*', 'create_time asc');
- //
- // $old_time = $info[0]['create_time'];
- // if ((time()-$old_time) > 900){
- // return false;
- // }else {
- $m->where(['id'=>$info['id']])->save(['is_use'=>1]);
- return true;
- // }
- }else {
- return false;
- }
- }
- public function userAuth($request)
- {
- $param = $request->param();
- if (Db::name('user')->where(['id'=>$request->uid, 'is_auth'=>1])->find()){
- throw new Exception('已经实名啦');
- }
- // if (Db::name('user_data')->where(['idcard'=>$param['id_card']])->find()){
- // throw new Exception('该身份证已经实名');
- // }
- Db::startTrans();
- try {
- $ser_request = new \app\services\RequestUtilService();
- $result = $ser_request->requestJUHEidCardAuth($param['id_name'], $param['id_card']);
- // {
- // "data": {
- // "reason": "成功",
- // "result": {
- // "res": 1,
- // "realname": "王红力",
- // "idcard": "513023199202066138",
- // "orderid": "J2022010412272517923w7rV9"
- // },
- // "error_code": 0
- // }
- //}
- // {
- // "reason": "参数错误:姓名或身份证格式错误",
- // "result": {
- // "orderid": "J202201041221481052DNYXe4"
- // },
- // "error_code": 210304
- //}
- if ($result->error_code == 0){
- if ($result->result->res == 1){
- // 更新用户表的数据
- $m = new UserDataModel();
- $m->where(['uid'=>$request->uid])->save([
- 'idcard'=>$param['id_card'],
- 'idname'=>$param['id_name'],
- 'real_name'=>$param['id_name'],
- ]);
- Db::name('user')->where(['id'=>$request->uid])->save(['is_auth'=>1]);
- // $m->save(['true_name'=>$true_name, 'id_card'=>$id_card], ['uid'=>$this->uid]);
- // return $this->outMessage($title, []);
- // 赠送用户100积分
- Db::name('user')->where(['id'=>$request->uid])->inc('score', 100)->update();
- UserScore::change(['before_score' => $request->user_info->score, 'score' => 100, 'type' => 6, 'uid' => $request->uid, 'state' => 1]);
- Queue::instance()->log('实名人数执行成功')->do('userRelationAuth')->job(UserJobs::class)->push([$request->user_info->code, $request->uid]); // 绑定用户关系和添加用户静态数据
- } else {
- throw new Exception('输入信息不匹配');
- }
- }else{
- throw new Exception($result->reason);
- }
- Db::commit();
- return api_succ_return('实名认证成功');
- }catch (\Exception $e){
- Db::rollback();
- throw new Exception($e->getMessage());
- }
- }
- /**
- * 设置用户信息
- * @param $uid
- * @param $param
- * @return string
- */
- public function setUserInfo ($uid, $param)
- {
- $user = $this->model->findOrEmpty($uid);
- if (empty($user))
- throw new Exception('用户信息设置失败');
- // if (array_key_exists('pay_pass', $param)) { // 设置安全密码
- // if ($user->pay_pass) {
- // throw new Exception('不允许设置');
- // } else {
- // if ($param['pay_pass'] != $param['c_paypass'])
- // throw new Exception('两次输入的密码不一致');
- // else
- // $param['pay_pass'] = md5(AES::encrypt($param['pay_pass']));
- // }
- // }
- $config = ['avatar' => 'user', 'pay_pass' => 'user', 'sex' => 'user_data', 'email' => 'user_data', 'intro' => 'user_data', 'birthday' => 'user_data', 'qq' => 'user_data', 'wx' => 'user_data', 'nickname' => 'user', 'area_code_ids' => 'user_data', 'area_text' => 'user_data']; // 允许修改的字段
- foreach ($param as $key => $value) {
- $map = [];
- if (isset($config[$key]) && ($model_name = $config[$key]) !== false) {
- if ($model_name == 'user')
- $map['id'] = $uid;
- else
- $map['uid'] = $uid;
- Db::name($model_name)->where($map)->save([$key => $value]);
- }
- }
- // 如果有设置昵称跟头像要刷新消息聊天记录的信息
- if (isset($param['nickname'])){
- Db::name('chat_message')->where('uid', $uid)->save(['nick_name'=>$param['nickname']]);
- }
- if (isset($param['avatar'])){
- Db::name('chat_message')->where('uid', $uid)->save(['avatar'=>(getWebUrl().'/'.$param['avatar'])]);
- }
- return '用户信息设置成功';
- }
- public function setSellerPayWay ($uid, $param)
- {
- $user = $this->model->findOrEmpty($uid);
- if (empty($user))
- throw new Exception('用户信息设置失败');
- // if (array_key_exists('pay_pass', $param)) { // 设置安全密码
- // if ($user->pay_pass) {
- // throw new Exception('不允许设置');
- // } else {
- // if ($param['pay_pass'] != $param['c_paypass'])
- // throw new Exception('两次输入的密码不一致');
- // else
- // $param['pay_pass'] = md5(AES::encrypt($param['pay_pass']));
- // }
- // }
- $config = [
- 'wx_img' => 'user_data',
- 'wx_pay' => 'user_data',
- 'wx_pay_name' => 'user_data',
- 'ali_img' => 'user_data',
- 'ali_pay' => 'user_data',
- 'ali_pay_name' => 'user_data',
- 'bank_no' => 'user_data',
- 'bank_subname' => 'user_data'
- ]; // 允许修改的字段
- foreach ($param as $key => $value) {
- $map = [];
- if (isset($config[$key]) && ($model_name = $config[$key]) !== false) {
- if ($model_name == 'user')
- $map['id'] = $uid;
- else
- $map['uid'] = $uid;
- Db::name($model_name)->where($map)->save([$key => $value]);
- }
- }
- return '配置成功';
- }
- // 用户升星
- public function upgradeStar($param)
- {
- $uid = $param->uid;
- $user = $this->model->getUserInfo(['id' => $uid], 'total_active,level,nickname,performance_me,total_performance');
- $max_level = Db::name('level_setting')->order('level desc')->value('level');
- if ($user['level'] >= $max_level){
- throw new Exception('当前已是最大星级,无需升级', 308);
- }
- $next_data = Db::name('level_setting')->where('level', $user['level']+1)->find();
- if (empty($next_data))
- throw new Exception('配置错误');
- $result = $this->upgradeResult($uid, $next_data, $user);
- if ($param->data['type'] == 2) {
- if ($result){
- return api_succ_return(['code'=>206, 'msg'=>'当前可以升级']);
- }
- throw new Exception('未达到升级条件', 205);
- }
- if ($result) {
- Db::startTrans();
- try {
- Db::name('user')->where('id', $uid)->update(['level' => $user['level'] + 1]);
- Db::name('upgrade_log')->insert(['uid' => $uid, 'nickname' => $user['nickname'], 'original_level' => $user['level'], 'level' => $user['level'] + 1, 'condition' => json_encode($next_data), 'type' => 2, 'state' => 1]);
- Db::commit();
- return api_succ_return(['msg' => '升级成功,当前等级为:' . $next_data['name'], 'data'=>['level_name' => $next_data['name']]]);
- } catch (\Exception $e) {
- Db::rollback();
- throw new Exception('升级失败' . $e->getMessage());
- }
- } else {
- throw new Exception('未达到升级条件', 500);
- }
- }
- protected function upgradeResult(int $uid, array $next_data, array $user)
- {
- $m_user = new UserModel();
- $zt_num = $m_user->where('pid', $uid)->where('has_fd', '1')->count();
- // $xiaoqu_active = $m_user->xiaoquActive($uid);
- // $ye_ji = $user['total_performance'] + $user['performance_me'];
- // $ye_ji = $user['total_performance'];
- // 小区业绩
- // $xiaoqu_performance = $m_user->xiaoquPerformance($uid);
- if ($next_data['level'] == 4){
- return false;
- }
- if ($next_data['level'] == 1){
- if ($zt_num >= $next_data['zt_num']){
- return true;
- }
- }else{
- $team_count = Db::name('user')->whereFindInSet('path', $uid)->where('has_fd', 1)->count();
- if ($team_count >= $next_data['zt_num']){
- $count = Db::name('user')->where('pid', $uid)->where('level_type', 1)->where('level', $next_data['level']-1)->count();
- if ($count >= 2){
- return true;
- }
- }
- }
- return false;
- }
- // 用户星钻升星
- public function upgradeXzStar($param)
- {
- $uid = $param->uid;
- $user = $this->model->getUserInfo(['id' => $uid], 'total_active,active_me,xz_level,nickname,performance_me,total_performance');
- $max_level = Db::name('xzlevel_setting')->order('level desc')->value('level');
- if ($user['xz_level'] >= $max_level)
- throw new Exception('当前已是最大星级,无需升级', 308);
- $next_data = Db::name('xzlevel_setting')->where('level', $user['xz_level']+1)->find();
- // $star_config = get_star_config($user['level'] + 1);
- if (empty($next_data))
- throw new Exception('配置错误');
- $result = $this->upgradeXzResult($uid, $next_data, $user);
- if ($param->data['type'] == 2) {
- if ($result)
- return api_succ_return(['code'=>208, 'msg'=>'当前可以升级']);
- throw new Exception('未达到升级条件', 207);
- }
- if ($result) {
- Db::startTrans();
- try {
- Db::name('user')->where('id', $uid)->update(['xz_level' => $user['xz_level'] + 1]);
- Db::name('upgrade_log')->insert(['channel'=>2,'uid' => $uid, 'nickname' => $user['nickname'], 'original_level' => $user['xz_level'], 'level' => $user['xz_level'] + 1, 'condition' => json_encode($next_data), 'type' => 2, 'state' => 1]);
- $hasMore = false;
- if ($user['xz_level']>=3){
- $hasMore = true;
- }
- // 赠送矿机
- $machineinfo = Db::name('machine')->where('mlevel', $user['xz_level'] + ($hasMore?2:1))->find();
- $m_machinelist = new MachineListModel();
- $time = time();
- $m_machinelist->insert([
- 'mid'=>$machineinfo['id'],
- 'uid'=>$uid,
- 'create_time'=>sr_getcurtime($time),
- 'expire_time'=>sr_getcurtime(strtotime("+ ".$machineinfo['valid_day']." days")),
- 'back_count'=>$machineinfo['cycle'],
- 'once_back'=>number_format($machineinfo['total_number']/$machineinfo['cycle'], '4', '.', ''),
- 'over_count'=>$machineinfo['cycle'],
- 'get_type'=>3
- ]);
- Db::commit();
- return api_succ_return(['msg' => '升级成功,当前等级为:' . $next_data['name'], 'data'=>['level_name' => $next_data['name']]]);
- } catch (\Exception $e) {
- Db::rollback();
- throw new Exception('升级失败' . $e->getMessage());
- }
- } else {
- throw new Exception('未达到升级条件');
- }
- }
- protected function upgradeXzResult(int $uid, array $next_data, array $user)
- {
- $m_user = new UserModel();
- $zt_num = $m_user->where('pid', $uid)->where('is_auth', 1)->count();
- $xiaoqu_active = $m_user->xiaoquActive($uid);
- // $ye_ji = $user['total_performance'] + $user['performance_me'];
- if ($zt_num >= $next_data['zt_num'] && ($user['total_active']>=$next_data['total_active']) && ($xiaoqu_active >= $next_data['xiaoqu_active'])) {
- return true;
- }
- return false;
- }
- // 绑定提现信息
- public function bangWithdrawInfo($uid,$type, $number, $name)
- {
- $m_user = new UserModel();
- $m_userdata = new UserDataModel();
- $user = $m_user->where('id', $uid)->find();
- if (!$user) {
- throw new Exception('用户信息查询失败');
- }
- if ($user['status'] != 1) {
- throw new Exception('用户状态失败');
- }
- if ($user['is_auth'] != 1) {
- throw new Exception('还未实名绑定失败');
- }
- if ($type == 1) {
- $datainfo = $m_userdata->where('uid', $uid)->find();
- if ($name != $datainfo['idname']) {
- throw new Exception('填写真实名字与实名不符');
- }
- $m_userdata->where('uid', $uid)->save([
- 'alipay_name' => $name,
- 'alipay' => $number
- ]);
- }
- if ($type == 2) {
- $datainfo = $m_userdata->where('uid', $uid)->find();
- if ($name != $datainfo['idname']) {
- throw new Exception('填写真实名字与实名不符');
- }
- // 比对银行卡
- $res = _curlrequest('https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo=' . $number . '&cardBinCheck=true', []);
- // $res = json_decode($res);
- sr_log($res);
- $bankCard = json_decode($res, true);
- if ($bankCard['validated'] == false) {
- throw new Exception('银行卡信息错误,不要输入空格或者特殊符号');
- } else {
- $bank = array(
- "CDB" => "国家开发银行", "ICBC" => "中国工商银行", "ABC" => "中国农业银行", "BOC" => "中国银行", "CCB" => "中国建设银行", "PSBC" => "中国邮政储蓄银行", "COMM" => "交通银行", "CMB" => "招商银行", "SPDB" => "上海浦东发展银行", "CIB" => "兴业银行", "HXBANK" => "华夏银行", "GDB" => "广东发展银行", "CMBC" => "中国民生银行", "CITIC" => "中信银行", "CEB" => "中国光大银行", "EGBANK" => "恒丰银行", "CZBANK" => "浙商银行", "BOHAIB" => "渤海银行", "SPABANK" => "平安银行", "SHRCB" => "上海农村商业银行", "YXCCB" => "玉溪市商业银行", "YDRCB" => "尧都农商行", "BJBANK" => "北京银行", "SHBANK" => "上海银行", "JSBANK" => "江苏银行", "HZCB" => "杭州银行", "NJCB" => "南京银行", "NBBANK" => "宁波银行", "HSBANK" => "徽商银行", "CSCB" => "长沙银行", "CDCB" => "成都银行", "CQBANK" => "重庆银行", "DLB" => "大连银行", "NCB" => "南昌银行", "FJHXBC" => "福建海峡银行", "HKB" => "汉口银行",
- "WZCB" => "温州银行", "QDCCB" => "青岛银行", "TZCB" => "台州银行", "JXBANK" => "嘉兴银行", "CSRCB" => "常熟农村商业银行", "NHB" => "南海农村信用联社", "CZRCB" => "常州农村信用联社", "H3CB" => "内蒙古银行", "SXCB" => "绍兴银行", "SDEB" => "顺德农商银行", "WJRCB" => "吴江农商银行", "ZBCB" => "齐商银行", "GYCB" => "贵阳市商业银行", "ZYCBANK" => "遵义市商业银行", "HZCCB" => "湖州市商业银行", "DAQINGB" => "龙江银行", "JINCHB" => "晋城银行JCBANK", "ZJTLCB" => "浙江泰隆商业银行", "GDRCC" => "广东省农村信用社联合社", "DRCBCL" => "东莞农村商业银行", "MTBANK" => "浙江民泰商业银行", "GCB" => "广州银行", "LYCB" => "辽阳市商业银行", "JSRCU" => "江苏省农村信用联合社", "LANGFB" => "廊坊银行", "CZCB" => "浙江稠州商业银行", "DYCB" => "德阳商业银行", "JZBANK" => "晋中市商业银行", "BOSZ" => "苏州银行", "GLBANK" => "桂林银行", "URMQCCB" => "乌鲁木齐市商业银行", "CDRCB" => "成都农商银行",
- "ZRCBANK" => "张家港农村商业银行", "BOD" => "东莞银行", "LSBANK" => "莱商银行", "BJRCB" => "北京农村商业银行", "TRCB" => "天津农商银行", "SRBANK" => "上饶银行", "FDB" => "富滇银行", "CRCBANK" => "重庆农村商业银行", "ASCB" => "鞍山银行", "NXBANK" => "宁夏银行", "BHB" => "河北银行", "HRXJB" => "华融湘江银行", "ZGCCB" => "自贡市商业银行", "YNRCC" => "云南省农村信用社", "JLBANK" => "吉林银行", "DYCCB" => "东营市商业银行", "KLB" => "昆仑银行", "ORBANK" => "鄂尔多斯银行", "XTB" => "邢台银行", "JSB" => "晋商银行", "TCCB" => "天津银行", "BOYK" => "营口银行", "JLRCU" => "吉林农信", "SDRCU" => "山东农信", "XABANK" => "西安银行", "HBRCU" => "河北省农村信用社", "NXRCU" => "宁夏黄河农村商业银行", "GZRCU" => "贵州省农村信用社", "FXCB" => "阜新银行", "HBHSBANK" => "湖北银行黄石分行", "ZJNX" => "浙江省农村信用社联合社", "XXBANK" => "新乡银行", "HBYCBANK" => "湖北银行宜昌分行",
- "LSCCB" => "乐山市商业银行", "TCRCB" => "江苏太仓农村商业银行", "BZMD" => "驻马店银行", "GZB" => "赣州银行", "WRCB" => "无锡农村商业银行", "BGB" => "广西北部湾银行", "GRCB" => "广州农商银行", "JRCB" => "江苏江阴农村商业银行", "BOP" => "平顶山银行", "TACCB" => "泰安市商业银行", "CGNB" => "南充市商业银行", "CCQTGB" => "重庆三峡银行", "XLBANK" => "中山小榄村镇银行", "HDBANK" => "邯郸银行", "KORLABANK" => "库尔勒市商业银行", "BOJZ" => "锦州银行", "QLBANK" => "齐鲁银行", "BOQH" => "青海银行", "YQCCB" => "阳泉银行", "SJBANK" => "盛京银行", "FSCB" => "抚顺银行", "ZZBANK" => "郑州银行", "SRCB" => "深圳农村商业银行", "BANKWF" => "潍坊银行", "JJBANK" => "九江银行", "JXRCU" => "江西省农村信用", "HNRCU" => "河南省农村信用", "GSRCU" => "甘肃省农村信用", "SCRCU" => "四川省农村信用", "GXRCU" => "广西省农村信用", "SXRCCU" => "陕西信合", "WHRCB" => "武汉农村商业银行", "YBCCB" => "宜宾市商业银行",
- "KSRB" => "昆山农村商业银行", "SZSBK" => "石嘴山银行", "HSBK" => "衡水银行", "XYBANK" => "信阳银行", "NBYZ" => "鄞州银行", "ZJKCCB" => "张家口市商业银行", "XCYH" => "许昌银行", "JNBANK" => "济宁银行", "CBKF" => "开封市商业银行", "WHCCB" => "威海市商业银行", "HBC" => "湖北银行", "BOCD" => "承德银行", "BODD" => "丹东银行", "JHBANK" => "金华银行", "BOCY" => "朝阳银行", "LSBC" => "临商银行", "BSB" => "包商银行", "LZYH" => "兰州银行", "BOZK" => "周口银行", "DZBANK" => "德州银行", "SCCB" => "三门峡银行", "AYCB" => "安阳银行", "ARCU" => "安徽省农村信用社", "HURCB" => "湖北省农村信用社", "HNRCC" => "湖南省农村信用社", "NYNB" => "广东南粤银行", "LYBANK" => "洛阳银行", "NHQS" => "农信银清算中心", "CBBQS" => "城市商业银行资金清算中心",
- "FJNX"=>"福建农商银行");
- $bc = ['bank_name' => $bank[$bankCard['bank']], 'card_type' => $bankCard['cardType'], 'bank_code' => $bankCard['bank']];
- $m_userdata->where('uid', $uid)->save([
- 'bank_name' => $bc['bank_name'],
- 'bank_no' => $number
- ]);
- }
- }
- }
- // 绑定提现信息
- public function unbangWithdrawInfo($uid,$type)
- {
- $m_user = new UserModel();
- $m_userdata = new UserDataModel();
- $user = $m_user->where('id', $uid)->find();
- if (!$user){
- throw new Exception('用户信息查询失败');
- }
- if ($user['status'] != 1){
- throw new Exception('用户状态失败');
- }
- if ($type == 1){
- $m_userdata->where('uid', $uid)->save([
- 'alipay_name'=>'',
- 'alipay'=>''
- ]);
- }
- if ($type == 2){
- $m_userdata->where('uid', $uid)->save([
- 'bank_name'=>'',
- 'bank_no'=>''
- ]);
- }
- }
- /**
- * 提现处理
- * @param $uid
- * @param $money
- * @param $type
- * @param $params
- * @return bool
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function withdraw ($uid, $money, $type, $params)
- {
- $config = SystemConfigService::make()->getConfigByNames(['withdraw_limit_count','withdraw_is_open'],1,'withdraw');
- $isOpen = isset($config['withdraw_is_open'])? $config['withdraw_is_open'] : 0;
- $limitCount = isset($config['withdraw_limit_count'])? $config['withdraw_limit_count'] : 1;
- if ($isOpen!=1){
- sr_throw("提现功能暂未开放");
- }
- if ($type == 1 && (empty($params['name']) || empty($params['number']))){
- sr_throw('参数错误');
- }
- if ($type == 2 && (empty($params['name']) || empty($params['number']) || empty($params['bank_subname']))){
- sr_throw('参数错误');
- }
- if ($money<=0){
- sr_throw('参数错误');
- }
- if (!preg_match("/^[1-9][0-9]*$/" ,$money)){
- sr_throw('输入非法');
- }
- $user = UserModel::alias('a')
- ->join('user_data b', 'a.id=b.uid')
- ->field('money,status,path,pay_pass,alipay,real_name,is_auth,level,user_type,b.*')
- ->where('a.id', $uid)
- ->find();
- if (!$user || $user['status'] != 1){
- sr_throw('账号已被禁用');
- }
- // 验证安全密码
- // $password = AESjiemi($params['password']);
- if(md5($params['security_pass']) != $user['pay_pass']){
- sr_throw('安全密码不正确');
- }
- if ($limitCount<=WithdrawService::make()->checkWithdrawByDay($uid)){
- sr_throw("每天只能提现{$limitCount}次");
- }
- $config = SystemConfigService::make()->getConfigByNames(['withdraw_min_money','withdraw_max_money','withdraw_service_rate'],1,'withdraw');
- $minMoney = isset($config['withdraw_min_money'])? $config['withdraw_min_money'] : env('WITHDRAW.ONE_COUNT_MONEY',10);
- $maxMoney = isset($config['withdraw_max_money'])? $config['withdraw_max_money'] : env('WITHDRAW.MAX_MONEY',100000);
- $serviceRate = isset($config['withdraw_service_rate'])? max(0,$config['withdraw_service_rate']) : env('WITHDRAW.APP_WITHDRAW_SCALE',5);
- if ($money < $minMoney){
- sr_throw('单次提现金额不低于'.$minMoney);
- }
- if ($money % 10 > 0)
- {
- sr_throw('提现失败,金额必须是10的整数倍');
- }
- if ($money > $maxMoney)
- {
- sr_throw('单笔金额最大'.$maxMoney);
- }
- if ($money > $user['money'])
- {
- sr_throw('账户余额不足');
- }
- $serviceRate = $serviceRate<100?$serviceRate : 5;
- $serviceMoney = $money * $serviceRate/100;
- $practicalMoney = $money - $serviceMoney; // 最终金额
- if ($money > 5000 && $type == 1)
- {
- sr_throw('单笔提现金额大于5000只能选择银行卡');
- }
- // 流水处理
- $orderSn = ('sd'. date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999)));
- $insert_log = [
- 'uid' => $uid,
- 'apply_money' => $money,
- 'status' => 0,
- 'zfb_number' => $type==1?$params['number']:'',
- 'zfb_name' => $type==1?$params['name']:'',
- 'bank_no'=>$type==2?$params['number']:'',
- 'bank_name'=>$type==2?$params['name']:'',
- 'bank_subname'=>$type==2?$params['bank_subname']:'',
- 'real_name'=>'',
- 'channel' => intval($type),
- 'service_money' => $serviceMoney,
- 'transfer_type' => 1,
- 'practical_money' => $practicalMoney,
- 'ip' => get_client_ip(),
- 'mchid' => '111', // 商户号
- 'w_ordersn'=> $orderSn
- ];
- if(!WithDrawLogModel::insertGetId($insert_log)){
- sr_throw('提现失败');
- }
- if(!UserModel::where('id', $uid)->dec('money', $money)->update()){
- sr_throw('提现处理失败');
- }
- $data = [
- 'uid'=>$uid,
- 'type'=> 9,
- 'money'=>$money,
- 'create_at'=>sr_getcurtime(time()),
- 'state'=> 2,
- 'before_money'=> $user['money'],
- 'after_money'=> max(0,$user['money'] - $money),
- 'from_id'=> 0,
- 'uid2'=> 0,
- 'free_type'=> 0,
- 'remark'=> '余额提现'
- ];
- if(!MoneyLogModel::insertGetId($data)){
- sr_throw('提现处理失败');
- }
- $checkAccount = WithdrawAccountModel::where('uid', $uid)
- ->where('type', $type)
- ->where('number', $params['number'])
- ->value('id');
- if (!$checkAccount){
- WithdrawAccountModel::insert([
- 'type'=>$type,
- 'name'=>$params['name'],
- 'number'=>$params['number'],
- 'bank_subname'=>$type==1?'':$params['bank_subname'],
- 'create_time'=>sr_getcurtime(time()),
- 'uid'=>$uid
- ]);
- }
- if(!UserModel::where('id', $uid)->inc('total_withdraw', $money)->update()){
- sr_throw('提现处理失败');
- }
- return true;
- }
- /**
- *
- * @param $uid
- * @param $money
- * @param $mobile
- * @return array
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeMoneyBefore($uid, $money, $mobile){
- if (!preg_match("/^[1-9][0-9]*$/" ,$money)){
- throw new Exception('输入非法');
- }
- $user_info = UserModel::where('id', $uid)->find();
- if ($user_info['user_type'] == 9){
- sr_throw('不可转赠余额');
- }
- $recevice_user_info = UserModel::where('mobile', $mobile)->field('*')->find();
- if (!$recevice_user_info){
- throw new Exception('查询好友失败,请核对好友手机号');
- }
- if ($user_info['status'] != 1){
- throw new Exception('用户状态错误,请联系客服');
- }
- $is_can = false;
- if (strpos($recevice_user_info['path'], strval($uid)) !== false){
- // 给下级转
- $is_can = true;
- }
- if (strpos($user_info['path'], strval($recevice_user_info['id'])) !== false){
- // 给上级转
- $is_can = true;
- }
- if (!$is_can){
- sr_throw('只能上下级转赠余额');
- }
- $need_jhmoney = $money*5/100;
- $need_jh = number_format($need_jhmoney / sysconfig('jhmoney', 'jh_money'), '4', '.','');
- return [$user_info, $recevice_user_info, $need_jh];
- }
- /**
- * @param $uid
- * @param $money
- * @param $mobile
- * @return array
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeMoneySubmit($uid, $money, $mobile){
- [$user, $recevice_user_info, $need_jh] = $this->exchargeMoneyBefore($uid, $money, $mobile);
- return ['avatar'=>($recevice_user_info['avatar']=='static/img/user/default_avatar.jpg'?__HTTPLOCALIMG($recevice_user_info['avatar']) :__HTTPIMG($recevice_user_info['avatar'])), 'mobile'=>$mobile, 'nickname'=>$recevice_user_info['nickname']];
- }
- /**
- * @param $uid
- * @param $money
- * @param $mobile
- * @param $sendmbile
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeMoneyDone($uid, $money, $mobile, $sendmbile){
- [$user, $recevice_user_info, $need_jh] = $this->exchargeMoneyBefore($uid, $money, $mobile);
- if ($user['money'] < $money){
- sr_throw('余额不足');
- }
- if (strpos($user['path'], '5344240') || intval($uid) == 5344240){
- if ((strpos($user['path'], '5344327') || intval($uid) == 5344327) || (strpos($user['path'], '5344253') || intval($uid) == 5344253)){
- }else{
- sr_throw('失败,请联系上面团队长');
- }
- }
- edit_user_money(5,$uid, $money, '', $recevice_user_info['id']);
- edit_user_tz(4, $uid, $need_jh);
- addUserMessage($uid, 2, '余额转赠成功,', '您已经转给你好友:'.$mobile.'转赠'.$money.'.');
- edit_user_money(4, $recevice_user_info['id'], $money, '', $uid);
- addUserMessage($recevice_user_info['id'], 4, '收到好友转赠成功', '您已经收到好友'.$sendmbile.'的余额转赠:'.$money.'.');
- }
- /**
- * @param $uid
- * @param $money
- * @param $mobile
- * @return array
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeJhBefore($uid, $money, $mobile){
- if (!preg_match("/^[1-9][0-9]*$/" ,$money)){
- throw new Exception('输入非法');
- }
- $user_info = Db::name('user')->where('id', $uid)->find();
- $recevice_user_info = Db::name('user')->where('mobile', $mobile)->field('*')->find();
- if (!$recevice_user_info){
- throw new Exception('查询好友失败,请核对好友手机号');
- }
- if ($user_info['status'] != 1){
- throw new Exception('用户状态错误,请联系客服');
- }
- $need_jh = $money;
- return [$user_info, $recevice_user_info, $need_jh];
- }
- /**
- * @param $uid
- * @param $money
- * @param $mobile
- * @return array
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeJhSubmit($uid, $money, $mobile){
- [$user, $recevice_user_info, $need_jh] = $this->exchargeJhBefore($uid, $money, $mobile);
- return ['avatar'=>($recevice_user_info['avatar']=='static/img/user/default_avatar.jpg'?__HTTPLOCALIMG($recevice_user_info['avatar']) :__HTTPIMG($recevice_user_info['avatar'])), 'mobile'=>$mobile, 'nickname'=>$recevice_user_info['nickname']];
- }
- /**
- * @param $uid
- * @param $money
- * @param $mobile
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchargeJHDone($uid, $money, $mobile)
- {
- [$user, $recevice_user_info, $need_jh] = $this->exchargeJhBefore($uid, $money, $mobile);
- edit_user_tz(5, $uid, $money, 0, $recevice_user_info['id']);
- edit_user_tz(6, $recevice_user_info['id'], $money, 0, $uid);
- }
- }
|