From 73efbbd3288e794c256541b1569c4dab8efe368e Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Wed, 16 Oct 2024 13:55:04 +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 | 4 +++- control/admin.php | 19 ++++++++++++++----- control/index.php | 4 ++-- data/dFormula.php | 2 +- model/mFormula.php | 23 ++++++++++++++++------- view/templates/admin/unit_conv.html | 12 +++++++----- view/templates/admin/unit_conv_add.html | 2 +- 7 files changed, 44 insertions(+), 22 deletions(-) diff --git a/config/define.php b/config/define.php index e4f41e1..7fb8da2 100644 --- a/config/define.php +++ b/config/define.php @@ -78,8 +78,10 @@ ); define('WEIGHT_LIANG', 1); + define('WEIGHT_SHENG', 2); $GLOBALS['weight_convert_list'] = array( - '两'=> WEIGHT_LIANG, + WEIGHT_LIANG => '两', + WEIGHT_SHENG => '升', ); $GLOBALS['weight_list'] = array( diff --git a/control/admin.php b/control/admin.php index b50c575..7bac4f5 100644 --- a/control/admin.php +++ b/control/admin.php @@ -173,19 +173,20 @@ class admin extends publicBase { } public function unit_conv() { - $this->view['unit_list'] = array_flip($GLOBALS['weight_convert_list']); + $this->view['unit_list'] = $GLOBALS['weight_convert_list']; $unit_type = trim($this->get('unit_type')) + 0; - if (!$unit_type) $unit_type = 1; $m_formula = new mFormula(); - $this->view['list'] = $m_formula->getUnitConvList($unit_type); + $condition = array(); + if ($unit_type) $condition['unit_type'] = $unit_type; + $this->view['list'] = $m_formula->getUnitConvList($condition); } public function ajax_change_unit_conv() { $id = $this->post('id') + 0; $data = array( - 'is_delete' => $this->post('is_delete') + 0 + 'status' => $this->post('status') + 0 ); $m_formula = new mFormula(); @@ -196,7 +197,15 @@ class admin extends publicBase { } public function unit_conv_add() { - $this->view['unit_list'] = array_flip($GLOBALS['weight_convert_list']); + $this->view['unit_list'] = $GLOBALS['weight_convert_list']; + + $id = $this->get('id'); + if ($id) { + $mformula = new mFormula(); + $data = $mformula->getUnitConvById($id); + + $this->view['data'] = $data; + } } public function ajax_save_unit_conv() { diff --git a/control/index.php b/control/index.php index 7a9e160..b167785 100644 --- a/control/index.php +++ b/control/index.php @@ -331,8 +331,8 @@ class index extends publicBase { public function ajax_unit_conv() { $uinfo = $this->_check_login(); - $unit_name = '两'; - $unit_type = $GLOBALS['weight_convert_list'][$unit_name]; + $unit_type = WEIGHT_LIANG; + $unit_name = $GLOBALS['weight_convert_list'][$unit_type]; $m_formula = new mFormula(); $unit_conv = $m_formula->getUnitTypeConv($unit_type); diff --git a/data/dFormula.php b/data/dFormula.php index d01d7d9..a3421be 100644 --- a/data/dFormula.php +++ b/data/dFormula.php @@ -49,7 +49,7 @@ class dFormula extends dBase { 'unit_type', 'num', 'from', - 'is_delete', + 'status', 'create_date', ), 'tcm_user_conv' => array( diff --git a/model/mFormula.php b/model/mFormula.php index a743a29..4d5306a 100644 --- a/model/mFormula.php +++ b/model/mFormula.php @@ -92,7 +92,7 @@ class mFormula extends mBase { $unit_name = preg_replace('/\d/', '', $num_str); - $unit_type = $GLOBALS['weight_convert_list'][$unit_name]; + $unit_type = array_search($unit_name, $GLOBALS['weight_convert_list']); if (!$unit_type) return false; if (!isset($unit_conv[$unit_type])) return false; @@ -660,19 +660,28 @@ class mFormula extends mBase { } public function getUnitConvByIds($ids) { - return $this->obj->selectIn($this->unit_conv, array('id' => $ids), array('sql' => '`is_delete`=?', 'vals' => array(0))); + return $this->obj->selectIn($this->unit_conv, array('id' => $ids), array('sql' => '`status`=?', 'vals' => array(0))); } public function getUnitConvById($id) { - return $this->obj->select($this->unit_conv, array('sql' => '`id`=? and `is_delete`=?', 'vals' => array($id, 0))); + return $this->obj->select($this->unit_conv, array('sql' => '`id`=?', 'vals' => array($id))); } public function getUnitTypeConv($unit_type) { - return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=? and `is_delete`=?', 'vals' => array($unit_type, 0))); + return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=? and `status`=?', 'vals' => array($unit_type, 0))); } - public function getUnitConvList($unit_type) { - return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=?', 'vals' => array($unit_type))); + public function getUnitConvList($condition, $page_num = 1, $page_size = 500) { + $offset = ($page_num - 1) * $page_size; + + $where = "1=1 "; + if (!empty($condition)) { + foreach ($condition as $key => $val) { + $where .= " and {$key}={$val}"; + } + } + + return $this->obj->selectAll($this->unit_conv, array('sql' => $where, 'vals' => array()), 'id desc ', array($offset, $page_size)); } public function updateUnitConv($id, $info) { @@ -707,7 +716,7 @@ class mFormula extends mBase { 'unit_type' => $unit_type, 'num' => $num, 'from' => $from, - 'is_delete' => 1, + 'status' => 1, ); if (!$id) { diff --git a/view/templates/admin/unit_conv.html b/view/templates/admin/unit_conv.html index b18b1f7..5d4f203 100644 --- a/view/templates/admin/unit_conv.html +++ b/view/templates/admin/unit_conv.html @@ -30,8 +30,9 @@