Commit 4f4c8fa3 by 杨树贤

添加可使用库存字段

parent 4c13de3c
Showing with 14 additions and 2 deletions
...@@ -41,7 +41,6 @@ class ExchangeSetting extends Model ...@@ -41,7 +41,6 @@ class ExchangeSetting extends Model
//先从redis里面查询是否有列表,没有的话从MySQL里面取出并且放入redis //先从redis里面查询是否有列表,没有的话从MySQL里面取出并且放入redis
$redis = new RedisModel(); $redis = new RedisModel();
$settings = $this->getExchangeSettingsFromRedis(); $settings = $this->getExchangeSettingsFromRedis();
$count = 0;
if (!$settings) { if (!$settings) {
$result = $this->addExchangeSettingListToRedis(); $result = $this->addExchangeSettingListToRedis();
if (!$result) { if (!$result) {
...@@ -49,7 +48,8 @@ class ExchangeSetting extends Model ...@@ -49,7 +48,8 @@ class ExchangeSetting extends Model
$settings = $this->getExchangeSettingsFromRedis(); $settings = $this->getExchangeSettingsFromRedis();
} }
} }
//这边还要去redis获取每项的可使用库存
$settings = $this->getAvailableStock($settings);
//如果需要过滤type //如果需要过滤type
if ($map['type']) { if ($map['type']) {
$settings = array_filter($settings, function ($value) use ($map) { $settings = array_filter($settings, function ($value) use ($map) {
...@@ -138,6 +138,18 @@ class ExchangeSetting extends Model ...@@ -138,6 +138,18 @@ class ExchangeSetting extends Model
} }
} }
public function getAvailableStock($settings = [])
{
$redis = new RedisModel();
foreach ($settings as $key => &$setting) {
$key = 'ic_exchange_settings_' . $setting['id'];
$setting['available_stock'] = $redis->llen($key);
}
unset($setting);
return $settings;
}
public function updateExchangeSetting($id, $data = []) public function updateExchangeSetting($id, $data = [])
{ {
$result = DB::transaction(function () use ($id, $data) { $result = DB::transaction(function () use ($id, $data) {
......
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 sign in to comment