配置修改

This commit is contained in:
2026-07-13 16:33:09 +08:00
parent 9998f4651b
commit d1a15a4c42
15 changed files with 348 additions and 38 deletions

View File

@ -7,7 +7,7 @@ use app\admin\logic\user\LevelLogic;
use app\admin\logic\user\UserLogic;
use app\common\model\user\UserLevel;
use app\common\server\JsonServer;
use app\common\enum\ClientEnum;
use app\common\logic\RegionLogic;
use app\admin\validate\user\UserValidate;
use think\exception\ValidateException;
@ -65,7 +65,8 @@ class User extends AdminBase
return view('', [
'info' => $detail,
'tag_list' => json_encode(TagLogic::getTagList())
'tag_list' => json_encode(TagLogic::getTagList()),
'city_list' => RegionLogic::hotCity(),
]);
}

View File

@ -141,7 +141,7 @@ class UserLogic extends Logic
{
$field = [
'id', 'sn','nickname','avatar','mobile','sex','birthday','tag_ids',
'remark','user_money','user_growth','user_integral','earnings', 'disable'
'remark','user_money','user_growth','user_integral','earnings', 'disable', 'city_id'
];
$user = User::field($field)->where(['del' => 0, 'id' => $id])->findOrEmpty();
@ -170,6 +170,7 @@ class UserLogic extends Logic
'tag_ids' => $post['select'],
'remark' => $post['remark'],
'disable' => $post['disable'],
'city_id' => (int)($post['city_id'] ?? 0),
'update_time' => time()
];
User::update($data);

View File

@ -69,6 +69,18 @@
<input class="layui-input" value="{$info.birthday}" autocomplete="off" name="birthday" id="birthday" type="text" placeholder="请输入生日" >
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">所属城市</label>
<div class="layui-input-inline" style="width: 380px;">
<select name="city_id" lay-search>
<option value="0">上海总部(默认)</option>
{volist name="city_list" id="city"}
<option value="{$city.id}" {if $info.city_id == $city.id}selected{/if}>{$city.name}</option>
{/volist}
</select>
</div>
<div class="layui-form-mid layui-word-aux">码主人所属地区,扫码进入时将展示对应城市商城</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">会员标签</label>
<div class="layui-input-block" style="width: 380px;">

View File

@ -4,12 +4,13 @@ namespace app\api\controller;
use app\common\basics\Api;
use app\api\logic\IndexLogic;
use app\common\logic\ChatLogic;
use app\common\logic\CityLogic;
use app\common\logic\RegionLogic;
use app\common\server\JsonServer;
class Index extends Api
{
public $like_not_need_login = ['index','hotCity', 'indexCategory', 'config','copyright','city','geocoder'];
public $like_not_need_login = ['index','hotCity', 'indexCategory', 'config','copyright','city','geocoder','getEntryCity'];
// 首页
public function index()
@ -114,4 +115,18 @@ class Index extends Api
}
return JsonServer::success('',$result);
}
/**
* 小程序进入时获取应展示的城市商城
* 未扫码:上海总部;扫码:码主人所属城市
*/
public function getEntryCity()
{
$params = [
'invite_code' => $this->request->get('invite_code', ''),
'user_id' => $this->request->get('user_id/d', 0),
];
$data = CityLogic::getEntryCity($params);
return JsonServer::success('获取成功', $data);
}
}

View File

@ -51,8 +51,7 @@ class Shop extends Api
public function getShopCityInfo()
{
if($this->request->isGet()) {
$city_id = $this->request->get('city_id', 0);
$data = ShopLogic::getShopCityInfo($city_id, $this->user_id, input());
$data = ShopLogic::getShopCityInfo(0, $this->user_id, input());
return JsonServer::success('获取店铺信息成功', $data);
}else{
return JsonServer::error('请求类型错误');

View File

@ -46,8 +46,7 @@ class ShopGoodsCategory extends Api
public function getCityGoodsCategory()
{
if($this->request->isGet()) {
$city_id = $this->request->get('city_id', 0);
$data = ShopGoodsCategoryLogic::getCityGoodsCategory($city_id);
$data = ShopGoodsCategoryLogic::getCityGoodsCategory(0, input());
return JsonServer::success('获取店铺分类成功', $data);
}else{
return JsonServer::error('请求类型错误');

View File

@ -27,6 +27,7 @@ use app\common\model\distribution\Distribution;
use app\common\model\distribution\DistributionLevel;
use app\common\server\ConfigServer;
use app\common\model\user\UserDistribution;
use app\common\logic\CityLogic;
use app\common\model\user\User;
use app\common\model\distribution\DistributionMemberApply;
use app\common\model\distribution\DistributionOrderGoods;
@ -133,7 +134,11 @@ class DistributionLogic extends Logic
'update_time' => $time,
];
DistributionMemberApply::create($data);
User::where("id",$user_id)->update(['url'=>$url['data']['qr_code']]);
$userUpdate = ['url' => $url['data']['qr_code']];
if (!empty($post['city'])) {
$userUpdate['city_id'] = (int)$post['city'];
}
User::where("id", $user_id)->update($userUpdate);
$distribution = Distribution::where("user_id",$user_id)->find();
$defaultLevelId = DistributionLevel::where('is_default', 1)->value('id');
$data = [
@ -263,7 +268,7 @@ class DistributionLogic extends Logic
try {
Db::startTrans();
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation','user_integral'])
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation','user_integral', 'city_id'])
->where(['distribution_code' => $post['code']])
->findOrEmpty();
if($firstLeader->isEmpty()) {
@ -298,6 +303,12 @@ class DistributionLogic extends Logic
'update_time' => time()
];
// 扫码进入时继承码主人的所属城市
$ownerCityId = CityLogic::getUserCityId((int)$firstLeader['id']);
if ($ownerCityId > 0) {
$data['city_id'] = $ownerCityId;
}
// 更新当前用户的分销关系
User::where(['id' => $post['user_id']])->update($data);
@ -368,7 +379,7 @@ class DistributionLogic extends Logic
try {
Db::startTrans();
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation','user_integral'])
$firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation','user_integral', 'city_id'])
->where(['id' => $post['user_id']])
->findOrEmpty();
if($firstLeader->isEmpty()) {
@ -389,6 +400,11 @@ class DistributionLogic extends Logic
'update_time' => time()
];
$ownerCityId = CityLogic::getUserCityId((int)$firstLeader['id']);
if ($ownerCityId > 0) {
$data['city_id'] = $ownerCityId;
}
// 更新当前用户的分销关系
User::where(['id' => $user_id])->update($data);
//通知用户

View File

@ -2,6 +2,7 @@
namespace app\api\logic;
use app\common\basics\Logic;
use app\common\logic\CityLogic;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopGoodsCategory;
@ -27,18 +28,21 @@ class ShopGoodsCategoryLogic extends Logic
return $data;
}
public static function getCityGoodsCategory($city_id)
public static function getCityGoodsCategory($city_id, $params = [])
{
$shop_msg = Shop::where("city_id",$city_id)
->where("is_run",1)
->where("is_freeze",0)
->where("del",0)
->find();
$c = "";
if($shop_msg == null){
$shopId = 1;
}else{
$shopId = $shop_msg['id'];
$entryCity = CityLogic::getEntryCity([
'invite_code' => $params['invite_code'] ?? '',
'user_id' => (int)($params['user_id'] ?? 0),
]);
$shopId = (int)($entryCity['shop_id'] ?? 0);
if ($shopId <= 0) {
$city_id = (int)($entryCity['id'] ?? 0);
$shop_msg = Shop::where("city_id", $city_id)
->where("is_run", 1)
->where("is_freeze", 0)
->where("del", 0)
->find();
$shopId = $shop_msg == null ? 1 : (int)$shop_msg['id'];
}
$where = [
'del' => 0,

View File

@ -5,6 +5,7 @@ use app\common\basics\Logic;
use app\common\enum\GoodsEnum;
use app\common\enum\ShopAdEnum;
use app\common\enum\ShopEnum;
use app\common\logic\CityLogic;
use app\common\logic\QrCodeLogic;
use app\common\model\dev\DevRegion;
use app\common\model\shop\ShopAd;
@ -108,21 +109,32 @@ class ShopLogic extends Logic
return $shop;
}
public static function getShopCityInfo($city_id,$userId, $params = [])
public static function getShopCityInfo($city_id, $userId, $params = [])
{
// 未扫码进入:上海总部;扫码进入:码主人所属城市(忽略定位 city_id
$entryCity = CityLogic::getEntryCity([
'invite_code' => $params['invite_code'] ?? '',
'user_id' => (int)($params['user_id'] ?? 0),
]);
$city_id = (int)($entryCity['id'] ?? 0);
$entryShopId = (int)($entryCity['shop_id'] ?? 0);
// 记录统计信息(访问商铺用户量)
Event::listen('ShopStat', 'app\common\listener\ShopStat');
$shop_msg = Shop::where("city_id",$city_id)
->where("is_run",1)
->where("is_freeze",0)
->where("del",0)
->find();
$c = "";
if($shop_msg == null){
$c = "id = 1";
}else{
$c = "city_id = ".$city_id."";
if ($entryShopId > 0) {
$c = 'id = ' . $entryShopId;
} else {
$shop_msg = Shop::where("city_id", $city_id)
->where("is_run", 1)
->where("is_freeze", 0)
->where("del", 0)
->find();
if ($shop_msg == null) {
$c = "id = 1";
} else {
$c = "city_id = " . $city_id . "";
}
}
$field = [
@ -199,6 +211,8 @@ class ShopLogic extends Logic
'mobile' => ShopAd::where($adWhere)->where('terminal', ShopAdEnum::TERMINAL_MOBILE)->append([ 'link_path', 'link_query' ])->order('sort desc,id desc')->select()->toArray(),
];
$shop['entry_city'] = $entryCity;
return $shop;
}

View File

@ -0,0 +1,178 @@
<?php
namespace app\common\logic;
use app\common\basics\Logic;
use app\common\model\DevRegion;
use app\common\model\distribution\DistributionMemberApply;
use app\common\model\shop\Shop;
use app\common\model\user\User;
use app\common\server\ConfigServer;
class CityLogic extends Logic
{
/**
* 根据进入方式获取应展示的城市商城
* 未扫码进入:上海总部;扫码进入:码主人所属城市
*/
public static function getEntryCity(array $params = []): array
{
if (!empty($params['invite_code'])) {
return self::getCityByInviteCode($params['invite_code']);
}
if (!empty($params['user_id'])) {
return self::getCityByUserId((int)$params['user_id']);
}
return self::getHeadquartersCity();
}
/**
* 上海总部城市(默认商城)
*/
public static function getHeadquartersCity(): array
{
$cityId = self::resolveHeadquartersCityId();
if ($cityId <= 0) {
return self::formatCityInfo(0, true);
}
return self::formatCityInfo($cityId, true);
}
/**
* 根据邀请码获取码主人所属城市
*/
public static function getCityByInviteCode(string $code): array
{
$user = User::where(['distribution_code' => $code, 'del' => 0])
->field('id,city_id')
->findOrEmpty();
if ($user->isEmpty()) {
return self::getHeadquartersCity();
}
$cityId = self::resolveUserCityId((int)$user['id'], (int)$user['city_id']);
if ($cityId <= 0) {
return self::getHeadquartersCity();
}
return self::formatCityInfo($cityId);
}
/**
* 根据用户ID获取所属城市分销扫码等场景
*/
public static function getCityByUserId(int $userId): array
{
$user = User::where(['id' => $userId, 'del' => 0])
->field('id,city_id')
->findOrEmpty();
if ($user->isEmpty()) {
return self::getHeadquartersCity();
}
$cityId = self::resolveUserCityId((int)$user['id'], (int)$user['city_id']);
if ($cityId <= 0) {
return self::getHeadquartersCity();
}
return self::formatCityInfo($cityId);
}
/**
* 解析用户所属城市:优先用户表,其次分销申请地区
*/
protected static function resolveUserCityId(int $userId, int $cityId = 0): int
{
if ($cityId > 0) {
return $cityId;
}
if ($userId <= 0) {
return 0;
}
return (int)DistributionMemberApply::where([
['user_id', '=', $userId],
['status', '=', 1],
])->order('id desc')->value('city');
}
/**
* 获取用户所属城市ID扫码绑定时继承上级地区
*/
public static function getUserCityId(int $userId): int
{
if ($userId <= 0) {
return 0;
}
$cityId = (int)User::where(['id' => $userId, 'del' => 0])->value('city_id');
return self::resolveUserCityId($userId, $cityId);
}
protected static function formatCityInfo(int $cityId, bool $isHeadquarters = false): array
{
if ($cityId <= 0) {
return [
'id' => 0,
'name' => '上海总部',
'gcj02_lat' => 0,
'gcj02_lng' => 0,
'shop_id' => 1,
'is_headquarters' => 1,
];
}
$city = DevRegion::where('id', $cityId)
->field('id,name,gcj02_lat,gcj02_lng,db09_lat,db09_lng')
->findOrEmpty();
if ($city->isEmpty()) {
return [
'id' => 0,
'name' => '上海总部',
'gcj02_lat' => 0,
'gcj02_lng' => 0,
'shop_id' => 1,
'is_headquarters' => 1,
];
}
$shop = Shop::where([
['city_id', '=', $cityId],
['is_run', '=', 1],
['is_freeze', '=', 0],
['del', '=', 0],
])->field('id')->findOrEmpty();
return [
'id' => (int)$city['id'],
'name' => $city['name'],
'gcj02_lat' => (float)($city['gcj02_lat'] ?: 0),
'gcj02_lng' => (float)($city['gcj02_lng'] ?: 0),
'shop_id' => $shop->isEmpty() ? 1 : (int)$shop['id'],
'is_headquarters' => $isHeadquarters ? 1 : 0,
];
}
protected static function resolveHeadquartersCityId(): int
{
$cityId = (int)ConfigServer::get('shop', 'headquarters_city_id', 0);
if ($cityId <= 0) {
$cityId = (int)Shop::where(['id' => 1, 'del' => 0])->value('city_id');
}
if ($cityId <= 0) {
$cityId = (int)DevRegion::where(['level' => 2])
->whereLike('name', '上海%')
->value('id');
}
return $cityId;
}
}