From 43f6211f3860589fc59ada77bbfa67ed1212d4f4 Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Fri, 6 Sep 2024 11:57:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=8D=AF=E6=96=B9=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/dCase.php | 30 +++++++++++++++++++----------- model/mCase.php | 22 ++++++++-------------- model/mUserCase.php | 4 ++-- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/data/dCase.php b/data/dCase.php index 08c1ac1..46540dc 100644 --- a/data/dCase.php +++ b/data/dCase.php @@ -6,16 +6,17 @@ include_once SERVER_ROOT . '/data/dBase.php'; * 药方相关 * @package data */ + class dCase extends dBase { protected $fieldlist = array( 'tcm_case' => array( - 'id', - 'name', - 'source', - 'original', - 'method', - 'use_num', - 'sort', + 'id', + 'name', + 'source', + 'original', + 'method', + 'use_num', + 'sort', ), 'tcm_case_herb' => array( 'id', @@ -34,13 +35,20 @@ class dCase extends dBase { 'collect_msg', 'collect_time', ), + 'tcm_case_use_log' => array( + 'id', + 'uid', + 'case_id', + 'use_num', + ), ); protected $primary_keys = array( - 'tcm_case' => 'id', - 'tcm_case_herb' => 'id', - 'tcm_herb' => 'id', - 'tcm_collect_log' => 'id', + 'tcm_case' => 'id', + 'tcm_case_herb' => 'id', + 'tcm_herb' => 'id', + 'tcm_collect_log' => 'id', + 'tcm_case_use_log' => 'id', ); } diff --git a/model/mCase.php b/model/mCase.php index ae086fc..dfb1acb 100644 --- a/model/mCase.php +++ b/model/mCase.php @@ -11,6 +11,7 @@ class mCase extends mBase { private $case_herb_tbl; private $herb_tbl; private $collect_log_tbl; + private $case_use_log_tbl; public function __construct() { $this->obj = new dCase(); @@ -18,6 +19,7 @@ class mCase extends mBase { $this->case_herb_tbl = 'tcm_case_herb'; $this->herb_tbl = 'tcm_herb'; $this->collect_log_tbl = 'tcm_collect_log'; + $this->case_use_log_tbl = 'tcm_case_use_log'; } public function createCase($name, $source, $original, $method, $herbs) { @@ -172,18 +174,10 @@ class mCase extends mBase { return $this->obj->selectAll($this->case_herb_tbl, array('sql' => '`case_id`=?', 'vals' => array($case_id)), 'sort asc '); } - public function getCaseByName($name, $page_num, $page_size) { - $where = array(); - if(!empty($name)) { - $sql = " `name` like '%{$name}%'"; - $where = array('sql' => $sql, 'vals' => array()); - } - + public function getCaseByName($uid, $name, $page_num, $page_size) { $offset = ($page_num - 1) * $page_size; - $res = $this->obj->selectAll($this->tbl, $where, 'use_num desc,sort asc ', array($offset, $page_size)); - - if (empty($res)) return array(); - return $res; + $sql = "select c.id,c.name,c.source,c.original,c.method,u.use_num,c.sort from {$this->tbl} as c left join {$this->case_use_log_tbl} as u on c.id=u.case_id and u.uid={$uid} where c.`name` like '%{$name}%' order by u.use_num desc,c.sort desc limit {$offset},{$page_size}"; + return $this->obj->execute($sql, true, true); } public function getCaseByNameTotal($name) { @@ -238,11 +232,11 @@ class mCase extends mBase { return $this->obj->selectIn($this->tbl, array('id' => $ids)); } - public function updateCaseSearchNum($id) { - $res = $this->obj->increase($this->tbl, array('sql' => '`id`=?', 'vals' => array($id)), 'use_num'); + public function updateCaseUseLog($uid, $case_id) { + $res = $this->obj->increase($this->case_use_log_tbl, array('sql' => '`uid`=? and `case_id`=?', 'vals' => array($uid, $case_id)), 'use_num'); if (!$res) { $tool_obj = new qTool(); - $tool_obj->trackLog('tcm', $id, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_case_use_num')); + $tool_obj->trackLog('tcm', $uid . "|" . $case_id, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_case_use_num')); $this->setError('药方使用次数更新失败'); return false; diff --git a/model/mUserCase.php b/model/mUserCase.php index fbb7a5f..f0b3c4a 100644 --- a/model/mUserCase.php +++ b/model/mUserCase.php @@ -143,8 +143,8 @@ class mUserCase extends mBase { return false; } - //更新药方使用次数 这个后期会增加定时脚本去修正 - $m_case->updateCaseSearchNum($case_id); + //更新用户药方使用次数 + $m_case->updateCaseUseLog($uid, $case_id); return $id; }