From 822fec6e64da955623e6df2e934e3240a5315d35 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Mon, 19 Feb 2024 13:35:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=B6=E8=B4=A7=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/CityAreaDao.php | 30 ++++ .../repositories/store/CityAreaRepository.php | 10 ++ .../store/coupon/StoreCouponRepository.php | 6 + app/controller/admin/store/Coupon.php | 2 +- .../merchant/store/shipping/City.php | 154 ++++++++++++++++++ app/validate/merchant/StoreCouponValidate.php | 2 +- route/api.php | 4 + 7 files changed, 206 insertions(+), 2 deletions(-) diff --git a/app/common/dao/store/CityAreaDao.php b/app/common/dao/store/CityAreaDao.php index 1e9c55ba..28c6d178 100644 --- a/app/common/dao/store/CityAreaDao.php +++ b/app/common/dao/store/CityAreaDao.php @@ -16,6 +16,12 @@ namespace app\common\dao\store; use app\common\dao\BaseDao; use app\common\model\BaseModel; use app\common\model\store\CityArea; +use app\common\model\store\GeoArea; +use app\common\model\store\GeoBrigade; +use app\common\model\store\GeoCity; +use app\common\model\store\GeoProvince; +use app\common\model\store\GeoStreet; +use app\common\model\store\GeoVillage; use think\exception\ValidateException; class CityAreaDao extends BaseDao @@ -68,4 +74,28 @@ class CityAreaDao extends BaseDao $lst[] = $city; return $lst; } + + public function searchGeo(array $where) + { + if (!empty($where['street_code'])) { + return GeoVillage::getDB()->where('street_code', $where['street_code']); + } + if (!empty($where['area_code'])) { + return GeoStreet::getDB()->where('area_code', $where['area_code']); + } + if (!empty($where['city_code'])) { + return GeoArea::getDB()->where('city_code', $where['city_code']); + } + if (!empty($where['province_code'])) { + return GeoCity::getDB()->where('province_code', $where['province_code']); + } else { + return GeoProvince::getDB(); + } + } + + public function searchBrigade(array $where) + { + return GeoBrigade::getDB(); + } + } diff --git a/app/common/repositories/store/CityAreaRepository.php b/app/common/repositories/store/CityAreaRepository.php index 5d64d734..1dc81844 100644 --- a/app/common/repositories/store/CityAreaRepository.php +++ b/app/common/repositories/store/CityAreaRepository.php @@ -34,6 +34,16 @@ class CityAreaRepository extends BaseRepository return $this->search(['pid' => $pid])->select(); } + public function getGeoChildren($where) + { + return $this->searchGeo($where)->select(); + } + + public function getBrigade($where) + { + return $this->searchBrigade($where)->select(); + } + public function getList($where) { return $this->dao->getSearch($where)->with(['parent'])->order('id ASC')->select()->append(['children','hasChildren']); diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index 165bf7c2..d6a2f6a0 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -54,6 +54,10 @@ class StoreCouponRepository extends BaseRepository const TYPE_PLATFORM_CATE = 11; //平台跨店券 const TYPE_PLATFORM_STORE = 12; + //平台购物卡,可全额抵扣,可结余 + const TYPE_PLATFORM_CARD = 13; + //平台抵扣券,按比例部分抵扣,可结余 + const TYPE_PLATFORM_COUPON = 14; //获取方式 const GET_COUPON_TYPE_RECEIVE = 0; @@ -392,6 +396,8 @@ class StoreCouponRepository extends BaseRepository ['value' => self::TYPE_PLATFORM_ALL, 'label' => '通用券'], ['value' => self::TYPE_PLATFORM_CATE, 'label' => '品类券'], ['value' => self::TYPE_PLATFORM_STORE, 'label' => '跨店券'], + ['value' => self::TYPE_PLATFORM_CARD, 'label' => '购物卡'], + ['value' => self::TYPE_PLATFORM_COUPON, 'label' => '抵扣券'], ])->control([ [ 'value' => self::TYPE_PLATFORM_CATE, diff --git a/app/controller/admin/store/Coupon.php b/app/controller/admin/store/Coupon.php index 13ade2c0..6cc82e39 100644 --- a/app/controller/admin/store/Coupon.php +++ b/app/controller/admin/store/Coupon.php @@ -243,7 +243,7 @@ class Coupon extends BaseController } else unset($data['use_start_time']); unset($data['range_date']); if ($data['is_limited'] == 0) $data['total_count'] = 0; - if (!in_array($data['type'], [10, 11, 12])) { + if (!in_array($data['type'], [10, 11, 12, 13, 14])) { throw new ValidateException('请选择有效的优惠券类型'); } $data['mer_id'] = $this->request->merId(); diff --git a/app/controller/merchant/store/shipping/City.php b/app/controller/merchant/store/shipping/City.php index 8247d8b7..a04aa89c 100644 --- a/app/controller/merchant/store/shipping/City.php +++ b/app/controller/merchant/store/shipping/City.php @@ -13,6 +13,7 @@ namespace app\controller\merchant\store\shipping; use app\common\repositories\store\CityAreaRepository; +use Overtrue\Pinyin\Pinyin; use think\App; use crmeb\basic\BaseController; use app\common\repositories\store\shipping\CityRepository as repository; @@ -72,4 +73,157 @@ class City extends BaseController { return app('json')->success($this->repository->getFormatList(['is_show' => 1])); } + + public function lstV3() + { + $provinceCode = $this->request->param('province_code') ?? ''; + $cityCode = $this->request->param('city_code') ?? ''; + $areaCode = $this->request->param('area_code') ?? ''; + $streetCode = $this->request->param('street_code') ?? ''; + $pinyin = $this->request->param('pinyin') ?? 0; + /** @var CityAreaRepository $repo */ + $repo = app()->make(CityAreaRepository::class); + $list = $repo->getGeoChildren(['province_code' => $provinceCode, 'city_code' => $cityCode, 'area_code' => $areaCode, 'street_code' => $streetCode]); + $geoList = []; + $pyList = []; + foreach ($list as $v) { + $temp = []; + if (!empty($v['village_id'])) { + if ($pinyin == 1) { + $py = strtoupper((new Pinyin)->abbr($v['village_name'])[0] ?? '-'); + $pyList[$py][] = [ + 'type' => 'village', + 'id' => $v['village_id'], + 'level' => 5, + 'name' => $v['village_name'] ?? '', + 'code' => $v['village_code'] ?? '' + ]; + } else { + $temp = [ + 'type' => 'village', + 'id' => $v['village_id'], + 'level' => 5, + 'name' => $v['village_name'] ?? '', + 'code' => $v['village_code'] ?? '' + ]; + $geoList[] = $temp; + } + } + if (!empty($v['street_id'])) { + if ($pinyin == 1) { + $py = strtoupper((new Pinyin)->abbr($v['street_name'])[0] ?? '-'); + $pyList[$py][] = [ + 'type' => 'street', + 'id' => $v['street_id'], + 'level' => 4, + 'name' => $v['street_name'] ?? '', + 'code' => $v['street_code'] ?? '' + ]; + } else { + $temp = [ + 'type' => 'street', + 'id' => $v['street_id'], + 'level' => 4, + 'name' => $v['street_name'] ?? '', + 'code' => $v['street_code'] ?? '' + ]; + $geoList[] = $temp; + } + } + if (!empty($v['area_id'])) { + if ($pinyin == 1) { + $py = strtoupper((new Pinyin)->abbr($v['area_name'])[0] ?? '-'); + $pyList[$py][] = [ + 'type' => 'area', + 'id' => $v['area_id'], + 'level' => 3, + 'name' => $v['area_name'] ?? '', + 'code' => $v['area_code'] ?? '' + ]; + } else { + $temp = [ + 'type' => 'area', + 'id' => $v['area_id'], + 'level' => 3, + 'name' => $v['area_name'] ?? '', + 'code' => $v['area_code'] ?? '' + ]; + $geoList[] = $temp; + } + } + if (!empty($v['city_id'])) { + if ($pinyin == 1) { + $py = strtoupper((new Pinyin)->abbr($v['city_name'])[0] ?? '-'); + $pyList[$py][] = [ + 'type' => 'city', + 'id' => $v['city_id'], + 'level' => 2, + 'name' => $v['city_name'] ?? '', + 'code' => $v['city_code'] ?? '' + ]; + } else { + $temp = [ + 'type' => 'city', + 'id' => $v['city_id'], + 'level' => 2, + 'name' => $v['city_name'] ?? '', + 'code' => $v['city_code'] ?? '', + ]; + $geoList[] = $temp; + } + } + if (!empty($v['province_id'])) { + if ($pinyin == 1) { + $py = strtoupper((new Pinyin)->abbr($v['province_name'])[0] ?? '-'); + $pyList[$py][] = [ + 'type' => 'province', + 'id' => $v['province_id'], + 'level' => 1, + 'name' => $v['province_name'] ?? '', + 'code' => $v['province_code'] ?? '' + ]; + } else { + $temp = [ + 'type' => 'province', + 'id' => $v['province_id'], + 'level' => 1, + 'name' => $v['province_name'] ?? '', + 'code' => $v['province_code'] ?? '' + ]; + $geoList[] = $temp; + } + } + } + if ($pinyin == 1) { + $geoList = []; + foreach($pyList as $k=>$v) { + $temp = []; + $temp['pinyin'] = $k; + $temp['data'] = $pyList[$k]; + $geoList[] = $temp; + } + } + return app('json')->success($geoList); + } + + public function brigade() + { + /** @var CityAreaRepository $repo */ + $repo = app()->make(CityAreaRepository::class); + $list = $repo->getBrigade([]); + $geoList = []; + foreach ($list as $v) { + $temp = [ + 'type' => 'brigade', + 'id' => $v['id'], + 'level' => 6, + 'name' => $v['brigade_name'] ?? '', + 'code' => $v['brigade_name'] ?? '' + ]; + $geoList[] = $temp; + } + return app('json')->success($geoList); + } + + } diff --git a/app/validate/merchant/StoreCouponValidate.php b/app/validate/merchant/StoreCouponValidate.php index 099998ff..670b5d8f 100644 --- a/app/validate/merchant/StoreCouponValidate.php +++ b/app/validate/merchant/StoreCouponValidate.php @@ -29,7 +29,7 @@ class StoreCouponValidate extends Validate 'use_start_time|有效期限' => 'requireIf:coupon_type,1|array|>:2', 'sort|排序' => 'require|integer', 'status|状态' => 'require|in:0,1', - 'type|优惠券类型' => 'require|in:0,1,10,11,12', + 'type|优惠券类型' => 'require|in:0,1,10,11,12,13,14', 'product_id|商品' => 'requireIf:type,1|array|>:0', 'send_type|类型' => 'require|in:0,1,2,3,4,5', 'full_reduction|满赠金额' => 'requireIf:send_type,1|float|>=:0', diff --git a/route/api.php b/route/api.php index 06769549..962ffb70 100644 --- a/route/api.php +++ b/route/api.php @@ -605,6 +605,10 @@ Route::group('api/', function () { Route::get('system/city/lst', 'merchant.store.shipping.City/getlist'); Route::get('v2/system/city/lst/:pid', 'merchant.store.shipping.City/lstV2'); Route::get('v2/system/city', 'merchant.store.shipping.City/cityList'); + //省市区县街道 + Route::get('v2/system/geo/lst', 'merchant.store.shipping.City/lstV3'); + //队列表 + Route::get('v2/system/brigade', 'merchant.store.shipping.City/brigade'); //热门搜索 Route::get('common/hot_keyword', 'api.Common/hotKeyword')->append(['type' => 0]);