Browse Source

删除自拟药方

pull/1/head
pengda 8 months ago
parent
commit
e7696a588a
  1. 48
      control/index.php
  2. 1
      data/dFormula.php
  3. 25
      model/mFormula.php

48
control/index.php

@ -10,6 +10,7 @@ include_once(SERVER_ROOT . "/model/mPage.php");
class index extends publicBase { class index extends publicBase {
private function _check_login() { private function _check_login() {
// return array('uid'=>$this->post('uid'));
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
if ($uid < 0 || !$token) $this->ajax_json(false, '参数错误', array('code' => CODE_LOGIN_EXIPRE)); 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(); $uinfo = $this->_check_login();
$id = $this->post('id') + 0; $id = $this->post('id') + 0;
$is_delete = $this->post('is_delete') + 0;
$name = trim($this->post('name')); $name = trim($this->post('name'));
$source = trim($this->post('source')); $source = trim($this->post('source'));
$method = trim($this->post('method')); $method = trim($this->post('method'));
@ -111,27 +113,39 @@ class index extends publicBase {
if (!$request_times) $this->ajax_json(false, $mformula->getError()); 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()); 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() { public function ajax_delete_formula() {
// $uinfo = $this->_check_login(); $uinfo = $this->_check_login();
//
// $id = $this->post('id') + 0; $id = $this->post('id') + 0;
// $name = trim($this->post('name'));
// $source = trim($this->post('source')); $mformula = new mFormula();
// $method = trim($this->post('method')); $id = $mformula->deleteFormula($uinfo['uid'], $id);
// $herbs = $this->post('herbs'); if (!$id) $this->ajax_json(false, $mformula->getError());
//
// $mformula = new mFormula(); $this->ajax_json(true, '请求成功');
// $res = $mformula->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs); }
// if (!$res) $this->ajax_json(false, $mformula->getError());
// // public function ajax_update_formula() {
// $this->ajax_json(true, '保存成功'); // $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() { public function ajax_user_formula() {
$uinfo = $this->_check_login(); $uinfo = $this->_check_login();

1
data/dFormula.php

@ -17,6 +17,7 @@ class dFormula extends dBase {
'original', 'original',
'method', 'method',
'sort', 'sort',
'is_delete',
'create_time', 'create_time',
), ),
'tcm_formula_herb' => array( 'tcm_formula_herb' => array(

25
model/mFormula.php

@ -25,7 +25,7 @@ class mFormula extends mBase {
public function getFormulaByCondition($condition, $page_num, $page_size) { public function getFormulaByCondition($condition, $page_num, $page_size) {
$offset = ($page_num - 1) * $page_size; $offset = ($page_num - 1) * $page_size;
$where = "1=1"; $where = "is_delete=0";
$use_limit = ""; $use_limit = "";
if (!empty($condition)) { if (!empty($condition)) {
foreach ($condition as $key => $val) { foreach ($condition as $key => $val) {
@ -82,7 +82,7 @@ class mFormula extends mBase {
} }
public function getFormulaTotal($condition) { public function getFormulaTotal($condition) {
$where = "1=1"; $where = "is_delete=0";
if (!empty($condition)) { if (!empty($condition)) {
foreach ($condition as $key => $val) { foreach ($condition as $key => $val) {
if ($key == 'name') { if ($key == 'name') {
@ -511,7 +511,7 @@ class mFormula extends mBase {
$this->setError('查询不到此药方'); $this->setError('查询不到此药方');
return false; return false;
} }
if ($formula['uid'] > 0 && $formula['uid'] != $uid) { if ($formula['uid'] != $uid) {
$this->setError('这不是你的药方'); $this->setError('这不是你的药方');
return false; return false;
} }
@ -585,6 +585,25 @@ class mFormula extends mBase {
return $id; 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) { public function getHerbById($id) {
return $this->obj->select($this->herb_tbl, array('sql' => '`id`=?', 'vals' => array($id))); return $this->obj->select($this->herb_tbl, array('sql' => '`id`=?', 'vals' => array($id)));

Loading…
Cancel
Save