作者 lyh

gx

... ... @@ -5,8 +5,12 @@ namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Http\Logic\Aside\LoginLogic;
use App\Models\Manage\Manage;
use App\Models\SmsLog;
use App\Models\User\User as UserModel;
use App\Rules\Mobile;
use Illuminate\Http\Request;
use Mrgoon\AliSms\AliSms;
/**
* @group 登录
... ... @@ -55,4 +59,37 @@ class LoginController extends BaseController
$data = $logic->accessAddress();
return $this->response('success',Code::SUCCESS,$data);
}
/**
* 发送登录短信
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function sendLoginSms()
{
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
],[
'mobile.required' => '手机号码不能为空',
'mobile.regex' => '请输入正确的手机号码',
]);
$mobile = $this->param['mobile'];
$manager = Manage::where(['mobile' => $mobile])->first();
if (empty($manager)) {
$this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
}
$last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_MANAGER_LOGIN);
if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
$this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
}
$template = config('aliyunsms.login_sms_temp');
$code['code'] = rand(100000,999999);
$ali_sms = new AliSms();
$send = $ali_sms->sendSms(strval($mobile), $template, $code);
if (empty($send->Code) && $send->Code != 'OK') {
$this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
}
SmsLog::createLog($mobile, $code['code'],SmsLog::TYPE_MANAGER_LOGIN);
$this->response('success');
}
}
... ...
... ... @@ -59,7 +59,6 @@ class ProductLogic extends BaseLogic
foreach ($info['keyword_id'] as $keyword_id){
$info['keyword_id_text'][] =(new KeywordLogic())->getCacheInfo($keyword_id)['title']??'';
}
$info['product_type_text'] = $this->model->productType[$info['product_type']];
$info['category_id_text'] = Arr::arrToSet($info['category_id_text'], 'trim');
$info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim');
$info['status_text'] = Product::statusMap()[$info['status']] ?? '';
... ...
... ... @@ -16,6 +16,8 @@ class SmsLog extends Base
const TYPE_REGISTER = 'register';
const TYPE_LOGIN = 'login';
const TYPE_MANAGER_LOGIN = 'manager_login';
const TYPE_NOTICE = 'notice';
const USE_USABLE = 0;
... ...