问题说明:进店规则获取门店和商品所在门店冲突造成没获取到门店信息
修改文件:app/services/store/SystemStoreServices.php
修改方法:getStoreList()
public function getStoreList(array $where, array $field = ['*'], string $latitude = '', string $longitude = '', int $product_id = 0, array $with = [], int $type = 0, $store_id = 0)
{
$order = 0;
if (isset($where['order_id']) && $where['order_id']) {
/** @var StoreOrderServices $storeOrderServices */
$storeOrderServices = app()->make(StoreOrderServices::class);
$user_location = $storeOrderServices->value(['id' => $where['order_id']], 'user_location');
if ($user_location) {
[$longitude, $latitude] = explode(' ', $user_location);
}
}
if ($longitude && $latitude) {
$order = 1;
}
$list = [];
$count = 0;
//移动端定位选择门店
if ($store_id) {
$where['ids'] = [$store_id];
}
//该商品上架的门店
if ($product_id) {
/** @var StoreBranchProductServices $productServices */
$productServices = app()->make(StoreBranchProductServices::class);
[$ids, $applicableType, $productType] = $productServices->getApplicableStoreIds($product_id, $type);
if ($ids) {
if ($productType == 1) {//门店商品
$where['ids'] = $ids;
} else {
if ($store_id && !in_array($store_id, $ids)) {
return compact('list', 'count');
}
if (isset($where['ids']) && $where['ids']) {
$ids = array_intersect($where['ids'], $ids);
}
if ($ids) {
$where['ids'] = $ids;
} else {
return compact('list', 'count');
}
$where['ids'] = isset($where['ids']) && $where['ids'] ? array_intersect($where['ids'], $ids) : $ids;
}
} else {
if ($applicableType != 1) {//不是所有门店
return compact('list', 'count');
}
}
}
$oid = (int)($where['order_id'] ?? 0);
unset($where['order_id']);
if (isset($where['ids'])) {//有选择门店 || 商品适用门店情况
if (isset($where['id']) && $where['id']) {//合并进店规则进入门店
$where['ids'] = array_merge($where['ids'], is_array($where['id']) ? $where['id'] :[$where['id']]);
unset($where['id']);
}
$where['ids'] = array_unique(array_diff($where['ids'], [0]));
}
if ($oid || $product_id) {//不分页
$page = $limit = 0;
} else {
[$page, $limit] = $this->getPageValue();
}
$storeList = $this->dao->getStoreList($where, $field, $page, $limit, $with, $latitude, $longitude, $order);
if ($storeList) {
$storeIds = [];
if ($oid) {
[$storeIds, $cartInfo] = $this->checkOrderProductShare($oid, $storeList, 2);
}
$prefix = config('admin.store_prefix');
$regionIds = array_column($storeList, 'region_id');
if ($regionIds) {
/** @var SystemRegionAgentServices $storeRegionServices */
$storeRegionServices = app()->make(SystemRegionAgentServices::class);
$regionNames = $storeRegionServices->getColumn([['id', 'in', $regionIds], ['is_del', '=', 0]], 'name', 'id');
}
$now = date('Hi');
foreach ($storeList as &$item) {
$item['type_name'] = '';
if (isset($item['type'])) {
$item['type_name'] = $this->typeName[$item['type']] ?? '';
}
if (isset($item['distance'])) {
$item['range'] = bcdiv($item['distance'], '1000', 1);
} else {
$item['range'] = 0;
}
$item['business_status'] = 0;
if ($item['is_show'] == 1) {
$item['status_name'] = '营业中';
if ($item['day_start'] && $item['day_end']) {
$start = date('Hi', strtotime($item['day_start']));
$end = date('Hi', strtotime($item['day_end']));
if ($now >= $start && $now <= $end) {
$item['business_status'] = 1;
}
}
} else {
$item['status_name'] = '已停业';
}
$item['prefix'] = $prefix;
$item['recommend_region_name'] = '';
if (isset($item['region_id']) && $item['region_id']) {
$item['recommend_region_name'] = $regionNames[$item['region_id']] ?? '';
}
if ($oid) {
if (in_array($item['id'], $storeIds)) {
$list[] = $item;
}
} else {
$list[] = $item;
}
}
if (count($list) && $store_id) {
$arr = [];
foreach ($list as $key => $value) {
if ($value['id'] == $store_id) {
$arr = $value;
unset($list[$key]);
}
}
if ($arr) array_unshift($list, $arr);
}
if ($oid) {
$count = count($list);
} else {
$count = $this->dao->count($where);
}
}
return compact('list', 'count');
}
