Commit 2360d669 by 赵增煜
parents 33ad331f 6115e4e0
......@@ -47,4 +47,8 @@ BAIDU_MAP_API_KEY=
# 小程序
WECHAT_MINI_PROGRAM_APPID=wx848e75ebc215b462
WECHAT_MINI_PROGRAM_SECRET=
\ No newline at end of file
WECHAT_MINI_PROGRAM_SECRET=
# 短信
SMS_USERNAME=tzthy
SMS_PASSWORD=
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace App\Admin\Controllers;
use App\Models\AdminUsers;
use App\Services\SmsService;
use Dcat\Admin\Http\Controllers\AuthController as BaseAuthController;
use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request;
......@@ -45,7 +46,8 @@ public function postLogin(Request $request)
/** @var \Illuminate\Validation\Validator $validator */
$validator = Validator::make($credentials, [
$this->username() => 'required',
'password' => 'required',
'password' => 'required_with:role',
'verification_code' => 'required_if:role,store',
]);
if ($validator->fails()) {
......@@ -60,11 +62,19 @@ public function postLogin(Request $request)
}
// 检查用户角色是否为 pharmacy
if ($role === 'store' && $user && $user->role === 'pharmacy') {
// if ($role === 'store' && $user && $user->role === 'pharmacy') {
if ($role === 'store') {
// 验证短信验证码
$verificationCode = $request->input('verification_code');
// 假设您有一个方法来验证短信验证码
if (! $this->verifySmsCode($user->username, $verificationCode)) {
if ($this->verifySmsCode($user->username, $verificationCode)) {
$this->guard()->login($user, $remember);
// 登录成功后,删除缓存中的短信验证码
cache()->forget("sms_verification_code_{$user->username}");
return $this->sendLoginResponse($request);
} else {
return $this->validationErrorsResponse([
'verification_code' => '验证码错误或已过期!',
]);
......@@ -82,4 +92,52 @@ public function postLogin(Request $request)
$this->username() => $this->getFailedLoginMessage(),
]);
}
// 药店管理员角色登录使用
public function getLoginSmsCode(Request $request)
{
// 验证手机号是否存在
$phone = $request->input('username');
if (! $phone) {
return response()->json(['error' => '手机号不能为空']);
}
// 验证手机号格式
if (! preg_match('/^1[3-9]\d{9}$/', $phone)) {
return response()->json(['error' => '手机号格式不正确']);
}
// 检查手机号在管理员表中是否存在
$user = AdminUsers::where('username', $phone)->first();
if (! $user) {
return response()->json(['error' => '该药店手机号未注册,请联系管理员~']);
}
// 生成短信验证码
$verificationCode = rand(100000, 999999); // 生成6位随机验证码
// 存储验证码和有效期(10分钟)
cache()->put("sms_verification_code_{$phone}", $verificationCode, 600); // 600秒 = 10分钟
$templateName = 'verification_code';
$templateData = ['code' => $verificationCode];
$smsService = new SmsService();
$response = $smsService->sendSms($phone, $templateName, $templateData);
return response()->json(['success' => true, 'message' => '验证码已发送']);
}
/**
* 验证短信验证码
*
* @param string $username
* @param string $code
* @return bool
*/
protected function verifySmsCode($username, $code)
{
$cachedCode = cache()->get("sms_verification_code_{$username}");
return $cachedCode && $cachedCode === $code;
}
}
......@@ -39,9 +39,11 @@ protected function grid()
$filter->like('tag_name')->width(3);
});
$grid->setActionClass(Grid\Displayers\Actions::class);
// 行按钮控制
$grid->disableDeleteButton(); // 禁用删除按钮
$grid->disableViewButton(); // 禁用详情按钮
$grid->disableRowSelector(); // 禁用行选择器
// 工具栏按钮控制
$grid->disableBatchDelete(); // 禁用批量删除
......
......@@ -29,9 +29,11 @@ protected function grid()
$filter->like('name')->width(3);
});
$grid->setActionClass(Grid\Displayers\Actions::class);
// 行按钮控制
$grid->disableDeleteButton(); // 禁用删除按钮
$grid->disableViewButton(); // 禁用详情按钮
$grid->disableRowSelector(); // 禁用行选择器
// 工具栏按钮控制
$grid->disableBatchDelete(); // 禁用批量删除
......
......@@ -187,17 +187,23 @@ public function search()
$img->save($tempPath);
// 上传到腾讯云
// \Storage::disk('cos')->putFileAs('prescriptions', $tempPath, $prescriptionNo.'.jpg');
Storage::putFileAs('prescriptions', $tempPath, $prescriptionNo.'.jpg');
// 删除临时文件
// unlink($tempPath);
// return response()->json([
// 'status' => true,
// 'data' => [
// 'img_url' => \Storage::disk('cos')->url($cosPath),
// ],
// ]);
unlink($tempPath);
$cosPath = 'prescriptions/'.$prescriptionNo.'.jpg';
// 将生成的图片路径存储到数据库
$prescription->prescription_pic = $cosPath;
$prescription->save();
return response()->json([
'status' => true,
'data' => [
'img_url' => Storage::url($cosPath),
],
]);
} catch (\Exception $e) {
return response()->json([
'status' => false,
......
<?php
/*
* // +----------------------------------------------------------------------
* // | erp
* // +----------------------------------------------------------------------
* // | Copyright (c) 2006~2020 erp All rights reserved.
* // +----------------------------------------------------------------------
* // | Licensed ( LICENSE-1.0.0 )
* // +----------------------------------------------------------------------
* // | Author: yxx <1365831278@qq.com>
* // +----------------------------------------------------------------------
*/
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PrintController extends Controller
{
public function print(Request $request)
{
$url = $request->input('url');
$pageData = [
'pic' => $url,
];
return view('admin.print', $pageData);
}
}
......@@ -64,8 +64,11 @@
$router->resource('prescription-print', 'PrescriptionPrintController');
// 用法用量
$router->resource('dosage', 'DosageController');
// 搜索打印处方单
$router->get('prescription-search', 'PrescriptionPrintController@search');
// 搜索生成处方单
$router->post('prescription-search', 'PrescriptionPrintController@search');
// 打印处方单
$router->get('/print', 'PrintController@print');
});
$router->get('/auth/smscode', 'AuthController@getLoginSmsCode');
/** 药店菜单-end **/
});
......@@ -157,6 +157,7 @@
'except' => [
'auth/login',
'auth/logout',
'auth/smscode',
],
'enable_session_middleware' => false,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
// -----------------------------------------------------------------------
// Eros Fratini - eros@recoding.it
// jqprint 0.3
//
// - 19/06/2009 - some new implementations, added Opera support
// - 11/05/2009 - first sketch
//
// Printing plug-in for jQuery, evolution of jPrintArea: http://plugins.jquery.com/project/jPrintArea
// requires jQuery 1.3.x
//
// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
//------------------------------------------------------------------------
(function($) {
var opt;
$.fn.jqprint = function (options) {
opt = $.extend({}, $.fn.jqprint.defaults, options);
var $element = (this instanceof jQuery) ? this : $(this);
if (opt.operaSupport && $.browser.opera)
{
var tab = window.open("","jqPrint-preview");
tab.document.open();
var doc = tab.document;
}
else
{
var $iframe = $("<iframe />");
if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-600px", top: "-600px" }); }
$iframe.appendTo("body");
var doc = $iframe[0].contentWindow.document;
}
if (opt.importCSS)
{
if ($("link[media=print]").length > 0)
{
$("link[media=print]").each( function() {
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
});
}
else
{
$("link").each( function() {
doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
});
}
}
if (opt.printContainer) { doc.write($element.outer()); }
else { $element.each( function() { doc.write($(this).html()); }); }
doc.close();
(opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
setTimeout( function() { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
}
$.fn.jqprint.defaults = {
debug: false,
importCSS: true,
printContainer: true,
operaSupport: true
};
// Thanks to 9__, found at http://users.livejournal.com/9__/380664.html
jQuery.fn.outer = function() {
return $($('<div></div>').html(this.clone())).html();
}
})(jQuery);
......@@ -74,16 +74,19 @@
<form id="login-form" method="POST" action="{{ admin_url('auth/login') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="role" value="store"/>
<fieldset class="form-label-group form-group position-relative has-icon-left">
<input
type="text"
type="tel"
class="form-control {{ $errors->has('username') ? 'is-invalid' : '' }}"
name="username"
placeholder="手机号"
value="{{ old('username') }}"
required
autofocus
pattern="^[0-9]*$"
title="请输入有效的手机号"
>
<div class="form-control-position">
......@@ -121,7 +124,7 @@
<div class="form-control-position" style="display: none;">
<i class="feather icon-lock"></i>
</div>
<label for="verification_code">{{ trans('admin.verification_code') }}</label>
<label for="verification_code">验证码</label>
<div class="help-block with-errors"></div>
@if($errors->has('verification_code'))
<span class="invalid-feedback text-danger" role="alert">
......@@ -184,11 +187,10 @@ function getVerificationCode() {
// 发送 AJAX 请求获取验证码
$.ajax({
url: "{{ admin_url('auth/get-verification-code') }}", // 替换为您的接口地址
method: 'POST',
url: "{{ admin_url('auth/smscode') }}", // 替换为您的接口地址
method: 'GET',
data: {
username: username,
role: store,
_token: '{{ csrf_token() }}'
},
success: function(response) {
......@@ -196,7 +198,7 @@ function getVerificationCode() {
alert('验证码已发送');
startCountdown();
} else {
alert(response.message || '获取验证码失败');
alert(response.error || '获取验证码失败');
}
},
error: function() {
......
......@@ -11,7 +11,7 @@
<div class="prescription-preview" id="prescription-container" style="display:none">
<div class="text-center">
<img id="prescription-image" class="img-fluid" style="max-width:100%">
<img id="prescription-image" class="img-fluid" style="max-width:30%">
<div class="mt-3">
<button class="btn btn-success" id="download-btn">
<i class="fa fa-download"></i> 下载处方
......@@ -107,14 +107,14 @@
// 打印处方
print() {
let prescriptionNo = $('#prescription_no').val();
if (!prescriptionNo) {
let url = $('#download-btn').data('url');
if (!url) {
Dcat.error('请先搜索处方');
return;
}
// 打开新的打印页面
let printUrl = '{{ admin_url('prescription-print/view') }}' + '?prescription_no=' + encodeURIComponent(prescriptionNo);
let printUrl = '{{ admin_url('print') }}' + '?url=' + url;
window.open(printUrl, '_blank');
}
......
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>打印处方</title>
<link rel="stylesheet" href="{{asset('static/css/bootstrap.css')}}" crossorigin="anonymous">
<style>
.image-container {
text-align: center;
margin-top: 50px;
}
.image-container img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="image-container">
<img src="{{$pic}}" alt="处方图片"/>
</div>
<script language="javascript" src="{{asset('static/js/jquery.js')}}"></script>
<script language="javascript" src="{{asset('static/js/jquery.print.js')}}"></script>
<script>
// 如果需要打印功能,可以在这里添加
$(".image-container").jqprint();
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment