From 880bfd2b98b72b59543ce1a4328032c7586fb850 Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Tue, 15 Oct 2024 18:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E9=87=8F=E5=8D=95=E4=BD=8D=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/define.php | 5 +++++ control/index.php | 17 ++++++++--------- data/dFormula.php | 9 ++------- model/mFormula.php | 28 +++++++++++----------------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/config/define.php b/config/define.php index 70c30cc..e4f41e1 100644 --- a/config/define.php +++ b/config/define.php @@ -77,6 +77,11 @@ ) ); + define('WEIGHT_LIANG', 1); + $GLOBALS['weight_convert_list'] = array( + '两'=> WEIGHT_LIANG, + ); + $GLOBALS['weight_list'] = array( "汉" => array( '少许'=>'', diff --git a/control/index.php b/control/index.php index cd256b7..62cfc01 100644 --- a/control/index.php +++ b/control/index.php @@ -331,18 +331,17 @@ class index extends publicBase { public function ajax_unit_conv() { $uinfo = $this->_check_login(); - $name = trim($this->post('name')) ? trim($this->post('name')) : '两'; + $unit_name = '两'; + $unit_type = $GLOBALS['weight_convert_list'][$unit_name]; $m_formula = new mFormula(); - $unit = $m_formula->getUnitByName($name); + $unit_conv = $m_formula->getUnitConvList($unit_type); - $unit_conv = $m_formula->getUnitConvList($unit['id']); - - $user_conv = $m_formula->getUserConv($uinfo['uid'], $unit['id']); + $user_conv = $m_formula->getUserConv($uinfo['uid'], $unit_type); foreach ($unit_conv as &$conv) { - $conv['conv_txt'] = "1{$unit['name']}={$conv['num']}g"; + $conv['conv_txt'] = "1{$unit_name}={$conv['num']}g"; if($user_conv['conv_id'] == $conv['id']){ - $user_conv['conv_txt'] = "当前1{$unit['name']}={$conv['num']}g"; + $user_conv['conv_txt'] = "当前1{$unit_name}={$conv['num']}g"; } } @@ -352,11 +351,11 @@ class index extends publicBase { public function ajax_set_user_conv() { $uinfo = $this->_check_login(); - $unit_id = trim($this->post('unit_id')) + 0; + $unit_type = trim($this->post('unit_type')) + 0; $conv_id = trim($this->post('conv_id')) + 0; $m_formula = new mFormula(); - $res = $m_formula->saveUserConv($uinfo['uid'], $unit_id, $conv_id); + $res = $m_formula->saveUserConv($uinfo['uid'], $unit_type, $conv_id); if (!$res) $this->ajax_json(false, $m_formula->getError()); $this->ajax_json(true, '保存成功'); diff --git a/data/dFormula.php b/data/dFormula.php index 518a5bb..72dba34 100644 --- a/data/dFormula.php +++ b/data/dFormula.php @@ -44,14 +44,10 @@ class dFormula extends dBase { 'formula_id', 'use_num', ), - 'tcm_unit_list' => array( - 'id', - 'name', - ), 'tcm_unit_conv' => array( 'id', 'uid', - 'unit_id', + 'unit_type', 'num', 'from', 'is_delete', @@ -60,7 +56,7 @@ class dFormula extends dBase { 'tcm_user_conv' => array( 'id', 'uid', - 'unit_id', + 'unit_type', 'conv_id', ), ); @@ -71,7 +67,6 @@ class dFormula extends dBase { 'tcm_herb' => 'id', 'tcm_collect_log' => 'id', 'tcm_formula_use_log' => 'id', - 'tcm_unit_list' => 'id', 'tcm_unit_conv' => 'id', 'tcm_user_conv' => 'id', ); diff --git a/model/mFormula.php b/model/mFormula.php index 58b1e44..efe8ad0 100644 --- a/model/mFormula.php +++ b/model/mFormula.php @@ -12,7 +12,6 @@ class mFormula extends mBase { private $herb_tbl; private $collect_log_tbl; private $formula_use_log_tbl; - private $unit_list; private $unit_conv; private $user_conv; @@ -23,7 +22,6 @@ class mFormula extends mBase { $this->herb_tbl = 'tcm_herb'; $this->collect_log_tbl = 'tcm_collect_log'; $this->formula_use_log_tbl = 'tcm_formula_use_log'; - $this->unit_list = 'tcm_unit_list'; $this->unit_conv = 'tcm_unit_conv'; $this->user_conv = 'tcm_user_conv'; } @@ -81,10 +79,10 @@ class mFormula extends mBase { public function convByUserChoice($uid, $num_str) { $unit_name = preg_replace('/\d/', '', $num_str); - $unit = $this->getUnitByName($unit_name); - if (!$unit) return false; + $unit_type = $GLOBALS['weight_convert_list'][$unit_name]; + if (!$unit_type) return false; - $user_conv = $this->getUserConv($uid, $unit['id']); + $user_conv = $this->getUserConv($uid, $unit_type); if (!$user_conv) return false; $unit_conv = $this->getUnitConvById($user_conv['conv_id']); @@ -642,29 +640,25 @@ class mFormula extends mBase { return $this->obj->count($this->collect_log_tbl); } - public function getUnitByName($name) { - return $this->obj->select($this->unit_list, array('sql' => '`name`=?', 'vals' => array($name))); - } - public function getUnitConvById($id) { return $this->obj->select($this->unit_conv, array('sql' => '`id`=? and `is_delete`=?', 'vals' => array($id, 0))); } - public function getUnitConvList($unit_id) { - return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_id`=? and `is_delete`=?', 'vals' => array($unit_id, 0))); + public function getUnitConvList($unit_type) { + return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=? and `is_delete`=?', 'vals' => array($unit_type, 0))); } - public function getUserConv($uid, $unit_id) { - return $this->obj->select($this->user_conv, array('sql' => '`uid`=? and `unit_id`=?', 'vals' => array($uid, $unit_id))); + public function getUserConv($uid, $unit_type) { + return $this->obj->select($this->user_conv, array('sql' => '`uid`=? and `unit_type`=?', 'vals' => array($uid, $unit_type))); } - public function saveUserConv($uid, $unit_id, $conv_id) { - if (!$unit_id || !$conv_id) { + public function saveUserConv($uid, $unit_type, $conv_id) { + if (!$unit_type || !$conv_id) { $this->setError('参数错误'); return false; } - $user_conv = $this->getUserConv($uid, $unit_id); + $user_conv = $this->getUserConv($uid, $unit_type); if ($user_conv) { $res = $this->updateUserConv($user_conv['id'], array('conv_id' => $conv_id)); if (!$res) { @@ -674,7 +668,7 @@ class mFormula extends mBase { return true; } - $res = $this->insertUserConv(array('uid' => $uid, 'unit_id' => $unit_id, 'conv_id' => $conv_id)); + $res = $this->insertUserConv(array('uid' => $uid, 'unit_type' => $unit_type, 'conv_id' => $conv_id)); if (!$res) { $this->setError('设置失败'); return false;