This commit is contained in:
wanghai
2026-04-10 18:21:41 +08:00
parent b29c28858b
commit d04912e815
14 changed files with 548 additions and 19 deletions

View File

@@ -1009,6 +1009,7 @@ class Distributor extends Controller
* @SWG\Parameter( name="distribution_type", in="query", description="店铺类型:0自营;1加盟", required=false, type="string"),
* @SWG\Parameter( name="merchant_id", in="query", description="所属商家", required=false, type="string"),
* @SWG\Parameter( name="distributor_category_id", in="query", description="店铺分类id", required=false, type="string"),
* @SWG\Parameter( name="show_distributor_self", in="query", description="是否展示虚拟门店(distributor_self=1)传1或true时列表不过滤虚拟门店默认0不展示", required=false, type="string"),
* @SWG\Response( response=200, description="成功返回结构", @SWG\Schema(
* @SWG\Property( property="data", type="object",
* @SWG\Property( property="total_count", type="string", example="36", description=""),
@@ -1196,8 +1197,11 @@ class Distributor extends Controller
$filter['distributor_id'] = $staffRegionAuthDistributorIds;
}
}
// 虚拟门店不在列表做展示
$filter['distributor_self'] = 0;
// 虚拟门店distributor_self=1默认不在列表展示show_distributor_self=1/true 时允许展示
$showDistributorSelf = $request->input('show_distributor_self', 0);
if ($showDistributorSelf == 0) {
$filter['distributor_self'] = 0;
}
$distributorService = new DistributorService();
$data = $distributorService->getListByLang($filter, ["created" => "DESC"], $pageSize, $page);
$data['tagList'] = [];

View File

@@ -385,6 +385,10 @@ class Activity extends BaseController
$result['store_setting'] = $itemSettingService->getItemStoreSetting($companyId)['item_store_status'];
$result['distributor_id'] = $activity['distributor_id'];
// 与 Api Activity::getActivityItemList -> getActivityItemList 一致:主商品 + 规格行多语言
$localized = $activitiesService->applyMultiLangToActivityItemList([$result]);
$result = $localized[0];
return $this->response->array($result);
}

View File

@@ -20,6 +20,9 @@ namespace EmployeePurchaseBundle\Repositories;
use Doctrine\ORM\EntityRepository;
use EmployeePurchaseBundle\Entities\ActivityGoods;
use Dingo\Api\Exception\ResourceException;
use GoodsBundle\Entities\Items;
use GoodsBundle\Repositories\ItemsRepository;
use GoodsBundle\Services\MultiLang\MultiLangService;
class ActivityGoodsRepository extends EntityRepository
{
@@ -340,15 +343,38 @@ class ActivityGoodsRepository extends EntityRepository
$qb = $qb->andWhere($qb->expr()->eq('g.activity_id', $filter['activity_id']));
}
if (isset($filter['keywords']) && $filter['keywords']) {
$qb = $qb->andWhere($qb->expr()->orX(
$qb->expr()->like('i.item_name', $qb->expr()->literal('%'.$filter['keywords'].'%')),
$qb->expr()->like('i.item_bn', $qb->expr()->literal('%'.$filter['keywords'].'%'))
));
// 商品名称 / 关键字:与 GoodsBundle\Services\ItemsService::_filter 一致(多语言 item_name + 编号/条码)
$nameSearch = null;
if (isset($filter['item_name']) && $filter['item_name'] !== '') {
$nameSearch = trim((string) $filter['item_name']);
} elseif (isset($filter['keywords']) && $filter['keywords'] !== '') {
$nameSearch = trim((string) $filter['keywords']);
}
if (isset($filter['item_name']) && $filter['item_name']) {
$qb = $qb->andWhere($qb->expr()->like('i.item_name', $qb->expr()->literal('%'.$filter['item_name'].'%')));
if ($nameSearch !== null && $nameSearch !== '') {
/** @var ItemsRepository $itemsRepository */
$itemsRepository = app('registry')->getManager('default')->getRepository(Items::class);
$multiLangService = new MultiLangService();
$lang = $itemsRepository->getLang();
$langIds = $multiLangService->filterByLang($lang, 'item_name', $nameSearch, 'items');
$or = [
'or' => [
'item_bn|contains' => $nameSearch,
'barcode' => $nameSearch,
],
];
if (!empty($langIds)) {
$or['or']['item_id'] = $langIds;
}
$listBn = $itemsRepository->getItemsLists($or);
$idsBn = array_column($listBn, 'default_item_id');
$totalIds = array_unique(array_merge($idsBn, $langIds));
$totalIds = array_values(array_filter($totalIds, static function ($id) {
return $id !== null && $id !== '';
}));
if ($totalIds === []) {
return ['total_count' => 0, 'list' => []];
}
$qb = $qb->andWhere($qb->expr()->in('i.item_id', $totalIds));
}
if (isset($filter['item_bn']) && $filter['item_bn']) {
@@ -363,11 +389,13 @@ class ActivityGoodsRepository extends EntityRepository
}
}
if (isset($filter['category']) && $filter['category']) {
if (is_array($filter['category'])) {
$qb = $qb->andWhere($qb->expr()->in('c.category_id', $filter['category']));
// Api 使用 categoryFrontApi 使用 cat_id与 ItemsCategory 解析结果一致)
$saleCategoryIds = $filter['category'] ?? $filter['cat_id'] ?? null;
if ($saleCategoryIds) {
if (is_array($saleCategoryIds)) {
$qb = $qb->andWhere($qb->expr()->in('c.category_id', $saleCategoryIds));
} else {
$qb = $qb->andWhere($qb->expr()->eq('c.category_id', $filter['category']));
$qb = $qb->andWhere($qb->expr()->eq('c.category_id', $saleCategoryIds));
}
}

View File

@@ -22,9 +22,12 @@ use EmployeePurchaseBundle\Entities\Activities;
use EmployeePurchaseBundle\Entities\ActivityItems;
use EmployeePurchaseBundle\Entities\ActivityGoods;
use EmployeePurchaseBundle\Entities\ActivityEnterprises;
use GoodsBundle\Entities\Items;
use GoodsBundle\Repositories\ItemsRepository;
use GoodsBundle\Services\ItemsService;
use GoodsBundle\Services\ItemsCategoryService;
use GoodsBundle\Services\ItemsRelCatsService;
use GoodsBundle\Services\MultiLang\MultiLangService;
use DistributionBundle\Services\DistributorService;
use DistributionBundle\Services\DistributorItemsService;
use EmployeePurchaseBundle\Services\ActivityItemsService;
@@ -196,6 +199,38 @@ class ActivitiesService
return $result;
}
/**
* 活动商品列表行多语言(与 GoodsBundle\Repositories\ItemsRepository::list 一致)
*
* 前端展示名使用 itemName仅当行上已存在 itemName 时,用多语言后的 item_name 覆盖。
*
* @param array $list getActivityItemsList 返回的列表(可含 spec_items 子项)
* @return array
*/
public function applyMultiLangToActivityItemList(array $list)
{
if ($list === []) {
return $list;
}
/** @var ItemsRepository $itemsRepository */
$itemsRepository = app('registry')->getManager('default')->getRepository(Items::class);
$multiLangField = ['item_name', 'brief', 'intro'];
$table = 'items';
$lang = $itemsRepository->getLang();
$service = new MultiLangService();
$list = $service->getListAddLang($list, $multiLangField, $table, $lang, 'item_id');
foreach ($list as $k => $row) {
if ( isset($row['itemName']) ) {
$list[$k]['itemName'] = $list[$k]['item_name'] ?? '';
}
if (!empty($row['spec_items']) && is_array($row['spec_items'])) {
$list[$k]['spec_items'] = $service->getListAddLang($row['spec_items'], $multiLangField, $table, $lang, 'item_id');
}
}
return $list;
}
public function getActivityItemList($filter, $page, $pageSize, $itemSpec = false, $isDefault = false, $orderBy = ['item_id' => 'desc'])
{
$distributorId = $filter['distributor_id'] ?? 0;
@@ -223,6 +258,8 @@ class ActivitiesService
$row['store'] = $distributorItemsList[$row['item_id']]['store'] ?? 0;
}
}
unset($row);
$result['list'] = $this->applyMultiLangToActivityItemList($result['list']);
}
return $result;
}

View File

@@ -21,14 +21,51 @@ use EspierBundle\Entities\OfflineBankAccount;
class OfflineBankAccountService
{
public $subdistrictRepository;
/** @var \EspierBundle\Repositories\OfflineBankAccountRepository */
public $offlineBankAccountRepository;
public function __construct()
{
$this->offlineBankAccountRepository = app('registry')->getManager('default')->getRepository(OfflineBankAccount::class);
}
/**
* 线下转账列表中的 bank_name 为历史快照;按 bank_account_id 从收款账户取当前语言银行名(与 getLists 多语言一致)并覆盖。
*
* @param int $companyId
* @param array $rows offline_payment 列表行(引用 bank_account_id、bank_name
* @return array
*/
public function applyLocalizedBankNameToOfflinePaymentRows(int $companyId, array $rows): array
{
if ($rows === []) {
return $rows;
}
$bankAccountIds = array_unique(array_filter(array_map('intval', array_column($rows, 'bank_account_id'))));
if (!$bankAccountIds) {
return $rows;
}
$banks = $this->offlineBankAccountRepository->getLists(
['company_id' => $companyId, 'id' => $bankAccountIds],
'id,bank_name',
1,
-1,
[]
);
$bankNameById = [];
foreach ($banks as $bankRow) {
$bankNameById[(int) $bankRow['id']] = $bankRow['bank_name'] ?? '';
}
foreach ($rows as $k => $row) {
$bid = isset($row['bank_account_id']) ? (int) $row['bank_account_id'] : 0;
if ($bid && array_key_exists($bid, $bankNameById)) {
$rows[$k]['bank_name'] = $bankNameById[$bid];
}
}
return $rows;
}
public function createData($params)
{
// 如果is_default=1,其他的设置为0

View File

@@ -21,6 +21,7 @@ use AftersalesBundle\Services\AftersalesRefundService;
use App\Http\Controllers\Controller as Controller;
use Dingo\Api\Exception\ResourceException;
use EspierBundle\Jobs\ExportFileJob;
use EspierBundle\Services\OfflineBankAccountService;
use Illuminate\Http\Request;
use MembersBundle\Services\MemberService;
use OrdersBundle\Services\DeliveryProcessLogServices;
@@ -92,6 +93,10 @@ class OfflinePayment extends Controller
$this->__getFilter($params, $filter);
$offlinePaymentService = new OfflinePaymentService();
$result = $offlinePaymentService->repository->lists($filter, '*', $page, $pageSize, $orderBy);
if (!empty($result['list'])) {
$bankAccountService = new OfflineBankAccountService();
$result['list'] = $bankAccountService->applyLocalizedBankNameToOfflinePaymentRows($company_id, $result['list']);
}
return $this->response->array($result);
}
@@ -118,6 +123,11 @@ class OfflinePayment extends Controller
$params['company_id'] = app('auth')->user()->get('company_id');
$offlinePaymentService = new OfflinePaymentService();
$result = $offlinePaymentService->getDetail($params);
if (is_array($result) && $result !== []) {
$bankAccountService = new OfflineBankAccountService();
$localized = $bankAccountService->applyLocalizedBankNameToOfflinePaymentRows($params['company_id'], [$result]);
$result = $localized[0];
}
return $this->response->array($result);
}