From 30c06f690833ea54862704507440efdc290b964c Mon Sep 17 00:00:00 2001
From: pengda <10266652509@qq.com>
Date: Wed, 18 Sep 2024 14:21:40 +0800
Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E6=8B=9F=E8=8D=AF=E6=96=B9=E6=8E=A5?=
 =?UTF-8?q?=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 control/index.php | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/control/index.php b/control/index.php
index 51eed10..ce39a97 100644
--- a/control/index.php
+++ b/control/index.php
@@ -34,29 +34,38 @@ class index extends publicBase {
     }
 
     public function ajax_save_formula() {
+        $uinfo = $this->_check_login();
+
         $name = trim($this->post('name'));
         $source = trim($this->post('source'));
         $method = trim($this->post('method'));
         $herbs = $this->post('herbs');
 
-        //新增药方
         $mformula = new mFormula();
-        $id = $mformula->createCase($name, $source, $method, $herbs);
+
+        //生成唯一id 防止重复请求
+        $request_id = md5($uinfo['uid'] . $name . $source . $herbs);
+        $request_times = $mformula->requestLimit(sprintf(_QR_REQUEST_LIMIT, $request_id), 1, 60);
+        if (!$request_times) $this->ajax_json(false, $mformula->getError());
+
+        //新增药方
+        $id = $mformula->createFormula($uinfo['uid'], $name, $source, $method, $herbs);
         if (!$id) $this->ajax_json(false, $mformula->getError());
 
-        $this->ajax_json(true, '添加成功');
+        $this->ajax_json(true, '添加成功', array('id' => $id));
     }
 
     public function ajax_update_formula() {
+        $uinfo = $this->_check_login();
+
         $id = $this->post('id') + 0;
         $name = trim($this->post('name'));
         $source = trim($this->post('source'));
-        $original = trim($this->post('original'));
         $method = trim($this->post('method'));
         $herbs = $this->post('herbs');
 
         $mformula = new mFormula();
-        $res = $mformula->updateCase($id, $name, $source, $method, $herbs);
+        $res = $mformula->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs);
         if (!$res) $this->ajax_json(false, $mformula->getError());
 
         $this->ajax_json(true, '保存成功');