Browse Source

Merge pull request 'wpd_bug' (#6) from wpd_bug into master

Reviewed-on: #6
pull/7/head
pengda 8 months ago
parent
commit
c8ac51bd5c
  1. 10
      control/index.php
  2. 142
      model/mFormula.php
  3. 4
      view/templates/admin/formula_add.html
  4. 4
      view/templates/admin/formula_list.html

10
control/index.php

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

142
model/mFormula.php

@ -22,36 +22,29 @@ class mFormula extends mBase {
$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;
$uid = 0;
$where = "1=1";
$use_limit = "";
if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'name') {
$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);
$where .= " and s.{$key} in ({$val})";
//兼容查药方只计算当前用户对药方的使用次数
$use_limit .= " and u.uid in ({$val})";
} elseif ($key == 'is_delete' && is_array($val)) {
$val = implode(',', $val);
$where .= " and {$key} in ({$val})";
} else {
$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}";
return $this->obj->execute($sql, true, true);
}
public function getFormulaList($condition, $page_num, $page_size) {
$data = $this->getFormulaByCondition($condition, $page_num, $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}";
$data = $this->obj->execute($sql, true, true);
$formula_ids = array_column($data, 'id');
$formula_arr = $this->getFormulaHerbData($formula_ids);
@ -67,7 +60,7 @@ class mFormula extends mBase {
foreach ($da['formula'] as &$v) {
if (isset($original[$v['name']])) {
$v['num_str'] = $original[$v['name']]['num'];
//$v['desc'] = $original[$v['name']]['desc'];
$v['desc'] = $original[$v['name']]['desc'];
}
}
}
@ -77,16 +70,61 @@ class mFormula extends mBase {
return $data;
}
public function getFormulaTotal($condition) {
public function searchFormulaTotal($condition) {
$where = "1=1";
if (!empty($condition)) {
foreach ($condition as $key => $val) {
if ($key == 'name') {
$where .= " and {$key} like '%{$val}%'";
} elseif ($key == 'uid' && is_array($val)) {
} elseif ($key == 'uid') {
$where .= " and {$key} in (0,{$val})";
} elseif (is_array($val)) {
$val = implode(',', $val);
$where .= " and {$key} in ({$val})";
} elseif ($key == 'is_delete' && is_array($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 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}";
}
}
}
$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);
}
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 {
@ -102,6 +140,67 @@ class mFormula extends mBase {
return $num;
}
public function getFormulaList($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_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 getFormulaTotal($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}";
}
}
}
return $this->obj->count($this->tbl, array('sql' => $where, 'vals' => array()));
}
public function getFormulaById($id) {
return $this->obj->select($this->tbl, array('sql' => '`id`=?', 'vals' => array($id)));
}
@ -168,7 +267,7 @@ class mFormula extends mBase {
foreach ($formulaHerb as &$v) {
if (isset($original[$v['name']])) {
$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) {
$name = trim($item['name']);
$num = trim($item['num']);
$desc = trim($item['desc']);
//自拟药方 克重不能为0
if ($uid > 0 && $num == 0) {
@ -260,7 +360,7 @@ class mFormula extends mBase {
if ($herb) {
$temp['herb_id'] = $herb['id'];
} 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']) {
$this->setError('添加药材失败');
return false;

4
view/templates/admin/formula_add.html

@ -69,11 +69,11 @@
<label>&nbsp;</label>
<div class="herb_input">
<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}"
placeholder="用量" required/>
<!-- /-->
<!-- <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>
</div>
@ -121,8 +121,8 @@
<label>&nbsp;</label>
<div class="herb_input">
<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_desc[]" placeholder="说明"/>
<button class="" type="button" onclick="removeIngredient(this)">X</button>
</div>
`;

4
view/templates/admin/formula_list.html

@ -83,7 +83,6 @@
<th width="50">录方者uid</th>
<th width="200">药方名称</th>
<th width="200">药方来源</th>
<!-- <th width="50">使用次数</th>-->
<th width="200">药方详情</th>
<th width="50">操作</th>
</tr>
@ -95,10 +94,9 @@
<td>{if $item.uid eq 0}-{else}{$item.uid}{/if}</td>
<td>{$item.name}</td>
<td>{$item.source}</td>
<!-- <td>{$item.use_num}</td>-->
<td style="display: flex;flex-wrap: wrap">
{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}
</td>

Loading…
Cancel
Save