初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,226 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\adminapi\logic\setting;
use app\common\logic\BaseLogic;
use app\common\model\city\City;
use app\common\model\goods\GoodsCategory;
use app\common\model\Region;
use app\common\model\skill\Skill;
class CityLogic extends BaseLogic
{
/**
* @notes 城市列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/10/6 17:27
*/
public function getCityLists()
{
$lists = City::where(['level'=>2])->select()->toArray();
$cityLists = [];
foreach ($lists as $city){
$parent = $cityLists[$city['parent_id']] ?? [];
if($parent){
$parent['sons'][] =[
'id' => $city['city_id'],
'name' => $city['name'],
];
}else{
$parent = [
'id' => $city['parent_id'],
'name' => $city['parent_name'],
'sons' => [
[
'id' => $city['city_id'],
'name' => $city['name'],
],
],
];
}
$cityLists[$city['parent_id']] = $parent;
}
return array_values($cityLists);
}
/**
* @notes 城市列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author cjhao
* @date 2024/10/6 17:27
*/
public function getRegionLists()
{
$lists = City::where(['level'=>2])->select()->toArray();
$cityLists = [];
foreach ($lists as $city){
$parent = $cityLists[$city['parent_id']] ?? [];
if($parent){
$parent['children'][] =[
'value' => $city['city_id'],
'label' => $city['name'],
'children' => [],
];
}else{
$parent = [
'value' => $city['parent_id'],
'label' => $city['parent_name'],
'children' => [
[
'value' => $city['city_id'],
'label' => $city['name'],
'children' => [],
],
],
];
}
$cityLists[$city['parent_id']] = $parent;
}
$cityIds = array_column($lists,'city_id');
$regionLists = Region::where(['parent_id'=>$cityIds,'level'=>3])->select()->toArray();
foreach ($cityLists as $key => $city){
foreach ($city['children'] as $sonsKey => $sons){
foreach ($regionLists as $regionList){
if($regionList['parent_id'] == $sons['value']){
$sons['children'][] = [
'value' => $regionList['id'],
'label' => $regionList['name'],
];
}
}
$cityLists[$key]['children'][$sonsKey] = $sons;
}
}
return array_values($cityLists);
}
/**
* @notes 添加
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 5:03 下午
*/
public function add($params)
{
$region = Region::where(['id'=>$params['city_id']])
->field('name,parent_id,level,gcj02_lng,gcj02_lat,db09_lng,db09_lat')
->findOrEmpty()
->toArray();
$parentName = Region::where(['id'=>$region['parent_id']])->value('name');
City::create([
'parent_id' => $region['parent_id'],
'parent_name' => $parentName,
'city_id' => $params['city_id'],
'level' => $region['level'],
'name' => $region['name'],
'taxi' => $params['taxi'],
'start_km' => $params['start_km'],
'start_price' => $params['start_price'],
'continue_price' => $params['continue_price'],
'gcj02_lng' => $region['gcj02_lng'],
'gcj02_lat' => $region['gcj02_lat'],
'db09_lng' => $region['db09_lng'],
'db09_lat' => $region['db09_lat'],
'bus' => $params['bus'],
'bus_start_time' => $params['bus_start_time'],
'bus_end_time' => $params['bus_end_time'],
'bus_fare' => $params['bus_fare'],
]);
return true;
}
/**
* @notes 查看服务分类详情
* @param $id
* @return array
* @author ljj
* @date 2022/2/8 5:21 下午
*/
public function detail($id)
{
$result = City::where('id',$id)->withoutField('update_time,delete_time')->findOrEmpty()->toArray();
return $result;
}
/**
* @notes 编辑服务分类
* @param $params
* @return bool
* @author ljj
* @date 2022/2/8 6:25 下午
*/
public function edit($params)
{
$region = Region::where(['id'=>$params['city_id']])
->field('name,parent_id,level,gcj02_lng,gcj02_lat,db09_lng,db09_lat')
->findOrEmpty()->toArray();
$parentName = Region::where(['id'=>$region['parent_id']])->value('name');
City::update([
'parent_id' => $region['parent_id'],
'parent_name' => $parentName,
'level' => $region['level'],
'city_id' => $params['city_id'],
'name' => $region['name'],
'taxi' => $params['taxi'],
'start_km' => $params['start_km'],
'start_price' => $params['start_price'],
'continue_price' => $params['continue_price'],
'bus' => $params['bus'],
'gcj02_lng' => $region['gcj02_lng'],
'gcj02_lat' => $region['gcj02_lat'],
'db09_lng' => $region['db09_lng'],
'db09_lat' => $region['db09_lat'],
'bus_start_time' => $params['bus_start_time'],
'bus_end_time' => $params['bus_end_time'],
'bus_fare' => $params['bus_fare'],
],['id'=>$params['id']]);
return true;
}
/**
* @notes 删除服务
* @param $id
* @return bool
* @author ljj
* @date 2022/2/8 6:34 下午
*/
public function del($id)
{
return City::destroy($id);
}
}