From 4c145c958452562dcc4946dad8fc09518048fa22 Mon Sep 17 00:00:00 2001
From: pengda <10266652509@qq.com>
Date: Wed, 9 Oct 2024 14:17:23 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=BD=95=E8=8D=AF?=
 =?UTF-8?q?=E6=96=B9=E5=AE=A1=E6=A0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 config/define.php                      |  4 +--
 control/index.php                      | 14 ++++++++-
 model/mFormula.php                     | 17 +++++++----
 view/templates/index/formula_add.html  |  4 +--
 view/templates/index/formula_list.html | 56 ++++++++++++++++++++++++++++++++--
 5 files changed, 81 insertions(+), 14 deletions(-)

diff --git a/config/define.php b/config/define.php
index c66dea1..0912b31 100644
--- a/config/define.php
+++ b/config/define.php
@@ -14,8 +14,8 @@
     define('LOG_PATH_BASE', DATACENTER_ROOT.'/logs/tcm/');
     define('LOG_TRACK_SAVE_PATH', LOG_PATH_BASE.'track/%s/%s.log'); // 监控日志的路径,如2014-02-14/1(检测类型).log
 
-    define('TCM_DOMAIN', 'http://tcm.pengda.checkcopy.com');
-    define('CSS_URL', '//tcm.pengda.checkcopy.com');
+    define('TCM_DOMAIN', 'https://yian.kuailebangshou.cn');
+    define('CSS_URL', '//yian.kuailebangshou.cn');
 
     // 小程序获取openid
     define('MP_APPID',"wxba76fd01dab5e1d8");  // 公众号APPID
diff --git a/control/index.php b/control/index.php
index c529cc9..feeea9a 100644
--- a/control/index.php
+++ b/control/index.php
@@ -50,6 +50,7 @@ class index extends publicBase {
         $this->view['uid'] = $_COOKIE['uid'];
         $this->view['token'] = $_COOKIE['token'];
 
+        $status = $this->get('status') + 0;
         $is_all = $this->get('is_all') + 0;
         $name = trim($this->get('name'));
 
@@ -63,6 +64,14 @@ class index extends publicBase {
             $condition['uid'] = 0;
         }
 
+        if ($status == 0) {
+            $condition['is_delete'] = array(0, 2);
+        } elseif ($status == 1) {
+            $condition['is_delete'] = 2;
+        } elseif ($status == 2) {
+            $condition['is_delete'] = 0;
+        }
+
         $mformula = new mFormula();
         $total = $mformula->getFormulaTotal($condition);
 
@@ -126,9 +135,10 @@ class index extends publicBase {
         $uinfo = $this->_check_login();
 
         $id = $this->post('id') + 0;
+        $is_delete = $this->post('is_delete') + 0;
 
         $mformula = new mFormula();
-        $id = $mformula->deleteFormula($uinfo['uid'], $id);
+        $id = $mformula->deleteFormula($uinfo['uid'], $id, $is_delete);
         if (!$id) $this->ajax_json(false, $mformula->getError());
 
         $this->ajax_json(true, '请求成功');
@@ -145,6 +155,7 @@ class index extends publicBase {
 
         $condition = array();
         $condition['uid'] = $uinfo['uid'];
+        $condition['is_delete'] = 0;
         if ($content) $condition['name'] = $content;
 
         $mformula = new mFormula();
@@ -186,6 +197,7 @@ class index extends publicBase {
 
         $condition = array();
         $condition['uid'] = array(0, $uinfo['uid']);
+        $condition['is_delete'] = 0;
         if ($content) $condition['name'] = $content;
 
         $mformula = new mFormula();
diff --git a/model/mFormula.php b/model/mFormula.php
index ca1d8ad..0fba1ba 100644
--- a/model/mFormula.php
+++ b/model/mFormula.php
@@ -25,7 +25,7 @@ class mFormula extends mBase {
     public function getFormulaByCondition($condition, $page_num, $page_size) {
         $offset = ($page_num - 1) * $page_size;
 
-        $where = "is_delete=0";
+        $where = "1=1";
         $use_limit = "";
         if (!empty($condition)) {
             foreach ($condition as $key => $val) {
@@ -33,11 +33,13 @@ class mFormula extends mBase {
                     $where .= " and s.{$key} like '%{$val}%'";
                 } elseif ($key == 'uid' && is_array($val)) {
                     $val = implode(',', $val);
-
                     $where .= " and s.{$key} in ({$val})";
 
                     //兼容查药方只计算当前用户对药方的使用次数
                     $use_limit .= " and u.uid in ({$val})";
+                } elseif ($key == 'is_delete' && is_array($val)) {
+                    $val = implode(',', $val);
+                    $where .= " and {$key} in ({$val})";
                 } else {
                     $where .= " and s.{$key}={$val}";
                 }
@@ -76,14 +78,16 @@ class mFormula extends mBase {
     }
 
     public function getFormulaTotal($condition) {
-        $where = "is_delete=0";
+        $where = "1=1";
         if (!empty($condition)) {
             foreach ($condition as $key => $val) {
                 if ($key == 'name') {
                     $where .= " and {$key} like '%{$val}%'";
                 } elseif ($key == 'uid' && is_array($val)) {
                     $val = implode(',', $val);
-
+                    $where .= " and {$key} in ({$val})";
+                } elseif ($key == 'is_delete' && is_array($val)) {
+                    $val = implode(',', $val);
                     $where .= " and {$key} in ({$val})";
                 } else {
                     $where .= " and {$key}={$val}";
@@ -407,6 +411,7 @@ class mFormula extends mBase {
             //更新原方和用法
             $data['original'] = json_encode($org_herb, JSON_UNESCAPED_UNICODE);
             $data['method'] = $method;
+            $data['is_delete'] = 2;
         }
 
         //格式化药方对应的药材数据
@@ -455,7 +460,7 @@ class mFormula extends mBase {
         return $id;
     }
 
-    public function deleteFormula($uid, $id) {
+    public function deleteFormula($uid, $id, $is_delete) {
         $formula = $this->getFormulaById($id);
         if (empty($formula)) {
             $this->setError('抱歉,未找到匹配的药方');
@@ -466,7 +471,7 @@ class mFormula extends mBase {
             return false;
         }
 
-        $res = $this->updateFormula($id, array('is_delete' => 1));
+        $res = $this->updateFormula($id, array('is_delete' => $is_delete));
         if (!$res) {
             $this->setError('删除药方失败');
             return false;
diff --git a/view/templates/index/formula_add.html b/view/templates/index/formula_add.html
index 0e65183..24be6ec 100644
--- a/view/templates/index/formula_add.html
+++ b/view/templates/index/formula_add.html
@@ -46,7 +46,7 @@
 
                                             <div class="row">
                                                 <label for="source">药方来源<font color='red'>*</font>:</label>
-                                                <input type="text" id="source" name="source" maxlength="" style="width:280px" value="{$data.source}">
+                                                <input type="text" id="source" name="source" maxlength="" style="width:280px" value="{if $data.source}$data.source{else}伤寒杂病论{/if}">
                                             </div>
 
                                             <div class="row">&nbsp;</div>
@@ -178,7 +178,7 @@
             success: function (response) {
                 alert(response.info);
                 if (response.status == true) {
-                    window.location.href = "/index/home"
+                    window.location.href = "/index/formula_list"
                 }
 
                 if(response.data.code == 40002){
diff --git a/view/templates/index/formula_list.html b/view/templates/index/formula_list.html
index e562766..77f22a7 100644
--- a/view/templates/index/formula_list.html
+++ b/view/templates/index/formula_list.html
@@ -28,6 +28,13 @@
                                         <option value="1" {if $smarty.get.is_all==1}selected{/if}>是</option>
                                     </select>
 
+                                    &nbsp;审核状态:&nbsp;
+                                    <select id="status">
+                                        <option value="0" {if $smarty.get.status==0}selected{/if}>全部</option>
+                                        <option value="1" {if $smarty.get.status==1}selected{/if}>待审核</option>
+                                        <option value="2" {if $smarty.get.status==2}selected{/if}>已审核</option>
+                                    </select>
+
                                     &nbsp;药方名称:&nbsp;
                                     <input type="text" id='name' value="{$smarty.get.name}">
 
@@ -96,8 +103,11 @@
                             </td>
 
                             <td>
+                                {if $item.is_delete == 2}
+                                <a href="javascript:;" onclick="to_status({$item.id})">审核通过</a>
+                                {/if}
                                 {if $item.uid == 0}
-                                <a href="/index/formula_add/id/{$item.id}">编辑</a>
+                                <a href="/admin/formula_add/id/{$item.id}">编辑</a>
                                 <a href="javascript:;" onclick="to_delete({$item.id})">删除</a>
                                 {/if}
                             </td>
@@ -116,12 +126,14 @@
 {literal}
 <script type="text/javascript">
     function searchList() {
+        var status = $('#status').val();
         var is_all = $('#is_all').val();
         var name = $.trim($('#name').val());
 
-        var url = '/index/home';
+        var url = '/index/formula_list';
 
         if(is_all > 0) url += '/is_all/' + is_all;
+        if(status > 0) url += '/status/' + status;
         if(name) url += '/name/' + name;
 
         location.href = url;
@@ -140,6 +152,7 @@
 
         const data = {
             id: id,
+            is_delete: 1,
             uid:  uid,
             token:  token,
         };
@@ -152,7 +165,7 @@
             success: function (response) {
                 alert(response.info);
                 if (response.status == true) {
-                    // window.location.reload();
+                    window.location.reload();
                 }
 
                 if(response.data.code == 40002){
@@ -165,6 +178,43 @@
             }
         });
     }
+    function to_status(id) {
+        if (!confirm("确定要操作吗?")) {
+            console.log("用户选择了确认");
+            return false;
+        }
+
+        const uid = {/literal}{$uid}{literal};
+        const token = {/literal}'{$token}'{literal};
+
+        const data = {
+            id: id,
+            is_delete: 0,
+            uid:  uid,
+            token:  token,
+        };
+
+        $.ajax({
+            url: '/ajax_delete_formula', // 替换为你的服务器端处理文件
+            type: 'POST',
+            data: data,
+            dataType: 'json',
+            success: function (response) {
+                if (response.status == true) {
+                    window.location.reload();
+                    return true;
+                }
+                alert(response.info);
+                if(response.data.code == 40002){
+                    window.location.href = "/index/login";
+                }
+            },
+            error: function (xhr, status, error) {
+                console.error('错误:', response);
+                alert('提交失败,请重试。');
+            }
+        });
+    }
 </script>
 {/literal}
 

From 1b7e86ed05ace7da7564d3fb910eb4fea400d5d8 Mon Sep 17 00:00:00 2001
From: pengda <10266652509@qq.com>
Date: Wed, 9 Oct 2024 14:17:23 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=BD=95=E8=8D=AF?=
 =?UTF-8?q?=E6=96=B9=E5=AE=A1=E6=A0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 config/define.php                      |  4 +--
 control/index.php                      | 14 ++++++++-
 model/mFormula.php                     | 17 +++++++----
 view/templates/index/formula_add.html  |  4 +--
 view/templates/index/formula_list.html | 56 ++++++++++++++++++++++++++++++++--
 5 files changed, 81 insertions(+), 14 deletions(-)

diff --git a/config/define.php b/config/define.php
index a76fbe5..0075789 100644
--- a/config/define.php
+++ b/config/define.php
@@ -14,8 +14,8 @@
     define('LOG_PATH_BASE', DATACENTER_ROOT.'/logs/tcm/');
     define('LOG_TRACK_SAVE_PATH', LOG_PATH_BASE.'track/%s/%s.log'); // 监控日志的路径,如2014-02-14/1(检测类型).log
 
-    define('TCM_DOMAIN', 'http://tcm.pengda.checkcopy.com');
-    define('CSS_URL', '//tcm.pengda.checkcopy.com');
+    define('TCM_DOMAIN', 'https://yian.kuailebangshou.cn');
+    define('CSS_URL', '//yian.kuailebangshou.cn');
 
     // 小程序获取openid
     define('MP_APPID',"wx7b28b3159197282d");  // 公众号APPID
diff --git a/control/index.php b/control/index.php
index c529cc9..feeea9a 100644
--- a/control/index.php
+++ b/control/index.php
@@ -50,6 +50,7 @@ class index extends publicBase {
         $this->view['uid'] = $_COOKIE['uid'];
         $this->view['token'] = $_COOKIE['token'];
 
+        $status = $this->get('status') + 0;
         $is_all = $this->get('is_all') + 0;
         $name = trim($this->get('name'));
 
@@ -63,6 +64,14 @@ class index extends publicBase {
             $condition['uid'] = 0;
         }
 
+        if ($status == 0) {
+            $condition['is_delete'] = array(0, 2);
+        } elseif ($status == 1) {
+            $condition['is_delete'] = 2;
+        } elseif ($status == 2) {
+            $condition['is_delete'] = 0;
+        }
+
         $mformula = new mFormula();
         $total = $mformula->getFormulaTotal($condition);
 
@@ -126,9 +135,10 @@ class index extends publicBase {
         $uinfo = $this->_check_login();
 
         $id = $this->post('id') + 0;
+        $is_delete = $this->post('is_delete') + 0;
 
         $mformula = new mFormula();
-        $id = $mformula->deleteFormula($uinfo['uid'], $id);
+        $id = $mformula->deleteFormula($uinfo['uid'], $id, $is_delete);
         if (!$id) $this->ajax_json(false, $mformula->getError());
 
         $this->ajax_json(true, '请求成功');
@@ -145,6 +155,7 @@ class index extends publicBase {
 
         $condition = array();
         $condition['uid'] = $uinfo['uid'];
+        $condition['is_delete'] = 0;
         if ($content) $condition['name'] = $content;
 
         $mformula = new mFormula();
@@ -186,6 +197,7 @@ class index extends publicBase {
 
         $condition = array();
         $condition['uid'] = array(0, $uinfo['uid']);
+        $condition['is_delete'] = 0;
         if ($content) $condition['name'] = $content;
 
         $mformula = new mFormula();
diff --git a/model/mFormula.php b/model/mFormula.php
index ca1d8ad..0fba1ba 100644
--- a/model/mFormula.php
+++ b/model/mFormula.php
@@ -25,7 +25,7 @@ class mFormula extends mBase {
     public function getFormulaByCondition($condition, $page_num, $page_size) {
         $offset = ($page_num - 1) * $page_size;
 
-        $where = "is_delete=0";
+        $where = "1=1";
         $use_limit = "";
         if (!empty($condition)) {
             foreach ($condition as $key => $val) {
@@ -33,11 +33,13 @@ class mFormula extends mBase {
                     $where .= " and s.{$key} like '%{$val}%'";
                 } elseif ($key == 'uid' && is_array($val)) {
                     $val = implode(',', $val);
-
                     $where .= " and s.{$key} in ({$val})";
 
                     //兼容查药方只计算当前用户对药方的使用次数
                     $use_limit .= " and u.uid in ({$val})";
+                } elseif ($key == 'is_delete' && is_array($val)) {
+                    $val = implode(',', $val);
+                    $where .= " and {$key} in ({$val})";
                 } else {
                     $where .= " and s.{$key}={$val}";
                 }
@@ -76,14 +78,16 @@ class mFormula extends mBase {
     }
 
     public function getFormulaTotal($condition) {
-        $where = "is_delete=0";
+        $where = "1=1";
         if (!empty($condition)) {
             foreach ($condition as $key => $val) {
                 if ($key == 'name') {
                     $where .= " and {$key} like '%{$val}%'";
                 } elseif ($key == 'uid' && is_array($val)) {
                     $val = implode(',', $val);
-
+                    $where .= " and {$key} in ({$val})";
+                } elseif ($key == 'is_delete' && is_array($val)) {
+                    $val = implode(',', $val);
                     $where .= " and {$key} in ({$val})";
                 } else {
                     $where .= " and {$key}={$val}";
@@ -407,6 +411,7 @@ class mFormula extends mBase {
             //更新原方和用法
             $data['original'] = json_encode($org_herb, JSON_UNESCAPED_UNICODE);
             $data['method'] = $method;
+            $data['is_delete'] = 2;
         }
 
         //格式化药方对应的药材数据
@@ -455,7 +460,7 @@ class mFormula extends mBase {
         return $id;
     }
 
-    public function deleteFormula($uid, $id) {
+    public function deleteFormula($uid, $id, $is_delete) {
         $formula = $this->getFormulaById($id);
         if (empty($formula)) {
             $this->setError('抱歉,未找到匹配的药方');
@@ -466,7 +471,7 @@ class mFormula extends mBase {
             return false;
         }
 
-        $res = $this->updateFormula($id, array('is_delete' => 1));
+        $res = $this->updateFormula($id, array('is_delete' => $is_delete));
         if (!$res) {
             $this->setError('删除药方失败');
             return false;
diff --git a/view/templates/index/formula_add.html b/view/templates/index/formula_add.html
index 0e65183..24be6ec 100644
--- a/view/templates/index/formula_add.html
+++ b/view/templates/index/formula_add.html
@@ -46,7 +46,7 @@
 
                                             <div class="row">
                                                 <label for="source">药方来源<font color='red'>*</font>:</label>
-                                                <input type="text" id="source" name="source" maxlength="" style="width:280px" value="{$data.source}">
+                                                <input type="text" id="source" name="source" maxlength="" style="width:280px" value="{if $data.source}$data.source{else}伤寒杂病论{/if}">
                                             </div>
 
                                             <div class="row">&nbsp;</div>
@@ -178,7 +178,7 @@
             success: function (response) {
                 alert(response.info);
                 if (response.status == true) {
-                    window.location.href = "/index/home"
+                    window.location.href = "/index/formula_list"
                 }
 
                 if(response.data.code == 40002){
diff --git a/view/templates/index/formula_list.html b/view/templates/index/formula_list.html
index e562766..77f22a7 100644
--- a/view/templates/index/formula_list.html
+++ b/view/templates/index/formula_list.html
@@ -28,6 +28,13 @@
                                         <option value="1" {if $smarty.get.is_all==1}selected{/if}>是</option>
                                     </select>
 
+                                    &nbsp;审核状态:&nbsp;
+                                    <select id="status">
+                                        <option value="0" {if $smarty.get.status==0}selected{/if}>全部</option>
+                                        <option value="1" {if $smarty.get.status==1}selected{/if}>待审核</option>
+                                        <option value="2" {if $smarty.get.status==2}selected{/if}>已审核</option>
+                                    </select>
+
                                     &nbsp;药方名称:&nbsp;
                                     <input type="text" id='name' value="{$smarty.get.name}">
 
@@ -96,8 +103,11 @@
                             </td>
 
                             <td>
+                                {if $item.is_delete == 2}
+                                <a href="javascript:;" onclick="to_status({$item.id})">审核通过</a>
+                                {/if}
                                 {if $item.uid == 0}
-                                <a href="/index/formula_add/id/{$item.id}">编辑</a>
+                                <a href="/admin/formula_add/id/{$item.id}">编辑</a>
                                 <a href="javascript:;" onclick="to_delete({$item.id})">删除</a>
                                 {/if}
                             </td>
@@ -116,12 +126,14 @@
 {literal}
 <script type="text/javascript">
     function searchList() {
+        var status = $('#status').val();
         var is_all = $('#is_all').val();
         var name = $.trim($('#name').val());
 
-        var url = '/index/home';
+        var url = '/index/formula_list';
 
         if(is_all > 0) url += '/is_all/' + is_all;
+        if(status > 0) url += '/status/' + status;
         if(name) url += '/name/' + name;
 
         location.href = url;
@@ -140,6 +152,7 @@
 
         const data = {
             id: id,
+            is_delete: 1,
             uid:  uid,
             token:  token,
         };
@@ -152,7 +165,7 @@
             success: function (response) {
                 alert(response.info);
                 if (response.status == true) {
-                    // window.location.reload();
+                    window.location.reload();
                 }
 
                 if(response.data.code == 40002){
@@ -165,6 +178,43 @@
             }
         });
     }
+    function to_status(id) {
+        if (!confirm("确定要操作吗?")) {
+            console.log("用户选择了确认");
+            return false;
+        }
+
+        const uid = {/literal}{$uid}{literal};
+        const token = {/literal}'{$token}'{literal};
+
+        const data = {
+            id: id,
+            is_delete: 0,
+            uid:  uid,
+            token:  token,
+        };
+
+        $.ajax({
+            url: '/ajax_delete_formula', // 替换为你的服务器端处理文件
+            type: 'POST',
+            data: data,
+            dataType: 'json',
+            success: function (response) {
+                if (response.status == true) {
+                    window.location.reload();
+                    return true;
+                }
+                alert(response.info);
+                if(response.data.code == 40002){
+                    window.location.href = "/index/login";
+                }
+            },
+            error: function (xhr, status, error) {
+                console.error('错误:', response);
+                alert('提交失败,请重试。');
+            }
+        });
+    }
 </script>
 {/literal}