|
@ -12,7 +12,6 @@ class mFormula extends mBase { |
|
|
private $herb_tbl; |
|
|
private $herb_tbl; |
|
|
private $collect_log_tbl; |
|
|
private $collect_log_tbl; |
|
|
private $formula_use_log_tbl; |
|
|
private $formula_use_log_tbl; |
|
|
private $unit_list; |
|
|
|
|
|
private $unit_conv; |
|
|
private $unit_conv; |
|
|
private $user_conv; |
|
|
private $user_conv; |
|
|
|
|
|
|
|
@ -23,7 +22,6 @@ class mFormula extends mBase { |
|
|
$this->herb_tbl = 'tcm_herb'; |
|
|
$this->herb_tbl = 'tcm_herb'; |
|
|
$this->collect_log_tbl = 'tcm_collect_log'; |
|
|
$this->collect_log_tbl = 'tcm_collect_log'; |
|
|
$this->formula_use_log_tbl = 'tcm_formula_use_log'; |
|
|
$this->formula_use_log_tbl = 'tcm_formula_use_log'; |
|
|
$this->unit_list = 'tcm_unit_list'; |
|
|
|
|
|
$this->unit_conv = 'tcm_unit_conv'; |
|
|
$this->unit_conv = 'tcm_unit_conv'; |
|
|
$this->user_conv = 'tcm_user_conv'; |
|
|
$this->user_conv = 'tcm_user_conv'; |
|
|
} |
|
|
} |
|
@ -81,10 +79,10 @@ class mFormula extends mBase { |
|
|
|
|
|
|
|
|
public function convByUserChoice($uid, $num_str) { |
|
|
public function convByUserChoice($uid, $num_str) { |
|
|
$unit_name = preg_replace('/\d/', '', $num_str); |
|
|
$unit_name = preg_replace('/\d/', '', $num_str); |
|
|
$unit = $this->getUnitByName($unit_name); |
|
|
$unit_type = $GLOBALS['weight_convert_list'][$unit_name]; |
|
|
if (!$unit) return false; |
|
|
if (!$unit_type) return false; |
|
|
|
|
|
|
|
|
$user_conv = $this->getUserConv($uid, $unit['id']); |
|
|
$user_conv = $this->getUserConv($uid, $unit_type); |
|
|
if (!$user_conv) return false; |
|
|
if (!$user_conv) return false; |
|
|
|
|
|
|
|
|
$unit_conv = $this->getUnitConvById($user_conv['conv_id']); |
|
|
$unit_conv = $this->getUnitConvById($user_conv['conv_id']); |
|
@ -642,29 +640,25 @@ class mFormula extends mBase { |
|
|
return $this->obj->count($this->collect_log_tbl); |
|
|
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) { |
|
|
public function getUnitConvById($id) { |
|
|
return $this->obj->select($this->unit_conv, array('sql' => '`id`=? and `is_delete`=?', 'vals' => array($id, 0))); |
|
|
return $this->obj->select($this->unit_conv, array('sql' => '`id`=? and `is_delete`=?', 'vals' => array($id, 0))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUnitConvList($unit_id) { |
|
|
public function getUnitConvList($unit_type) { |
|
|
return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_id`=? and `is_delete`=?', 'vals' => array($unit_id, 0))); |
|
|
return $this->obj->selectAll($this->unit_conv, array('sql' => '`unit_type`=? and `is_delete`=?', 'vals' => array($unit_type, 0))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getUserConv($uid, $unit_id) { |
|
|
public function getUserConv($uid, $unit_type) { |
|
|
return $this->obj->select($this->user_conv, array('sql' => '`uid`=? and `unit_id`=?', 'vals' => array($uid, $unit_id))); |
|
|
return $this->obj->select($this->user_conv, array('sql' => '`uid`=? and `unit_type`=?', 'vals' => array($uid, $unit_type))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function saveUserConv($uid, $unit_id, $conv_id) { |
|
|
public function saveUserConv($uid, $unit_type, $conv_id) { |
|
|
if (!$unit_id || !$conv_id) { |
|
|
if (!$unit_type || !$conv_id) { |
|
|
$this->setError('参数错误'); |
|
|
$this->setError('参数错误'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$user_conv = $this->getUserConv($uid, $unit_id); |
|
|
$user_conv = $this->getUserConv($uid, $unit_type); |
|
|
if ($user_conv) { |
|
|
if ($user_conv) { |
|
|
$res = $this->updateUserConv($user_conv['id'], array('conv_id' => $conv_id)); |
|
|
$res = $this->updateUserConv($user_conv['id'], array('conv_id' => $conv_id)); |
|
|
if (!$res) { |
|
|
if (!$res) { |
|
@ -674,7 +668,7 @@ class mFormula extends mBase { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$res = $this->insertUserConv(array('uid' => $uid, 'unit_id' => $unit_id, 'conv_id' => $conv_id)); |
|
|
$res = $this->insertUserConv(array('uid' => $uid, 'unit_type' => $unit_type, 'conv_id' => $conv_id)); |
|
|
if (!$res) { |
|
|
if (!$res) { |
|
|
$this->setError('设置失败'); |
|
|
$this->setError('设置失败'); |
|
|
return false; |
|
|
return false; |
|
|