- 药方列表
- 添加药方 {if $data.id} @@ -112,7 +117,7 @@
diff --git a/config/define.php b/config/define.php index 70c30cc..7fb8da2 100644 --- a/config/define.php +++ b/config/define.php @@ -77,6 +77,13 @@ ) ); + define('WEIGHT_LIANG', 1); + define('WEIGHT_SHENG', 2); + $GLOBALS['weight_convert_list'] = array( + WEIGHT_LIANG => '两', + WEIGHT_SHENG => '升', + ); + $GLOBALS['weight_list'] = array( "汉" => array( '少许'=>'', diff --git a/control/admin.php b/control/admin.php index ce38146..7bac4f5 100644 --- a/control/admin.php +++ b/control/admin.php @@ -22,6 +22,13 @@ class admin extends publicBase { } } + public function logout() { + setcookie("uid", '', time() + 3600 * 24, '/'); + setcookie("token", '', time() + 3600 * 24, '/'); + + header('Location: /admin/login'); + } + public function user_list() { $m_admin_user = new mAdminUser(); $list = $m_admin_user->getUserList(); @@ -32,8 +39,6 @@ class admin extends publicBase { public function user_add() {} public function ajax_save_user() { - $this->_check_login(true); - $name = trim($this->post('name')); $password = md5('123456'); @@ -166,4 +171,53 @@ class admin extends publicBase { $this->ajax_json(true, '操作成功'); } + + public function unit_conv() { + $this->view['unit_list'] = $GLOBALS['weight_convert_list']; + + $unit_type = trim($this->get('unit_type')) + 0; + + $m_formula = new mFormula(); + $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( + 'status' => $this->post('status') + 0 + ); + + $m_formula = new mFormula(); + $id = $m_formula->updateUnitConv($id, $data); + if (!$id) $this->ajax_json(false, '操作失败'); + + $this->ajax_json(true, '操作成功'); + } + + public function unit_conv_add() { + $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() { + $id = $this->post('id') + 0; + $unit_type = trim($this->post('unit_type')) + 0; + $num = trim($this->post('num')) + 0; + $from = trim($this->post('from')); + + $m_formula = new mFormula(); + $id = $m_formula->saveUnitConv($id, $unit_type, $num, $from); + if (!$id) $this->ajax_json(false, $m_formula->getError()); + + $this->ajax_json(true, '操作成功', array('id' => $id)); + } } diff --git a/control/index.php b/control/index.php index c1639f1..b167785 100644 --- a/control/index.php +++ b/control/index.php @@ -327,4 +327,37 @@ class index extends publicBase { $this->view['data'] = array($data); $this->setViewTpl('index/export_pdf.html'); } + + public function ajax_unit_conv() { + $uinfo = $this->_check_login(); + + $unit_type = WEIGHT_LIANG; + $unit_name = $GLOBALS['weight_convert_list'][$unit_type]; + + $m_formula = new mFormula(); + $unit_conv = $m_formula->getUnitTypeConv($unit_type); + + $user_conv = $m_formula->getUserConv($uinfo['uid'], $unit_type); + foreach ($unit_conv as &$conv) { + $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"; + } + } + + $this->ajax_json(true, '获取成功', array('user_conv' => $user_conv, 'unit_conv' => $unit_conv)); + } + + public function ajax_set_user_conv() { + $uinfo = $this->_check_login(); + + $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_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 bcbf2dd..a3421be 100644 --- a/data/dFormula.php +++ b/data/dFormula.php @@ -44,6 +44,20 @@ class dFormula extends dBase { 'formula_id', 'use_num', ), + 'tcm_unit_conv' => array( + 'id', + 'unit_type', + 'num', + 'from', + 'status', + 'create_date', + ), + 'tcm_user_conv' => array( + 'id', + 'uid', + 'unit_type', + 'conv_id', + ), ); protected $primary_keys = array( @@ -52,6 +66,8 @@ class dFormula extends dBase { 'tcm_herb' => 'id', 'tcm_collect_log' => 'id', 'tcm_formula_use_log' => 'id', + 'tcm_unit_conv' => 'id', + 'tcm_user_conv' => 'id', ); } diff --git a/index.php b/index.php index 6787a76..82aef90 100644 --- a/index.php +++ b/index.php @@ -129,7 +129,7 @@ if ($is_super && $uinfo['is_super'] != 1) $this->ajax_json(false, '你没有该权限'); - $this->para['_uinfo'] = $uinfo; + $this->view['_uinfo'] = $this->para['_uinfo'] = $uinfo; return true; } diff --git a/model/mFormula.php b/model/mFormula.php index f994194..4d5306a 100644 --- a/model/mFormula.php +++ b/model/mFormula.php @@ -12,6 +12,8 @@ class mFormula extends mBase { private $herb_tbl; private $collect_log_tbl; private $formula_use_log_tbl; + private $unit_conv; + private $user_conv; public function __construct() { $this->obj = new dFormula(); @@ -20,6 +22,8 @@ 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_conv = 'tcm_unit_conv'; + $this->user_conv = 'tcm_user_conv'; } public function searchFormulaList($condition, $page_num, $page_size) { @@ -49,6 +53,16 @@ class mFormula extends mBase { $formula_ids = array_column($data, 'id'); $formula_arr = $this->getFormulaHerbData($formula_ids); + $unit_conv = array(); + $user_conv = $this->getUserConvList($uid); + if ($user_conv) { + $conv_ids = array_column($user_conv, 'conv_id'); + if ($conv_ids) { + $unit_conv = $this->getUnitConvByIds($conv_ids); + $unit_conv = array_column($unit_conv, null, 'unit_type'); + } + } + foreach ($data as &$da) { if (isset($formula_arr[$da['id']])) $da['formula'] = $formula_arr[$da['id']]; @@ -59,6 +73,9 @@ class mFormula extends mBase { foreach ($da['formula'] as &$v) { if (isset($original[$v['name']])) { + $num = $this->convByUserChoice($original[$v['name']]['num'], $unit_conv); + if ($num) $v['num'] = $num; + $v['num_str'] = $original[$v['name']]['num']; $v['desc'] = $original[$v['name']]['desc']; } @@ -70,6 +87,24 @@ class mFormula extends mBase { return $data; } + public function convByUserChoice($num_str, $unit_conv) { + if (!$unit_conv) return false; + + $unit_name = preg_replace('/\d/', '', $num_str); + + $unit_type = array_search($unit_name, $GLOBALS['weight_convert_list']); + if (!$unit_type) return false; + if (!isset($unit_conv[$unit_type])) return false; + + $unit_num = filter_var($num_str, FILTER_SANITIZE_NUMBER_INT); + $conv_num = $unit_conv[$unit_type]['num']; + + $num = $unit_num * $conv_num; + if (!$num) return false; + + return $num; + } + public function searchFormulaTotal($condition) { $where = "1=1"; if (!empty($condition)) { @@ -261,11 +296,24 @@ class mFormula extends mBase { return $formula; } + $unit_conv = array(); + $user_conv = $this->getUserConvList($uid); + if ($user_conv) { + $conv_ids = array_column($user_conv, 'conv_id'); + if ($conv_ids) { + $unit_conv = $this->getUnitConvByIds($conv_ids); + $unit_conv = array_column($unit_conv, null, 'unit_type'); + } + } + //原方信息 $original = json_decode($original, true); $original = array_column($original, null, 'name'); foreach ($formulaHerb as &$v) { if (isset($original[$v['name']])) { + $num = $this->convByUserChoice($original[$v['name']]['num'], $unit_conv); + if ($num) $v['num'] = $num; + $v['num_str'] = $original[$v['name']]['num']; $v['desc'] = $original[$v['name']]['desc']; } @@ -611,4 +659,135 @@ class mFormula extends mBase { return $this->obj->count($this->collect_log_tbl); } + public function getUnitConvByIds($ids) { + 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`=?', 'vals' => array($id))); + } + + public function getUnitTypeConv($unit_type) { + return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=? and `status`=?', 'vals' => array($unit_type, 0))); + } + + 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) { + return $this->obj->update($this->unit_conv, $info, array('sql' => '`id`=?', 'vals' => array($id))); + } + + public function insertUnitConv($info) { + $id = $this->obj->insert($this->unit_conv, $info); + if (empty($id)) { + $this->writeLog('formula', 'save_error_log', '添加计量单位转换失败|' . json_encode($info, JSON_UNESCAPED_UNICODE)); + return false; + } + + return $id; + } + + public function saveUnitConv($id, $unit_type, $num, $from) { + if (!$unit_type) { + $this->setError('请选择计量单位'); + return false; + } + if (!$num) { + $this->setError('请填写转换克重'); + return false; + } + if (empty($from)) { + $this->setError('请填写转换根据'); + return false; + } + + $data = array( + 'unit_type' => $unit_type, + 'num' => $num, + 'from' => $from, + 'status' => 1, + ); + + if (!$id) { + //添加药方 并添加药方药材关联关系 + $id = $this->insertUnitConv($data); + if (!$id) { + $this->setError('添加失败'); + return false; + } + + } else { + //更新药方 并更新药方药材关联关系 + $res = $this->updateUnitConv($id, $data); + if (!$res) { + $this->setError('更新失败'); + return false; + } + } + + return $id; + } + + public function getUserConvList($uid) { + return $this->obj->selectAll($this->user_conv, array('sql' => '`uid`=?', 'vals' => array($uid))); + } + + 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_type, $conv_id) { + if (!$unit_type || !$conv_id) { + $this->setError('参数错误'); + return false; + } + + $user_conv = $this->getUserConv($uid, $unit_type); + if ($user_conv) { + $res = $this->updateUserConv($user_conv['id'], array('conv_id' => $conv_id)); + if (!$res) { + $this->setError('更新失败'); + return false; + } + return true; + } + + $res = $this->insertUserConv(array('uid' => $uid, 'unit_type' => $unit_type, 'conv_id' => $conv_id)); + if (!$res) { + $this->setError('设置失败'); + return false; + } + return true; + } + + public function updateUserConv($id, $info) { + $res = $this->obj->update($this->user_conv, $info, array('sql' => '`id`=?', 'vals' => array($id))); + if (!$res) { + $this->writeLog('formula', 'save_error_log', '更新用户计量单位转换设置失败|' . $id . '|' . json_encode($info, JSON_UNESCAPED_UNICODE)); + return false; + } + + return true; + } + + public function insertUserConv($info) { + $res = $this->obj->insert($this->user_conv, $info); + if (!$res) { + $this->writeLog('formula', 'save_error_log', '添加用户计量单位转换设置失败|' . json_encode($info)); + return false; + } + + return true; + } } \ No newline at end of file diff --git a/model/mPage.php b/model/mPage.php index 908a653..85d8a8d 100644 --- a/model/mPage.php +++ b/model/mPage.php @@ -5,7 +5,7 @@ class Page extends publicBase { public $totalnum; // 总记录数[必填],例:$page->setTotalnum(100); public $page; // 当前页码[必填] public $url; // 分页URL[必填] - public $pagesize=50; // 每页记录数 + public $pagesize=20; // 每页记录数 public $viewpagenum=7; // 每页看到的页码数 public $virtualpage='...'; // 省略或跨越页码 diff --git a/view/css/global.css b/view/css/global.css index a19c636..55c0510 100644 --- a/view/css/global.css +++ b/view/css/global.css @@ -3568,7 +3568,8 @@ body{ display: block; text-indent:-9999px; margin: 6px 57px 0 0; - background:url('/agentsite/0.png') no-repeat; + background:url('../images/index_logo.png') no-repeat; + background-size: 80%; } .topbar-inner-logo { @@ -6073,7 +6074,7 @@ table { border-radius: 0 0 4px 0; } .table-striped tbody tr:nth-child(odd) td, .table-striped tbody tr:nth-child(odd) th { - background-color: #f9f9f9; + /*background-color: #f9f9f9;*/ } .table tbody tr:hover td, .table tbody tr:hover th { background-color: #f5f5f5; @@ -6990,4 +6991,19 @@ button.danger:hover{ text-shadow: none; border-color: #d9534f; background-position: 0 -10px; +} + +/* 提示框的样式 */ +.custom-alert { + position: fixed; + top: 30%; + right: 50%; + background-color: #787878; + color: white; + padding: 15px; + border-radius: 5px; + z-index: 1000; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + opacity: 1; + transition: opacity 0.5s ease; } \ No newline at end of file diff --git a/view/images/index_logo.png b/view/images/index_logo.png new file mode 100644 index 0000000..efe20f6 Binary files /dev/null and b/view/images/index_logo.png differ diff --git a/view/js/common.js b/view/js/common.js new file mode 100644 index 0000000..318693a --- /dev/null +++ b/view/js/common.js @@ -0,0 +1,18 @@ +function showAlert(text,href = ""){ + // 创建提示框元素 + var $alertBox = $('