12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\api\controller\code;
- use app\api\controller\Controller;
- use app\api\service\User as UserService;
- use app\common\model\code\UserAuthcode as UserAuthcodeModel;
- /**
- * 授权码评价管理
- * Class Comment
- * @package app\api\controller\order
- */
- class UserAuthcode extends Controller
- {
- //生成授权码接口,后面再改成限制账号,
- public function invitecode(){
- $userinfo = UserService::getCurrentLoginUser(true);
- if($userinfo->grade_id!=10001){
- return $this->renderError("没有权限");
- }
- $invite_code = $this->randomkeys();
- $param = $this->request->post();
- if(!isset($param['seller_grade']) || !in_array($param['seller_grade'],[2,3])){
- return $this->renderError("推荐官等级非法");
- }
- $authModel = new UserAuthcodeModel;
- $one = UserAuthcodeModel::where('invite_code',$invite_code)->find();
- $now = Date("Y-m-d H:i:s",time());
- if(empty($one)){
- $data['user_id'] = $userinfo->user_id;
- $data['invite_code'] = $invite_code;
- $data['activation_state'] =0;
- $data['seller_grade'] =$param['seller_grade'];
- $data['create_time'] = $now;
- $data['update_time'] = $now;
- $authModel->save($data);
- return $this->renderSuccess(compact('invite_code'));
- }else{
- return $this->renderError("生成授权码失败,请重新刷新一下页面");
- }
-
- }
- //随机数
- public function randomkeys() {
- $pattern = 'ABCDEFGHIJKLMNPQRSTUVWXYZ';
- $key = '';
- $length = 3;
- for($i=0;$i<$length;$i++){
- $key .= $pattern[mt_rand(0,strlen($pattern)-1)]; //生成php随机数
- }
- $num = rand(1000,9999);
- $key = $key.$num;
- return $key;
- }
- }
|