作者 lyh

gx

@@ -5,8 +5,12 @@ namespace App\Http\Controllers\Aside; @@ -5,8 +5,12 @@ namespace App\Http\Controllers\Aside;
5 5
6 use App\Enums\Common\Code; 6 use App\Enums\Common\Code;
7 use App\Http\Logic\Aside\LoginLogic; 7 use App\Http\Logic\Aside\LoginLogic;
  8 +use App\Models\Manage\Manage;
  9 +use App\Models\SmsLog;
  10 +use App\Models\User\User as UserModel;
8 use App\Rules\Mobile; 11 use App\Rules\Mobile;
9 use Illuminate\Http\Request; 12 use Illuminate\Http\Request;
  13 +use Mrgoon\AliSms\AliSms;
10 14
11 /** 15 /**
12 * @group 登录 16 * @group 登录
@@ -55,4 +59,37 @@ class LoginController extends BaseController @@ -55,4 +59,37 @@ class LoginController extends BaseController
55 $data = $logic->accessAddress(); 59 $data = $logic->accessAddress();
56 return $this->response('success',Code::SUCCESS,$data); 60 return $this->response('success',Code::SUCCESS,$data);
57 } 61 }
  62 +
  63 + /**
  64 + * 发送登录短信
  65 + * @param Request $request
  66 + * @return \Illuminate\Http\JsonResponse
  67 + */
  68 + public function sendLoginSms()
  69 + {
  70 + $this->request->validate([
  71 + 'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
  72 + ],[
  73 + 'mobile.required' => '手机号码不能为空',
  74 + 'mobile.regex' => '请输入正确的手机号码',
  75 + ]);
  76 + $mobile = $this->param['mobile'];
  77 + $manager = Manage::where(['mobile' => $mobile])->first();
  78 + if (empty($manager)) {
  79 + $this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
  80 + }
  81 + $last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_MANAGER_LOGIN);
  82 + if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
  83 + $this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
  84 + }
  85 + $template = config('aliyunsms.login_sms_temp');
  86 + $code['code'] = rand(100000,999999);
  87 + $ali_sms = new AliSms();
  88 + $send = $ali_sms->sendSms(strval($mobile), $template, $code);
  89 + if (empty($send->Code) && $send->Code != 'OK') {
  90 + $this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
  91 + }
  92 + SmsLog::createLog($mobile, $code['code'],SmsLog::TYPE_MANAGER_LOGIN);
  93 + $this->response('success');
  94 + }
58 } 95 }
@@ -59,7 +59,6 @@ class ProductLogic extends BaseLogic @@ -59,7 +59,6 @@ class ProductLogic extends BaseLogic
59 foreach ($info['keyword_id'] as $keyword_id){ 59 foreach ($info['keyword_id'] as $keyword_id){
60 $info['keyword_id_text'][] =(new KeywordLogic())->getCacheInfo($keyword_id)['title']??''; 60 $info['keyword_id_text'][] =(new KeywordLogic())->getCacheInfo($keyword_id)['title']??'';
61 } 61 }
62 - $info['product_type_text'] = $this->model->productType[$info['product_type']];  
63 $info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim'); 62 $info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim');
64 $info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim'); 63 $info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim');
65 $info['status_text'] = Product::statusMap()[$info['status']] ?? ''; 64 $info['status_text'] = Product::statusMap()[$info['status']] ?? '';
@@ -16,6 +16,8 @@ class SmsLog extends Base @@ -16,6 +16,8 @@ class SmsLog extends Base
16 16
17 const TYPE_REGISTER = 'register'; 17 const TYPE_REGISTER = 'register';
18 const TYPE_LOGIN = 'login'; 18 const TYPE_LOGIN = 'login';
  19 +
  20 + const TYPE_MANAGER_LOGIN = 'manager_login';
19 const TYPE_NOTICE = 'notice'; 21 const TYPE_NOTICE = 'notice';
20 22
21 const USE_USABLE = 0; 23 const USE_USABLE = 0;