Commit 161e49d4 authored by wwccw0591's avatar wwccw0591

upd

parent 03b8eaa8
......@@ -14,7 +14,16 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
}
public function setGoodsStorage($storeId, $goodsId, $num = 0, $type='set') {
/**
* 设置库存
* @param $storeId
* @param $goodsId
* @param int $num
* @param string $type
* @return array
* @throws \Exception
*/
public function setGoodsStorage($storeId, $goodsId, $num = 0, $type='add') {
if($goodsId === 0){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::commonError);
}
......@@ -27,12 +36,12 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
if(!$data) {
\Error\ErrorModel::throwException(\Error\CodeConfigModel::goodsNotExist);
}
$op = isset($this->setStorageType[$type]) ? $this->setStorageType[$type] : 2; //默认设置库存
$op = isset($this->setStorageType[$type]) ? $this->setStorageType[$type] : 1; //默认增加库存
$goodsDao->db->doTransaction();
$ret1 = $goodsDao->updateStorage($goodsId, $num, $op);
$ret2 = true;
if($op==1) { //如果就库存调整
$ret2 = $commonDao->updateStorage($data['goods_commonid']);
$ret2 = $commonDao->updateStorage($data['goods_commonid'], $op);
}
if(!$ret1 || !$ret2) {
......
......@@ -35,10 +35,14 @@ class GoodsCommonModel extends \DAO\AbstractModel {
* @param $op 1增加 2设置
* @return mixed
*/
public function updateStorage($goodsCommonid) {
public function updateStorage($goodsCommonid, $op = 1) {
$this->setDb();
$whereSql = 'goods_commonid='.$goodsCommonid;
$updateSql = 'goods_storage = (select sum(t.goods_storage) from '.$this->_child_tableName.' t where t.goods_commonid='.$goodsCommonid.')';
if($op==1){
$updateSql = 'goods_storage = (select sum(t.goods_storage) from '.$this->_child_tableName.' t where t.goods_commonid='.$goodsCommonid.')';
} else {
$updateSql = 'goods_storage_alarm = 0';
}
$updateAllSql = "UPDATE {$this->_tableName} set {$updateSql} where {$whereSql}";
return $this->db->update($this->_tableName)->query($updateAllSql);
}
......
File mode changed from 100755 to 100644
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment