[FEAT] 銷售訂單管理:補齊欄位、即時搜尋、篩選與來源自動判定
This commit is contained in:
@@ -190,10 +190,10 @@ class ProductService implements ProductServiceInterface
|
||||
{
|
||||
$product = null;
|
||||
if (!empty($barcode)) {
|
||||
$product = Product::query()->where('barcode', $barcode)->first();
|
||||
$product = Product::where('barcode', $barcode)->first();
|
||||
}
|
||||
if (!$product && !empty($code)) {
|
||||
$product = Product::query()->where('code', $code)->first();
|
||||
$product = Product::where('code', $code)->first();
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
@@ -207,7 +207,6 @@ class ProductService implements ProductServiceInterface
|
||||
*/
|
||||
public function searchProducts(array $filters, int $perPage = 50)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
||||
$query = Product::query()
|
||||
->with(['category', 'baseUnit'])
|
||||
->where('is_active', true);
|
||||
@@ -226,12 +225,16 @@ class ProductService implements ProductServiceInterface
|
||||
$query->where('external_pos_id', $filters['external_pos_id']);
|
||||
}
|
||||
|
||||
// 3. 分類過濾
|
||||
// 3. 分類過濾 (優先使用 ID,若傳入字串則按名稱)
|
||||
if (!empty($filters['category'])) {
|
||||
$categoryName = $filters['category'];
|
||||
$query->whereHas('category', function ($q) use ($categoryName) {
|
||||
$q->where('name', $categoryName);
|
||||
});
|
||||
$categoryVal = $filters['category'];
|
||||
if (is_numeric($categoryVal)) {
|
||||
$query->where('category_id', $categoryVal);
|
||||
} else {
|
||||
$query->whereHas('category', function ($q) use ($categoryVal) {
|
||||
$q->where('name', $categoryVal);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 增量同步 (Updated After)
|
||||
|
||||
Reference in New Issue
Block a user