diff --git a/control/index.php b/control/index.php index 419bd86..3ff678d 100644 --- a/control/index.php +++ b/control/index.php @@ -10,6 +10,7 @@ include_once(SERVER_ROOT . "/model/mPage.php"); class index extends publicBase { private function _check_login() { +// return array('uid'=>$this->post('uid')); $uid = $this->post('uid'); $token = $this->post('token'); if ($uid < 0 || !$token) $this->ajax_json(false, '参数错误', array('code' => CODE_LOGIN_EXIPRE)); @@ -98,6 +99,7 @@ class index extends publicBase { $uinfo = $this->_check_login(); $id = $this->post('id') + 0; + $is_delete = $this->post('is_delete') + 0; $name = trim($this->post('name')); $source = trim($this->post('source')); $method = trim($this->post('method')); @@ -111,27 +113,39 @@ class index extends publicBase { if (!$request_times) $this->ajax_json(false, $mformula->getError()); //新增药方 - $id = $mformula->formula($uinfo['uid'], $id, $name, $source, $method, $herbs); + $id = $mformula->formula($uinfo['uid'], $id, $name, $source, $method, $herbs, $is_delete); if (!$id) $this->ajax_json(false, $mformula->getError()); - $this->ajax_json(true, '成功', array('id' => $id)); + $this->ajax_json(true, '请求成功', array('id' => $id)); } -// public function ajax_update_formula() { -// $uinfo = $this->_check_login(); -// -// $id = $this->post('id') + 0; -// $name = trim($this->post('name')); -// $source = trim($this->post('source')); -// $method = trim($this->post('method')); -// $herbs = $this->post('herbs'); -// -// $mformula = new mFormula(); -// $res = $mformula->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs); -// if (!$res) $this->ajax_json(false, $mformula->getError()); -// -// $this->ajax_json(true, '保存成功'); -// } + public function ajax_delete_formula() { + $uinfo = $this->_check_login(); + + $id = $this->post('id') + 0; + + $mformula = new mFormula(); + $id = $mformula->deleteFormula($uinfo['uid'], $id); + if (!$id) $this->ajax_json(false, $mformula->getError()); + + $this->ajax_json(true, '请求成功'); + } + + // public function ajax_update_formula() { + // $uinfo = $this->_check_login(); + // + // $id = $this->post('id') + 0; + // $name = trim($this->post('name')); + // $source = trim($this->post('source')); + // $method = trim($this->post('method')); + // $herbs = $this->post('herbs'); + // + // $mformula = new mFormula(); + // $res = $mformula->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs); + // if (!$res) $this->ajax_json(false, $mformula->getError()); + // + // $this->ajax_json(true, '保存成功'); + // } public function ajax_user_formula() { $uinfo = $this->_check_login(); diff --git a/data/dFormula.php b/data/dFormula.php index a4fc475..bcbf2dd 100644 --- a/data/dFormula.php +++ b/data/dFormula.php @@ -17,6 +17,7 @@ class dFormula extends dBase { 'original', 'method', 'sort', + 'is_delete', 'create_time', ), 'tcm_formula_herb' => array( diff --git a/model/mFormula.php b/model/mFormula.php index c01fca8..987e98f 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 = "1=1"; + $where = "is_delete=0"; $use_limit = ""; if (!empty($condition)) { foreach ($condition as $key => $val) { @@ -82,7 +82,7 @@ class mFormula extends mBase { } public function getFormulaTotal($condition) { - $where = "1=1"; + $where = "is_delete=0"; if (!empty($condition)) { foreach ($condition as $key => $val) { if ($key == 'name') { @@ -511,7 +511,7 @@ class mFormula extends mBase { $this->setError('查询不到此药方'); return false; } - if ($formula['uid'] > 0 && $formula['uid'] != $uid) { + if ($formula['uid'] != $uid) { $this->setError('这不是你的药方'); return false; } @@ -585,6 +585,25 @@ class mFormula extends mBase { return $id; } + public function deleteFormula($uid, $id) { + $formula = $this->getFormulaById($id); + if (empty($formula)) { + $this->setError('查询不到此药方'); + return false; + } + if ($formula['uid'] != $uid) { + $this->setError('这不是你的药方'); + return false; + } + + $res = $this->updateFormula($id, array('is_delete' => 1)); + if (!$res) { + $this->writeLog('formula', 'update_error_log', '更新药方失败|' . $uid . '|' . json_encode($data, JSON_UNESCAPED_UNICODE)); + return false; + } + + return true; + } public function getHerbById($id) { return $this->obj->select($this->herb_tbl, array('sql' => '`id`=?', 'vals' => array($id)));