Browse Source

增加药材说明

pull/6/head
pengda 8 months ago
parent
commit
59fce2bf8d
  1. 8
      control/index.php
  2. 140
      model/mFormula.php
  3. 4
      view/templates/admin/formula_add.html
  4. 4
      view/templates/admin/formula_list.html

8
control/index.php

@ -79,7 +79,7 @@ class index extends publicBase {
if ($content) $condition['name'] = $content; if ($content) $condition['name'] = $content;
$mformula = new mFormula(); $mformula = new mFormula();
$list = $mformula->getFormulaList($condition, $page_num, $page_size); $list = $mformula->getUserFormulaList($condition, $page_num, $page_size);
$total = $mformula->getFormulaTotal($condition); $total = $mformula->getFormulaTotal($condition);
$rdata = array( $rdata = array(
@ -116,13 +116,13 @@ class index extends publicBase {
$page_size = $this->post('page_size') ? $this->post('page_size') : 20; $page_size = $this->post('page_size') ? $this->post('page_size') : 20;
$condition = array(); $condition = array();
$condition['uid'] = array(0, $uinfo['uid']); $condition['uid'] = $uinfo['uid'];
$condition['is_delete'] = 0; $condition['is_delete'] = 0;
if ($content) $condition['name'] = $content; if ($content) $condition['name'] = $content;
$mformula = new mFormula(); $mformula = new mFormula();
$list = $mformula->getFormulaList($condition, $page_num, $page_size); $list = $mformula->searchFormulaList($condition, $page_num, $page_size);
$total = $mformula->getFormulaTotal($condition); $total = $mformula->searchFormulaTotal($condition);
$rdata = array( $rdata = array(
'total' => $total, 'total' => $total,

140
model/mFormula.php

@ -22,36 +22,142 @@ class mFormula extends mBase {
$this->formula_use_log_tbl = 'tcm_formula_use_log'; $this->formula_use_log_tbl = 'tcm_formula_use_log';
} }
public function getFormulaByCondition($condition, $page_num, $page_size) { public function searchFormulaList($condition, $page_num, $page_size) {
$offset = ($page_num - 1) * $page_size; $offset = ($page_num - 1) * $page_size;
$uid = 0;
$where = "1=1"; $where = "1=1";
$use_limit = "";
if (!empty($condition)) { if (!empty($condition)) {
foreach ($condition as $key => $val) { foreach ($condition as $key => $val) {
if ($key == 'name') { if ($key == 'name') {
$where .= " and s.{$key} like '%{$val}%'"; $where .= " and s.{$key} like '%{$val}%'";
} elseif ($key == 'uid' && is_array($val)) { } elseif ($key == 'uid') {
$uid = $val;
$where .= " and s.{$key} in (0,{$val})";
} elseif (is_array($val)) {
$val = implode(',', $val); $val = implode(',', $val);
$where .= " and s.{$key} in ({$val})"; $where .= " and s.{$key} in ({$val})";
} else {
$where .= " and s.{$key}={$val}";
}
}
}
$sql = "select s.*,COALESCE(u.use_num, 0) AS use_num from {$this->tbl} as s left join {$this->formula_use_log_tbl} as u on s.id=u.formula_id and u.uid={$uid} where {$where} group by s.id order by use_num desc,s.sort desc,s.id desc limit {$offset},{$page_size}";
$data = $this->obj->execute($sql, true, true);
$formula_ids = array_column($data, 'id');
$formula_arr = $this->getFormulaHerbData($formula_ids);
foreach ($data as &$da) {
if (isset($formula_arr[$da['id']])) $da['formula'] = $formula_arr[$da['id']];
//原方信息
if (!empty($da['original'])) {
$original = json_decode($da['original'], true);
$original = array_column($original, null, 'name');
foreach ($da['formula'] as &$v) {
if (isset($original[$v['name']])) {
$v['num_str'] = $original[$v['name']]['num'];
$v['desc'] = $original[$v['name']]['desc'];
}
}
}
unset($da['original']);
}
return $data;
}
//兼容查药方只计算当前用户对药方的使用次数 public function searchFormulaTotal($condition) {
$use_limit .= " and u.uid in ({$val})"; $where = "1=1";
} elseif ($key == 'is_delete' && is_array($val)) { if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'name') {
$where .= " and {$key} like '%{$val}%'";
} elseif ($key == 'uid') {
$where .= " and {$key} in (0,{$val})";
} elseif (is_array($val)) {
$val = implode(',', $val); $val = implode(',', $val);
$where .= " and {$key} in ({$val})"; $where .= " and {$key} in ({$val})";
} else { } else {
$where .= " and {$key}={$val}";
}
}
}
$sql = "select count(*) as count from $this->tbl where {$where}";
$res = $this->obj->execute($sql, true, true);
$num = $res[0]['count'];
return $num;
}
public function getUserFormulaList($condition, $page_num, $page_size) {
$offset = ($page_num - 1) * $page_size;
$uid = 0;
$where = "1=1";
if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'uid') $uid = $val;
if ($key == 'name') {
$where .= " and s.{$key} like '%{$val}%'";
} elseif (is_array($val)) {
$val = implode(',', $val);
$where .= " and s.{$key} in ({$val})";
} else {
$where .= " and s.{$key}={$val}"; $where .= " and s.{$key}={$val}";
} }
} }
} }
$sql = "select s.*,COALESCE(SUM(u.use_num), 0) AS use_num from {$this->tbl} as s left join {$this->formula_use_log_tbl} as u on s.id=u.formula_id {$use_limit} where {$where} group by s.id order by use_num desc,s.sort desc,s.id desc limit {$offset},{$page_size}"; $sql = "select s.*,COALESCE(u.use_num, 0) AS use_num from {$this->tbl} as s left join {$this->formula_use_log_tbl} as u on s.id=u.formula_id and u.uid={$uid} where {$where} group by s.id order by use_num desc,s.sort desc,s.id desc limit {$offset},{$page_size}";
return $this->obj->execute($sql, true, true); return $this->obj->execute($sql, true, true);
} }
public function getUserFormulaTotal($condition) {
$where = "1=1";
if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'name') {
$where .= " and {$key} like '%{$val}%'";
} elseif (is_array($val)) {
$val = implode(',', $val);
$where .= " and {$key} in ({$val})";
} else {
$where .= " and {$key}={$val}";
}
}
}
$sql = "select count(*) as count from $this->tbl where {$where}";
$res = $this->obj->execute($sql, true, true);
$num = $res[0]['count'];
return $num;
}
public function getFormulaList($condition, $page_num, $page_size) { public function getFormulaList($condition, $page_num, $page_size) {
$data = $this->getFormulaByCondition($condition, $page_num, $page_size); $offset = ($page_num - 1) * $page_size;
$where = "1=1 ";
if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'name') {
$where .= " and {$key} like '%{$val}%'";
} elseif (is_array($val)) {
$val = implode(',', $val);
$where .= " and {$key} in ({$val})";
} else {
$where .= " and {$key}={$val}";
}
}
}
$data = $this->obj->selectAll($this->tbl, array('sql' => $where, 'vals' => array()), 'id desc ', array($offset, $page_size));
$formula_ids = array_column($data, 'id'); $formula_ids = array_column($data, 'id');
$formula_arr = $this->getFormulaHerbData($formula_ids); $formula_arr = $this->getFormulaHerbData($formula_ids);
@ -67,7 +173,7 @@ class mFormula extends mBase {
foreach ($da['formula'] as &$v) { foreach ($da['formula'] as &$v) {
if (isset($original[$v['name']])) { if (isset($original[$v['name']])) {
$v['num_str'] = $original[$v['name']]['num']; $v['num_str'] = $original[$v['name']]['num'];
//$v['desc'] = $original[$v['name']]['desc']; $v['desc'] = $original[$v['name']]['desc'];
} }
} }
} }
@ -83,10 +189,7 @@ class mFormula extends mBase {
foreach ($condition as $key => $val) { foreach ($condition as $key => $val) {
if ($key == 'name') { if ($key == 'name') {
$where .= " and {$key} like '%{$val}%'"; $where .= " and {$key} like '%{$val}%'";
} elseif ($key == 'uid' && is_array($val)) { } elseif (is_array($val)) {
$val = implode(',', $val);
$where .= " and {$key} in ({$val})";
} elseif ($key == 'is_delete' && is_array($val)) {
$val = implode(',', $val); $val = implode(',', $val);
$where .= " and {$key} in ({$val})"; $where .= " and {$key} in ({$val})";
} else { } else {
@ -95,11 +198,7 @@ class mFormula extends mBase {
} }
} }
$sql = "select count(*) as count from $this->tbl where {$where}"; return $this->obj->count($this->tbl, array('sql' => $where, 'vals' => array()));
$res = $this->obj->execute($sql, true, true);
$num = $res[0]['count'];
return $num;
} }
public function getFormulaById($id) { public function getFormulaById($id) {
@ -168,7 +267,7 @@ class mFormula extends mBase {
foreach ($formulaHerb as &$v) { foreach ($formulaHerb as &$v) {
if (isset($original[$v['name']])) { if (isset($original[$v['name']])) {
$v['num_str'] = $original[$v['name']]['num']; $v['num_str'] = $original[$v['name']]['num'];
//$v['desc'] = $original[$v['name']]['desc']; $v['desc'] = $original[$v['name']]['desc'];
} }
} }
@ -246,6 +345,7 @@ class mFormula extends mBase {
foreach ($herbs as $key => $item) { foreach ($herbs as $key => $item) {
$name = trim($item['name']); $name = trim($item['name']);
$num = trim($item['num']); $num = trim($item['num']);
$desc = trim($item['desc']);
//自拟药方 克重不能为0 //自拟药方 克重不能为0
if ($uid > 0 && $num == 0) { if ($uid > 0 && $num == 0) {
@ -260,7 +360,7 @@ class mFormula extends mBase {
if ($herb) { if ($herb) {
$temp['herb_id'] = $herb['id']; $temp['herb_id'] = $herb['id'];
} else { } else {
$temp['herb_id'] = $this->insertHerb(array('uid' => $uid, 'name' => $name)); $temp['herb_id'] = $this->insertHerb(array('uid' => $uid, 'name' => $name, 'desc' => $desc));
if (!$temp['herb_id']) { if (!$temp['herb_id']) {
$this->setError('添加药材失败'); $this->setError('添加药材失败');
return false; return false;

4
view/templates/admin/formula_add.html

@ -69,11 +69,11 @@
<label>&nbsp;</label> <label>&nbsp;</label>
<div class="herb_input"> <div class="herb_input">
<input type="text" name="herb_name[]" value="{$item.name}" placeholder="药材名" required/> <input type="text" name="herb_name[]" value="{$item.name}" placeholder="药材名" required/>
<input type="text" name="herb_desc[]" value="{$item.desc}" placeholder="炮制方法"/>
<input type="text" name="herb_num[]" value="{$item.num_str}" <input type="text" name="herb_num[]" value="{$item.num_str}"
placeholder="用量" required/> placeholder="用量" required/>
<!-- /--> <!-- /-->
<!-- <input style="width: 80px" type="text" value="{$item.num}克" disabled/>--> <!-- <input style="width: 80px" type="text" value="{$item.num}克" disabled/>-->
<input type="text" name="herb_desc[]" value="{$item.desc}" placeholder="说明"/>
<button class="" type="button" onclick="removeIngredient(this)">X</button> <button class="" type="button" onclick="removeIngredient(this)">X</button>
</div> </div>
@ -121,8 +121,8 @@
<label>&nbsp;</label> <label>&nbsp;</label>
<div class="herb_input"> <div class="herb_input">
<input type="text" name="herb_name[]" placeholder="药材名" required /> <input type="text" name="herb_name[]" placeholder="药材名" required />
<input type="text" name="herb_desc[]" placeholder="炮制方法"/>
<input type="text" name="herb_num[]" placeholder="药量" required /> <input type="text" name="herb_num[]" placeholder="药量" required />
<input type="text" name="herb_desc[]" placeholder="说明"/>
<button class="" type="button" onclick="removeIngredient(this)">X</button> <button class="" type="button" onclick="removeIngredient(this)">X</button>
</div> </div>
`; `;

4
view/templates/admin/formula_list.html

@ -83,7 +83,6 @@
<th width="50">录方者uid</th> <th width="50">录方者uid</th>
<th width="200">药方名称</th> <th width="200">药方名称</th>
<th width="200">药方来源</th> <th width="200">药方来源</th>
<!-- <th width="50">使用次数</th>-->
<th width="200">药方详情</th> <th width="200">药方详情</th>
<th width="50">操作</th> <th width="50">操作</th>
</tr> </tr>
@ -95,10 +94,9 @@
<td>{if $item.uid eq 0}-{else}{$item.uid}{/if}</td> <td>{if $item.uid eq 0}-{else}{$item.uid}{/if}</td>
<td>{$item.name}</td> <td>{$item.name}</td>
<td>{$item.source}</td> <td>{$item.source}</td>
<!-- <td>{$item.use_num}</td>-->
<td style="display: flex;flex-wrap: wrap"> <td style="display: flex;flex-wrap: wrap">
{foreach from=$item.formula item=value} {foreach from=$item.formula item=value}
<span style="margin-right: 20px">{$value.name} {$value.num_str}</span> <span style="margin-right: 20px">{$value.name}{if $value.desc}({$value.desc}){/if} {$value.num_str}</span>
{/foreach} {/foreach}
</td> </td>

Loading…
Cancel
Save