diff --git a/app/api/controller/CommonController.php b/app/api/controller/CommonController.php index be4d661..d3f523d 100755 --- a/app/api/controller/CommonController.php +++ b/app/api/controller/CommonController.php @@ -203,8 +203,12 @@ class CommonController extends BaseController{ /** * 登录 * @Apidoc\Method("POST") - * @Apidoc\Param("username", type="string",require=true, desc="用户名") - * @Apidoc\Param("password", type="string",require=true, desc="密码") + * @Apidoc\Param("username", type="string",require=false, desc="用户名登录必填") + * @Apidoc\Param("mobile", type="string",require=false, desc="手机号登录必填") + * @Apidoc\Param("type", type="string",require=true,default="mobile",desc="登录方式,username,mobile,email") + * @Apidoc\Param("password", type="string",require=false, desc="密码的登录必填") + * @Apidoc\Param("code", type="string",require=false, desc="验证码登录必填") + * @Apidoc\Param("region", type="string",require=false,default="86", desc="区域,手机号登录必填") */ public function login(Request $request){ $username = input('username'); @@ -237,7 +241,8 @@ class CommonController extends BaseController{ if($user === false){ return $this->fail(\support\Jwt::getError()); } - $user= Hook('user.profile',$user); + //登录成功的事件 + $user = Hook("user.login_successed", $user); return $this->success(__('successful'), $user[0]); } catch (\Exception $e) { return $this->error($e->getMessage()); @@ -271,28 +276,28 @@ class CommonController extends BaseController{ return $this->error(__('Invalid parameters')); } //验证Token - if (!Validate::check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) { - return $this->error(__('Password must be 6 to 30 characters')); + if (!Validate::check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,32}'])) { + return $this->error(__('Password must be 6 to 32 characters')); } - if (!$mobile && !$email){ try{ $user = \support\Jwt::getUser(); }catch(\Exception $e){ - log_alert($e->getMessage()); + //log_alert($e->getMessage()); $user = false; } if($user){ captcha_verfiy('mobile','reset_pwd',$user->mobile); } }else{ - if ($email && Validate::is($email, "email")) { - captcha_verfiy('email','reset_pwd',$email); - $user = UserModel::getByEmail($email); - } if ($mobile && Validate::regex($mobile, "^1\d{10}$")) { captcha_verfiy('mobile','reset_pwd',$mobile); - $user = UserModel::getByMobile($mobile); + $region = Input('region'); + $region = str_replace('+','',$region); + $user = UserModel::where('region',$region)->where('mobile',$mobile)->find(); + }else if ($email && Validate::is($email, "email")) { + captcha_verfiy('email','reset_pwd',$email); + $user = UserModel::getByEmail($email); } } if (!$user) { @@ -327,8 +332,8 @@ class CommonController extends BaseController{ return $this->error(__('Invalid parameters')); } //验证Token - if (!Validate::check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,6}'])) { - return $this->error(__('Trade password must be 6 characters')); + if (!Validate::check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,32}'])) { + return $this->error(__('Trade password must be 6-32 characters')); } if (!$mobile && !$email){ diff --git a/app/api/controller/ThaliController.php b/app/api/controller/ThaliController.php index 68a79d5..f45562a 100755 --- a/app/api/controller/ThaliController.php +++ b/app/api/controller/ThaliController.php @@ -99,10 +99,11 @@ class ThaliController extends BaseController{ return $this->fail(__('Role does not exist')); } $role_id = $thali->role_id; - if($user->role_id >= $role_id){ + if($user->role_id > $role_id){ return $this->fail(__('Your level is too high to purchase this character')); } $price = $thali->price; + if($quantity == 1){ $price = $thali->month_price; } @@ -112,7 +113,17 @@ class ThaliController extends BaseController{ if($quantity == 12){ $price = $thali->year_price; } - $amount = $price * $quantity; + //升级 + $isUpgrade=true; + //续费 + if($user->role_id == $role_id){ + $isUpgrade = false; + } + $amount = $price; + if($isUpgrade){ + //按那个价格算,目前是按原价,剩余时间不做抵扣 + } + //$amount = $price * $quantity; if($amount <=0){ return $this->fail(__('This character group is not allowed to be sold')); } @@ -121,14 +132,17 @@ class ThaliController extends BaseController{ } \support\Jwt::verify_trade_password($request->post('trade_password')); $user = \support\Jwt::getUser(); - $user->role_id = $role_id; $user->expire_at = ($user->expire_at>time() ? $user->expire_at : time())+86400* $quantity * 30; + if($isUpgrade){ + $user->expire_at = (time())+86400* $quantity * 30; + $user->role_id = $role_id; + } $user->save(); cache('user_role_'.$user->userID,[ 'role_id'=>$role_id,'expire_at'=>$user->expire_at ],$user->expire_at-time()); - \app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,$role_id); + \app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,json_encode(['role_id'=>$role_id,'quantity'=>$quantity,'role_name'=>$thali->title])); //Hook('user.roleup', $user); // $data = [ // 'role_id' => $role_id, diff --git a/app/controller/HookController.php b/app/controller/HookController.php index d91147d..53cf956 100755 --- a/app/controller/HookController.php +++ b/app/controller/HookController.php @@ -19,6 +19,7 @@ class HookController{ "nextCode"=> 0 ]); } + //用户注册完成后 function callbackAfterUserRegisterCommand(Request $request): Response { $userID= Input('userID'); @@ -60,25 +61,25 @@ class HookController{ { //log_alert(Input()); - $user_id = Input('sendID'); - $recv_user_id = Input( 'recvID'); - $status = Input('status',1); - $sessionType = Input('sessionType',null); - if($status == 1 && $sessionType != 4){ - //$max = 10000000000;//限制消息数量 - $user_rights = get_user_rights($user_id); - $max = $user_rights['max_send_msg_count']; - $sended_msg_count = cache('single_msg_count_'.$user_id)??0 + cache('group_msg_count_'.$user_id)??0; - if($sended_msg_count > $max){ - return json([ - "actionCode" => 0, - "errCode" => 1002, - "errMsg" => "超出消息数量限制,请先开通或升级会员", - "errDlt" => "超出消息数量限制,请先开通或升级会员", - "nextCode"=> 1 - ]); - } - } + // $user_id = Input('sendID'); + // $recv_user_id = Input( 'recvID'); + // $status = Input('status',1); + // $sessionType = Input('sessionType',null); + // if($status == 1 && $sessionType != 4){ + // //$max = 10000000000;//限制消息数量 + // $user_rights = get_user_rights($user_id); + // $max = $user_rights['max_send_msg_count']; + // $sended_msg_count = cache('single_msg_count_'.$user_id)??0 + cache('group_msg_count_'.$user_id)??0; + // if($sended_msg_count > $max){ + // return json([ + // "actionCode" => 0, + // "errCode" => 1002, + // "errMsg" => "超出消息数量限制,请先开通或升级会员", + // "errDlt" => "超出消息数量限制,请先开通或升级会员", + // "nextCode"=> 1 + // ]); + // } + // } return json([ "actionCode" => 0, "errCode" => 0, @@ -122,8 +123,6 @@ class HookController{ */ public function callbackBeforeSendGroupleMsgCommand(Request $request): Response { - //log_alert('callbackBeforeSendGroupleMsgCommand:'); - //log_alert(Input()); return json([ "actionCode" => 0, "errCode" => 0, @@ -138,9 +137,6 @@ class HookController{ */ public function callbackAfterSendGroupleMsgCommand(Request $request): Response { - - //log_alert('callbackAfterSendGroupleMsgCommand:'); - //log_alert(Input()); return json([ "actionCode" => 0, "errCode" => 0, @@ -160,7 +156,7 @@ class HookController{ $handleResult = Input('handleResult'); $key = 'friend_count_'.$from_user_id; $user_rights = get_user_rights($from_user_id); - $max = $user_rights['max_friend_count']; + $max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; if(cache($key) > $max){ return json([ "actionCode" => 0, @@ -210,7 +206,7 @@ class HookController{ if($handleResult == 1){ $key = 'friend_count_'.$to_user_id; $user_rights = get_user_rights($to_user_id); - $max = $user_rights['max_friend_count']; + $max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; if(cache($key) > $max){ return json([ "actionCode" => 0, @@ -276,6 +272,8 @@ class HookController{ "nextCode"=> 0 ]); } + + //用户删除好友之后得回调 function callbackAfterDeleteFriendCommand() : Response { $friendUserID = Input('friendUserID'); $ownerUserID = Input('ownerUserID'); @@ -297,6 +295,215 @@ class HookController{ "nextCode"=> 0 ]); } + + + /** + * 在创建群组之前的回调 + * @return void + */ + public function callbackbeforeCreateGroupCommand(Request $request): Response + { + $from_user_id = Input('fromUserID'); + $to_user_id = Input('toUserID'); + $handleResult = Input('handleResult'); + if($handleResult == 1){ + $key = 'friend_count_'.$to_user_id; + $user_rights = get_user_rights($to_user_id); + $max = isset($user_rights['max_friend_count']) ? $user_rights['max_friend_count'] : -1; + if(cache($key) > $max){ + return json([ + "actionCode" => 0, + "errCode" => 1001, + "errMsg" => "超出好友数量限制,请先开通或升级会员", + "errDlt" => "超出好友数量限制,请先开通或升级会员", + "nextCode"=> 1 + ]); + } + } + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + /** + * 在创建群组之后的回调 + * @param Request $request + * @return void + */ + public function callbackafterCreateGroupCommand(Request $request):Response + { + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + /** + * 转让群主之后的回调 + * @param Request $request + * @return void + */ + public function callbackAfterTransferGroupOwnerCommand(Request $request):Response + { + $oldOwnerUserID = Input('oldOwnerUserID'); + $newOwnerUserID = Input('newOwnerUserID'); + cache_add('user_'.$oldOwnerUserID.'_create_group_count',-1); + cache_add('user_'.$newOwnerUserID.'_create_group_count',1); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + + /** + * 解散群组后回调 + * @param Request $request + * @return void + */ + public function callbackAfterDisMissGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $ownerID = Input('ownerID'); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + /** + * 用户退出群组的回调 + * @param Request $request + * @return void + */ + public function callbackAfterQuitGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $userID = Input('userID'); + cache_add('user_'.$userID.'_join_group_count',-1); + cache_add('group_'.$groupID.'_user_count',-1); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + /** + * 群成员进群之前的回调 + * @param Request $request + * @return void + */ + public function callbackBeforeMembersJoinGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $memberList = Input('memberList'); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + /** + * 踢除群组成员的回调 + * @param Request $request + * @return void + */ + public function callbackAfterKickGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $kickedUserIDs = Input('kickedUserIDs'); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + /** + * 新成员加入群组之后的回调 + * @param Request $request + * @return void + */ + public function callbackAfterJoinGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $userID = Input('userID'); + cache_add('user_'.$userID.'_join_group_count',-1); + cache_add('group_'.$groupID.'_user_count',-1); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + /** + * 邀请新成员加入群组之前的回调 + * @param Request $request + * @return void + */ + public function callbackBeforeInviteJoinGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $invitedUserIDs = Input('invitedUserIDs'); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + + /** + * 申请加入群组之前的回调 + * @param Request $request + * @return void + */ + public function callbackBeforeJoinGroupCommand(Request $request):Response + { + $groupID = Input('groupID'); + $applyID = Input('applyID'); + return json([ + "actionCode" => 0, + "errCode" => 0, + "errMsg" => "", + "errDlt" => "", + "nextCode"=> 0 + ]); + } + + + + + + + + + + function getSdk(){ $IM = new \support\OpenImSdk\Client([ 'host' => 'http://127.0.0.1:10002', // OpenIM API地址 diff --git a/app/event/User.php b/app/event/User.php index 44426f1..a870bd7 100755 --- a/app/event/User.php +++ b/app/event/User.php @@ -39,6 +39,13 @@ class User{ $this->buildTeam($user); } function login_successed($data=[]){ + $data = $this->profile($data); + /** + * @var \support\OpenImSdk\Client $IM + */ + $IM = request()->IM; + $imToken = $IM->auth->getUserToken($data['userID'],Input('platform')); + $data['imToken'] = $imToken['token']; return $data; } function profile($user=[]){ @@ -65,15 +72,7 @@ class User{ $data['avatar'] = $data['avatar']?:"/static/img/avatar.png"; $data['role'] = isset($role_arr[$data['role_id']]) ? $role_arr[$data['role_id']] : __('普通用户');//\app\model\UserRole::where('id',$data['role_id'])->value('name'); - /** - * @var \support\OpenImSdk\Client $IM - */ - $IM = request()->IM; - $imToken = $IM->auth->getUserToken(idEncode($data['id']),Input('platform')); - $data['imToken'] = $imToken['token']; $last_see = $last_see ?? cache('last_see_'.$data['id']); - $data['id'] = idEncode($data['id']); - $data['userID'] = $data['id'] ; $count = 0; $data['friend_settings'] = [ 'unread_count' => $count ??0, diff --git a/app/functions.php b/app/functions.php index cbd952c..792e813 100755 --- a/app/functions.php +++ b/app/functions.php @@ -720,27 +720,16 @@ if(!function_exists('generateShortUniqueID')){ } if(!function_exists('get_user_rights')){ function get_user_rights($user_id):array{ - // return [ - // 'name' => 'VIP', - // 'max_send_msg_count' => 999999999999, - // 'max_friend_count' => 999999999999, - // 'max_group_join_count' => 999999999999, - // 'max_gourp_create_count' => 999999999999 - // ]; $user_id = idDecode($user_id); $key = 'user_rights_'.$user_id; $result = cache($key); if(!$result){ - // log_alert(\think\facade\Db::name('user_role')->alias('ur') - // ->join('user u','ur.id = u.role_id') - // ->where('u.id',$user_id) - // ->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count') - // ->buildSql()); $result = \think\facade\Db::name('user_role')->alias('ur') ->join('user u','ur.id = u.role_id') ->where('u.id',$user_id) - ->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count') + ->field('ur.name,ur.right') ->find(); + $result['right'] = json_decode($result['right'],true); cache($key,$result,86400); } return $result; diff --git a/app/middleware/ActionHook.php b/app/middleware/ActionHook.php index 8b67253..bab044c 100755 --- a/app/middleware/ActionHook.php +++ b/app/middleware/ActionHook.php @@ -13,7 +13,17 @@ class ActionHook implements MiddlewareInterface public function process(Request $request, callable $next) : Response { if ($request->controller) { - + $headers = [ + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Allow-Origin' => $request->header('origin', '*'), + 'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'), + 'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'), + ]; + if($request->method() == 'OPTIONS'){ + $response = response('',204,$headers); + return $response; + } + log_alert($request->controller); // 禁止直接访问beforeAction afterAction if (substr($request->action,0,9) === '__before_' || substr($request->action,0,8) === '__after_') { $callback = Route::getFallback() ?? function () { @@ -38,7 +48,9 @@ class ActionHook implements MiddlewareInterface return $after_response; } } - + if($request->controller == '\\hg\\apidoc\\Controller' && !$response->getHeader('Access-Control-Allow-Methods')){ + $response->withHeaders($headers); + } return $response; } return $next($request); diff --git a/app/model/Thali.php b/app/model/Thali.php index 50a71ee..85930fb 100755 --- a/app/model/Thali.php +++ b/app/model/Thali.php @@ -37,21 +37,21 @@ class Thali extends Base */ public function getMonthPriceAttr($value,$row) { - return bcmul($row['price'],$row['month_discount'],2); + return round(bcmul($row['price'],$row['month_discount'],2)); } /** * 季价 */ public function getQuarterPriceAttr($value,$row) { - return bcmul($row['price'],$row['quarter_discount'],2); + return round(bcmul($row['price']*3,$row['quarter_discount'],2)); } /** * 年价 */ public function getYearPriceAttr($value,$row) { - return bcmul($row['price'],$row['year_discount'],2); + return round(bcmul($row['price']*12,$row['year_discount'],2)); } function Role(){ return $this->hasOne('UserRole','id','role_id')->bind([ diff --git a/app/model/UserRole.php b/app/model/UserRole.php index e808293..84cd6dd 100755 --- a/app/model/UserRole.php +++ b/app/model/UserRole.php @@ -35,5 +35,19 @@ class UserRole extends Base { return $this->rules ? explode(',', $this->rules) : []; } + public function setRightAttr($v='',$row=[]) + { + if(is_array($v)){ + return json_encode($v); + } + return $v; + } + /** + * @return mixed + */ + public function getRightIds($v='',$row=[]) + { + return $v ? (is_array($v) ? $v : json_decode($v,true)) : []; + } } diff --git a/config/plugin/shopwwi/filesystem/app.php b/config/plugin/shopwwi/filesystem/app.php index 4462cb3..a6e3290 100755 --- a/config/plugin/shopwwi/filesystem/app.php +++ b/config/plugin/shopwwi/filesystem/app.php @@ -89,20 +89,6 @@ return [ // 'proxy' => null, 'prefix' => '', ], - 'ossmy' => [ - 'driver' => \Shopwwi\WebmanFilesystem\Adapter\AliyunOssAdapterFactory::class, - 'accessId' => 'LTAI5tLsFoJAda5juPabytuU', - 'accessSecret' => 'ZyiKpt6lqLBfHPZcvHd7SWM7eENRJW', - 'bucket' => 'wjba', - 'endpoint' => 'oss-cn-hongkong.aliyuncs.com', - 'url' => '//wjba.oss-accelerate.aliyuncs.com', // 静态文件访问域名 - // 'timeout' => 3600, - // 'connectTimeout' => 10, - 'isCName' => false, - 'prefix' => '', - // 'token' => null, - // 'proxy' => null, - ], 'qiniu' => [ 'driver' => \Shopwwi\WebmanFilesystem\Adapter\QiniuAdapterFactory::class, 'accessKey' => 'QINIU_ACCESS_KEY', diff --git a/plugin/admin/app/view/user_role/update.html b/plugin/admin/app/view/user_role/update.html index 2fe1cc0..7cb1265 100755 --- a/plugin/admin/app/view/user_role/update.html +++ b/plugin/admin/app/view/user_role/update.html @@ -10,7 +10,7 @@ @@ -21,28 +21,34 @@ + + + + + +
- +
- +
- +
- +
- +
- +
- +
- +
{php} diff --git a/plugin/admin/public/js/userrole.js b/plugin/admin/public/js/userrole.js index 5a18e95..7c8e498 100755 --- a/plugin/admin/public/js/userrole.js +++ b/plugin/admin/public/js/userrole.js @@ -41,24 +41,36 @@ define(['table','form','yntree'], function (Table,Form,YnTree1) { filter: "string", }, { - field: 'max_send_msg_count', - title: '最大消息数量', + field: 'max_friend_count', + title: '最大好友', filter: "number", + formatter:function(v,row){ + return row.right.max_friend_count; + }, + visible:false }, { - field: 'max_friend_count', - title: '最大好友数量', - filter: "number", + field: 'max_group_user_count', + title: '群容量', + formatter:function(v,row){ + return row.right.max_group_user_count; + } }, { field: 'max_group_join_count', - title: '群组加入限制', + title: '加入群组', filter: "number", + formatter:function(v,row){ + return row.right.max_group_join_count; + } }, { - field: 'max_gourp_create_count', - title: '群组创建限制', + field: 'max_group_create_count', + title: '创建群组', filter: "number", + formatter:function(v,row){ + return row.right.max_group_create_count; + } }, { title: "创建时间", diff --git a/support/Jwt.php b/support/Jwt.php index a23d2c7..211f791 100755 --- a/support/Jwt.php +++ b/support/Jwt.php @@ -296,8 +296,6 @@ class Jwt ]; $_token = \support\Jwt\JwtToken::generateToken($_user); $user->token = $_token['access_token']; - //登录成功的事件 - Hook("user.login_successed", $user); return self::getUserinfo($user); } catch (\Exception $e) { Db::rollback();