|
|
@ -12,6 +12,9 @@ class mFormula extends mBase { |
|
|
|
private $herb_tbl; |
|
|
|
private $collect_log_tbl; |
|
|
|
private $formula_use_log_tbl; |
|
|
|
private $unit_list; |
|
|
|
private $unit_conv; |
|
|
|
private $user_conv; |
|
|
|
|
|
|
|
public function __construct() { |
|
|
|
$this->obj = new dFormula(); |
|
|
@ -20,6 +23,9 @@ 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_list = 'tcm_unit_list'; |
|
|
|
$this->unit_conv = 'tcm_unit_conv'; |
|
|
|
$this->user_conv = 'tcm_user_conv'; |
|
|
|
} |
|
|
|
|
|
|
|
public function searchFormulaList($condition, $page_num, $page_size) { |
|
|
@ -59,6 +65,9 @@ class mFormula extends mBase { |
|
|
|
|
|
|
|
foreach ($da['formula'] as &$v) { |
|
|
|
if (isset($original[$v['name']])) { |
|
|
|
$num = $this->convByUserChoice($uid, $original[$v['name']]['num']); |
|
|
|
if ($num) $v['num'] = $num; |
|
|
|
|
|
|
|
$v['num_str'] = $original[$v['name']]['num']; |
|
|
|
$v['desc'] = $original[$v['name']]['desc']; |
|
|
|
} |
|
|
@ -70,6 +79,25 @@ class mFormula extends mBase { |
|
|
|
return $data; |
|
|
|
} |
|
|
|
|
|
|
|
public function convByUserChoice($uid, $num_str) { |
|
|
|
$unit_name = preg_replace('/\d/', '', $num_str); |
|
|
|
$unit = $this->getUnitByName($unit_name); |
|
|
|
if (!$unit) return false; |
|
|
|
|
|
|
|
$user_conv = $this->getUserConv($uid, $unit['id']); |
|
|
|
if (!$user_conv) return false; |
|
|
|
|
|
|
|
$unit_conv = $this->getUnitConvById($user_conv['conv_id']); |
|
|
|
if (!$unit_conv) return false; |
|
|
|
|
|
|
|
$unit_num = filter_var($num_str, FILTER_SANITIZE_NUMBER_INT); |
|
|
|
|
|
|
|
$num = $unit_num * $unit_conv['num']; |
|
|
|
if (!$num) return false; |
|
|
|
|
|
|
|
return $num; |
|
|
|
} |
|
|
|
|
|
|
|
public function searchFormulaTotal($condition) { |
|
|
|
$where = "1=1"; |
|
|
|
if (!empty($condition)) { |
|
|
@ -266,6 +294,9 @@ class mFormula extends mBase { |
|
|
|
$original = array_column($original, null, 'name'); |
|
|
|
foreach ($formulaHerb as &$v) { |
|
|
|
if (isset($original[$v['name']])) { |
|
|
|
$num = $this->convByUserChoice($uid, $original[$v['name']]['num']); |
|
|
|
if ($num) $v['num'] = $num; |
|
|
|
|
|
|
|
$v['num_str'] = $original[$v['name']]['num']; |
|
|
|
$v['desc'] = $original[$v['name']]['desc']; |
|
|
|
} |
|
|
@ -611,4 +642,63 @@ class mFormula extends mBase { |
|
|
|
return $this->obj->count($this->collect_log_tbl); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUnitByName($name) { |
|
|
|
return $this->obj->select($this->unit_list, array('sql' => '`name`=?', 'vals' => array($name))); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUnitConvById($id) { |
|
|
|
return $this->obj->select($this->unit_conv, array('sql' => '`id`=? and `is_delete`=?', 'vals' => array($id, 0))); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUnitConvList($unit_id) { |
|
|
|
return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_id`=? and `is_delete`=?', 'vals' => array($unit_id, 0))); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUserConv($uid, $unit_id) { |
|
|
|
return $this->obj->select($this->user_conv, array('sql' => '`uid`=? and `unit_id`=?', 'vals' => array($uid, $unit_id))); |
|
|
|
} |
|
|
|
|
|
|
|
public function saveUserConv($uid, $unit_id, $conv_id) { |
|
|
|
if (!$unit_id || !$conv_id) { |
|
|
|
$this->setError('参数错误'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
$user_conv = $this->getUserConv($uid, $unit_id); |
|
|
|
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_id' => $unit_id, '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; |
|
|
|
} |
|
|
|
} |