UserAuthcode.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\controller\code;
  13. use app\api\controller\Controller;
  14. use app\api\service\User as UserService;
  15. use app\common\model\code\UserAuthcode as UserAuthcodeModel;
  16. /**
  17. * 授权码评价管理
  18. * Class Comment
  19. * @package app\api\controller\order
  20. */
  21. class UserAuthcode extends Controller
  22. {
  23. //生成授权码接口,后面再改成限制账号,
  24. public function invitecode(){
  25. $userinfo = UserService::getCurrentLoginUser(true);
  26. if($userinfo->grade_id!=10001){
  27. return $this->renderError("没有权限");
  28. }
  29. $invite_code = $this->randomkeys();
  30. $param = $this->request->post();
  31. if(!isset($param['seller_grade']) || !in_array($param['seller_grade'],[2,3])){
  32. return $this->renderError("推荐官等级非法");
  33. }
  34. $authModel = new UserAuthcodeModel;
  35. $one = UserAuthcodeModel::where('invite_code',$invite_code)->find();
  36. $now = Date("Y-m-d H:i:s",time());
  37. if(empty($one)){
  38. $data['user_id'] = $userinfo->user_id;
  39. $data['invite_code'] = $invite_code;
  40. $data['activation_state'] =0;
  41. $data['seller_grade'] =$param['seller_grade'];
  42. $data['create_time'] = $now;
  43. $data['update_time'] = $now;
  44. $authModel->save($data);
  45. return $this->renderSuccess(compact('invite_code'));
  46. }else{
  47. return $this->renderError("生成授权码失败,请重新刷新一下页面");
  48. }
  49. }
  50. //随机数
  51. public function randomkeys() {
  52. $pattern = 'ABCDEFGHIJKLMNPQRSTUVWXYZ';
  53. $key = '';
  54. $length = 3;
  55. for($i=0;$i<$length;$i++){
  56. $key .= $pattern[mt_rand(0,strlen($pattern)-1)]; //生成php随机数
  57. }
  58. $num = rand(1000,9999);
  59. $key = $key.$num;
  60. return $key;
  61. }
  62. }