diff --git a/app/Http/Controllers/Mobile/CommonController.php b/app/Http/Controllers/Mobile/CommonController.php index 2339345..852b4ed 100644 --- a/app/Http/Controllers/Mobile/CommonController.php +++ b/app/Http/Controllers/Mobile/CommonController.php @@ -42,13 +42,12 @@ class CommonController extends Controller * ) * ) */ - public function sendSms() - { + public function sendSms(){ $all = \request()->all(); $messages = [ - 'mobile.required' => __('mobile.common.mobile_required'), - 'mobile.numeric' => __('mobile.common.mobile_numeric'), - 'type.numeric' => __('mobile.common.type_required'), + 'mobile.required' => '手机号必填', + 'mobile.numeric' => '手机号格式错误', + 'type.numeric' => '类型必填', ]; $validator = Validator::make($all, [ 'mobile' => 'required|numeric', @@ -58,27 +57,27 @@ class CommonController extends Controller return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]); } $key = $all['mobile']; - if ($all['type'] == 1) { + if($all['type'] == 1){ // 参观预约验证码 - $key = 'visit_' . $key; + $key = 'visit_'.$key; } - if ($all['type'] == 2) { + if($all['type'] == 2){ // 参观预约验证码 - $key = 'activity_' . $key; + $key = 'activity_'.$key; } $check = Cache::get($key); - if (isset($check) && time() - $check['time'] <= 60) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.common.send_too_frequent')]); + if(isset($check) && time() - $check['time'] <= 60){ + return $this->fail([ResponseCode::ERROR_BUSINESS, '请勿频繁发送']); } - $code = randStr(4, true); + $code = randStr(4,true); $template_id = 'Pat5Z3'; - $result = sms($all['mobile'], ['code' => $code, 'minutes' => 5], $template_id); - if ($result) { + $result = sms($all['mobile'], ['code'=>$code,'minutes'=>5], $template_id); + if($result){ // 缓存 - Cache::put($key, ['code' => $code, 'time' => time()], 5); - return $this->success(__('mobile.common.send_success')); + Cache::put($key,['code'=>$code,'time'=>time()],5); + return $this->success("发送成功"); } - return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, __('mobile.common.send_failed')]); + return $this->fail([StarterResponseCode::START_ERROR_PARAMETER,"发送失败"]); } } diff --git a/app/Http/Controllers/Mobile/UserController.php b/app/Http/Controllers/Mobile/UserController.php index 4f62797..8e6785a 100644 --- a/app/Http/Controllers/Mobile/UserController.php +++ b/app/Http/Controllers/Mobile/UserController.php @@ -29,7 +29,7 @@ class UserController extends CommonController { $all = \request()->all(); $messages = [ - 'code.required' => __('mobile.user.code_required'), + 'code.required' => 'code必填', ]; $validator = Validator::make($all, [ 'code' => 'required', @@ -43,7 +43,7 @@ class UserController extends CommonController $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $appSecret . "&js_code={$all['code']}&grant_type=authorization_code"; $userInfo = json_decode(file_get_contents($url), true); if (!isset($userInfo['openid'])) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.user.code_invalid')]); + return $this->fail([ResponseCode::ERROR_BUSINESS, 'code异常']); } $openid = $userInfo['openid']; //判断该用户是否在数据库 @@ -82,7 +82,7 @@ class UserController extends CommonController $model = User::find($this->getUserId()); $model->fill($all); $model->save(); - return $this->success(__('mobile.user.update_success')); + return $this->success("更新成功"); } /** @@ -103,7 +103,7 @@ class UserController extends CommonController { $all = \request()->all(); $messages = [ - 'code.required' => __('mobile.user.mobile_required'), + 'code.required' => 'code必填', ]; $validator = Validator::make($all, [ 'code' => 'required', @@ -162,7 +162,7 @@ class UserController extends CommonController public function myVisit() { $all = request()->all(); - $list = Visit::with('accompany.department', 'logs.admin', 'logs.user', 'visitTime', 'admin', 'visitArea', 'acceptAdmin.department', 'acceptAdminSignFile', 'acceptGoodsAdmin.department')->where('user_id', $this->getUserId()) + $list = Visit::with('accompany.department','logs.admin', 'logs.user', 'visitTime', 'admin', 'visitArea', 'acceptAdmin.department', 'acceptAdminSignFile', 'acceptGoodsAdmin.department')->where('user_id', $this->getUserId()) ->where(function ($query) use ($all) { if (isset($all['type'])) { $query->where('type', $all['type']); @@ -190,7 +190,7 @@ class UserController extends CommonController { $all = \request()->all(); $messages = [ - 'id.required' => __('mobile.user.id_required'), + 'id.required' => 'Id必填', ]; $validator = Validator::make($all, [ 'id' => 'required' @@ -198,7 +198,7 @@ class UserController extends CommonController if ($validator->fails()) { return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); } - $detail = Visit::with('accompany.department', 'logs.admin', 'logs.user', 'visitTime', 'admin', 'visitArea', 'acceptAdmin.department', 'acceptAdminSignFile', 'acceptGoodsAdmin.department')->find($all['id']); + $detail = Visit::with('accompany.department','logs.admin', 'logs.user', 'visitTime', 'admin', 'visitArea', 'acceptAdmin.department', 'acceptAdminSignFile', 'acceptGoodsAdmin.department')->find($all['id']); return $this->success($detail); } @@ -217,7 +217,7 @@ class UserController extends CommonController */ public function config() { - $list = Config::all(); + $list = Config::get(); return $this->success($list); } diff --git a/app/Http/Controllers/Mobile/VisitController.php b/app/Http/Controllers/Mobile/VisitController.php index 926b8ca..91ef7dd 100644 --- a/app/Http/Controllers/Mobile/VisitController.php +++ b/app/Http/Controllers/Mobile/VisitController.php @@ -12,7 +12,6 @@ use App\Models\VisitArea; use App\Models\VisitAudit; use App\Models\VisitLog; use App\Models\VisitTime; -use App\Notifications\VisitEmailNotify; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -65,9 +64,9 @@ class VisitController extends CommonController { $all = \request()->all(); $messages = [ - 'name.required' => __('mobile.visit.name_required'), - 'visit_area_id.required' => __('mobile.visit.visit_area_id_required'), - 'accept_admin_id.required' => __('mobile.visit.accept_admin_id_required') + 'name.required' => '名称必填', + 'visit_area_id.required' => '区域id必填', + 'accept_admin_id.required' => '接待人必填' ]; $validator = Validator::make($all, [ 'name' => 'required', @@ -106,11 +105,11 @@ class VisitController extends CommonController // 上级审核 $admin = Admin::find($all['accept_admin_id']); if (empty($admin->department_id)) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.visit.accept_admin_department_not_exists')]); + return $this->fail([ResponseCode::ERROR_BUSINESS, '接待人部门不存在']); } $department = Department::find($admin->department_id); if (empty($department->manager_id)) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.visit.accept_admin_department_manager_not_exists')]); + return $this->fail([ResponseCode::ERROR_BUSINESS, '接待人部门不存在负责人']); } $item['admin_id'] = $department->manager_id; } @@ -127,24 +126,37 @@ class VisitController extends CommonController } } VisitLog::add('', $this->getUser(), $model->id, isset($all['id']) ? '更新拜访记录' : '新增拜访记录'); + // 通知,发订阅消息给当前用户 + $visitTime = VisitTime::find($all['visit_time_id']); // 被访人信息 $acceptAdmin = Admin::find($all['accept_admin_id']); - - // 邮件通知被访人 - if ($acceptAdmin && $acceptAdmin->email) { - $visitData = [ - 'name' => $all['name'], - 'date' => $all['date'], - 'mobile' => $all['mobile'], - 'reason' => $all['reason'] ?? null, - ]; - $acceptAdmin->notify(new VisitEmailNotify($visitData)); - } - - // 邮件通知第一个审核人 + $accpetDepartment = Department::find($all['accpet_department_id']); + $templateData = [ + 'date1' => [ + 'value' => $all['date'] + ], + 'name2' => [ + 'value' => $all['name'] + ], + 'phone_number3' => [ + 'value' => $all['mobile'] + ], + 'name4' => [ + 'value' => $acceptAdmin->name ?? '', + ], + 'thing6' => [ + 'value' => $accpetDepartment->name ?? '' + ], + ]; + Visit::subMsg('DmzNRREPFdZrMWconNDdbj_ebtVPRWufq27kRQ25eNg', $this->getUser()->openid, $templateData, $model->id); + // 短信通知被访人 + $vars = ['date' => $all['date'], 'name' => $all['name'], 'phone_number' => $all['mobile']]; + $template_id = '5wReg1'; + sms($acceptAdmin->mobile, $vars, $template_id); + // 短信通知第一个审核人 VisitAudit::smsNextAudit($model, -1); DB::commit(); - return $this->success(__('mobile.visit.update_success')); + return $this->success('更新成功'); } catch (\Exception $exception) { DB::rollBack(); return $this->fail([$exception->getCode(), $exception->getMessage()]); @@ -169,7 +181,7 @@ class VisitController extends CommonController { $all = \request()->all(); $messages = [ - 'type.required' => __('mobile.visit.type_required') + 'type.required' => '类型必填' ]; $validator = Validator::make($all, [ 'type' => 'required' @@ -247,13 +259,13 @@ class VisitController extends CommonController $type = request('type'); $log = StudyLog::where('type', $type)->where('user_id', $this->getUserId())->orderBy('id', 'desc')->first(); if (empty($log)) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.visit.not_studied')]); + return $this->fail([ResponseCode::ERROR_BUSINESS, '未学习']); } $diff = Carbon::parse($log->created_at)->diffInDays(Carbon::now()); if ($diff > $log->expire_day) { - return $this->fail([ResponseCode::ERROR_BUSINESS, __('mobile.visit.study_expired')]); + return $this->fail([ResponseCode::ERROR_BUSINESS, '学习过期']); } - return $this->success(__('mobile.visit.study_valid')); + return $this->success("学习有效中"); } /** @@ -304,7 +316,7 @@ class VisitController extends CommonController { $all = request()->all(); $messages = [ - 'idcard.required' => __('mobile.visit.idcard_required') + 'idcard.required' => '身份证数组必填' ]; $validator = Validator::make($all, [ 'idcard' => 'required' diff --git a/routes/api.php b/routes/api.php index 411945a..f0c00dd 100644 --- a/routes/api.php +++ b/routes/api.php @@ -96,7 +96,7 @@ Route::group(['prefix' => 'admin', 'middleware' => ['sanctum.jwt:admin', 'set.lo // 前台 Route::get('mobile/user/login', [\App\Http\Controllers\Mobile\UserController::class, 'login']); Route::get('mobile/user/config', [\App\Http\Controllers\Mobile\UserController::class, 'config']); -Route::group(["namespace" => "Mobile", "prefix" => "mobile", "middleware" => ["sanctum.jwt:mobile", "set.locale"]], function () { +Route::group(["namespace" => "Mobile", "prefix" => "mobile", "middleware" => "sanctum.jwt:mobile"], function () { Route::post('user/save', [\App\Http\Controllers\Mobile\UserController::class, 'save']); Route::get('user/mobile', [\App\Http\Controllers\Mobile\UserController::class, 'mobile']); Route::get('user/show', [\App\Http\Controllers\Mobile\UserController::class, 'show']);