| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- <?php
- namespace app\api\services;
- use AlibabaCloud\SDK\Cloudauth\V20190307\Models\CompareFacesResponseBody\data;
- use app\common\model\MachineListModel;
- 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 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'] = app('request')->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();
- // $insert['is_regup'] = empty($param['invite_code'])?2:1;
- $this->model->save($insert);
- $uid = $this->model->id;
- // if ($pingyiinfo){
- // incUserPerformance($uid, intval($pingyiinfo['kuisun_money'])+1);
- // }
- $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;
- // Queue::instance()->log('执行成功')->do('userRelationRegister')->job(UserJobs::class)->push([$param['invite_code'], $uid]); // 绑定用户关系和添加用户静态数据
- return ['msg' => '注册成功'];
- }
- // code| 注册的邀请码 uid 当前用户的uid
- 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();
- // $star_config = get_star_config($user['level'] + 1);
- 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'=>''
- ]);
- }
- }
- // 提现
- public function withdraw ($uid, $money, $type, $params)
- {
- $today_count = Db::name('withdraw_log')->where('uid', $uid)->whereDay('create_at', 'today')->count();
- if ($today_count > 0){
- 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){
- throw new Exception('参数错误');
- }
- if (!preg_match("/^[1-9][0-9]*$/" ,$money)){
- throw new Exception('输入非法');
- }
- $user = Db::name('user')
- ->alias('a')
- ->join('user_data b', 'a.id=b.uid')
- ->field('money,status,path,alipay,real_name,is_auth,level,user_type,b.*')
- ->where('a.id', $uid)->find();
- // sr_log('user==='.json_encode($user));
- if ($user['status'] != 1)
- throw new Exception('账号已被禁用');
- // if ($user['user_type'] == 9){
- // if (!in_array($uid,explode('|', env('APP.WITHDRAW_FUCHI_OPEN')))){
- // sr_throw('不可提现');
- // }
- // }
- // if ($user['is_auth'] != 1)
- // throw new Exception('你还未实名认证');
- // if ($type == 1){
- // throw new Exception('暂不支持支付宝提现');
- // if (empty($user['alipay']) || empty($user['alipay_name'])){
- // throw new Exception('你还未绑定支付宝');
- // }
- // }
- // if ($type == 2){
- // if (empty($user['bank_name']) || empty($user['bank_no'])){
- // throw new Exception('你还未绑定银行卡');
- // }
- // }
- if ($money < env('WITHDRAW.ONE_COUNT_MONEY')){
- throw new Exception('单次提现金额要大于'.env('WITHDRAW.ONE_COUNT_MONEY'));
- }
- if ($money % 10 > 0)
- {
- throw new Exception('提现失败,金额必须是10的整数倍');
- }
- if ($money > $user['money'])
- {
- throw new Exception('余额不足');
- }
- $service_money = $money * env('WITHDRAW.APP_WITHDRAW_SCALE')/100;
- $practical_money = $money - $service_money; // 最终金额
- // 2 + 5 其中的 2快
- // $practical_money = $money - env('WITHDRAW.APP_WITHDRAW_BEGIN');
- // $tz_num = number_format($service_money / sysconfig('jhmoney', 'jh_money'), '4', '.','');
- // if ($money < $pay_configs['AGENT_REFLECT_MONEY'])
- // return api_error_return('单笔提现金额小于' . $pay_configs['AGENT_REFLECT_MONEY'] . '元');
- if ($money > 5000 && $type == 1)
- {
- throw new Exception('单笔提现金额大于5000只能选择银行卡');
- }
- if ($money > 30000)
- {
- throw new Exception('单笔提现金额不能大于30000元');
- }
- $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' => $service_money,
- // 'service_tz' => $tz_num,
- 'transfer_type' => 1,
- 'practical_money' => $practical_money,
- 'ip' => app('request')->ip(),
- 'mchid' => '111', // 商户号
- 'w_ordersn'=>('sd'. date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999)))
- ];
- // sr_log(json_encode($insert_log));
- edit_user_money(9, $uid, $money);
- // edit_user_tz(3, $uid, $tz_num);
- $log_id = Db::name('withdraw_log')->insertGetId($insert_log);
- if (!Db::name('withdraw_accoiuntinfo')->where('uid', $uid)->where('type', $type)->where('number', $params['number'])->find()){
- Db::name('withdraw_accoiuntinfo')->insert([
- 'type'=>$type,
- 'name'=>$params['name'],
- 'number'=>$params['number'],
- 'bank_subname'=>$type==1?'':$params['bank_subname'],
- 'create_time'=>sr_getcurtime(time()),
- 'uid'=>$uid
- ]);
- }
- Db::name('user')->where('id', $uid)->inc('total_withdraw', $money)->update();
- }
- public function exchargeMoneyBefore($uid, $money, $mobile){
- if (!preg_match("/^[1-9][0-9]*$/" ,$money)){
- throw new Exception('输入非法');
- }
- $user_info = Db::name('user')->where('id', $uid)->find();
- if ($user_info['user_type'] == 9){
- // if (!in_array($uid,explode('|', env('APP.WITHDRAW_FUCHI_OPEN')))){
- sr_throw('不可转赠余额');
- // }
- }
- $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('用户状态错误,请联系客服');
- }
- $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', '.','');
- // if ($user_info['tz_num'] < $need_jh){
- // sr_throw('当前通证不足'.$need_jh);
- // }
- return [$user_info, $recevice_user_info, $need_jh];
- }
- 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']];
- // edit_user_xz(5, uid, $need_xz);
- // edit_user_xz(6, $recevice_user_info['id'], $xz_num);
- // Db::name('user')->where('id', $recevice_user_info['id'])->save(['is_excharge_lock'=>1]);
- }
- 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, '余额转赠成功', '您已经转给你好友'.$money.'.并扣除通证服务费用:'.$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.'.');
- }
- 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+ $money*5/100;
- $need_jh = $money;
- // if ($user_info['tz_num'] < $need_jh){
- // sr_throw('当前通证不足');
- // }
- return [$user_info, $recevice_user_info, $need_jh];
- }
- 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']];
- }
- public function exchargeJHDone($uid, $money, $mobile){
- [$user, $recevice_user_info, $need_jh] = $this->exchargeJhBefore($uid, $money, $mobile);
- // edit_user_tz(4, $uid, $need_jh-$money);
- edit_user_tz(5, $uid, $money, 0, $recevice_user_info['id']);
- edit_user_tz(6, $recevice_user_info['id'], $money, 0, $uid);
- }
- public function JHBuy($uid, $count){
- $info = Db::name('user')->where('id', $uid)->find();
- $need_money = sysconfig('jhmoney', 'jh_money')*$count;
- if ($info['money'] < $need_money){
- sr_throw('当前你的余额不足');
- }
- if ($count < 0){
- sr_throw('购买数量有问题');
- }
- // 找到最大一期
- $info = Db::name('jh_sellplan')->where('status', 1)->find();
- if ($count > $info['less_num']){
- sr_throw('最多可购买'.$info['less_num'].'枚');
- }
- if ($info['less_num'] > 100){
- if ($count <= 100){
- sr_throw('100枚起兑');
- }
- }
- Db::name('jh_sellplan')->where('id', $info['id'])->dec('less_num', $count)->update();
- edit_user_money(7, $uid, $need_money);
- edit_user_tz(1, $uid, $count);
- return $info['less_num']-$count;
- }
- }
|