|
@@ -27,9 +27,13 @@ class GoodLogic extends BaseLogic
|
|
|
$count = $db->count('a.id');
|
|
|
|
|
|
$list = $db
|
|
|
- ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,b.price,b.type')
|
|
|
+ ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,b.price,b.type,0 inventory')
|
|
|
->page($data['page'], $data['size'])
|
|
|
->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
|
|
|
+ ->withAttr('inventory', function ($val, $da) {
|
|
|
+ if ($da['type'] == GoodModel::$type_exchange) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
|
|
|
+ else return InventoryShoppingModel::where(['good_id' => $da['good_id']])->value('inventory');
|
|
|
+ })
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
@@ -54,7 +58,7 @@ class GoodLogic extends BaseLogic
|
|
|
})->withAttr('good_banner_img', function ($val) {
|
|
|
return explode(',', $val);
|
|
|
})->withAttr('inventory', function ($val, $da) {
|
|
|
- if ($da['type'] == GoodModel::$type_shopping) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
|
|
|
+ if ($da['type'] == GoodModel::$type_exchange) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
|
|
|
else return InventoryShoppingModel::where(['good_id' => $da['good_id']])->value('inventory');
|
|
|
})
|
|
|
->findOrEmpty()
|