diff --git a/app/controller/api/Area.php b/app/controller/api/Area.php index 6b641b7..951b597 100644 --- a/app/controller/api/Area.php +++ b/app/controller/api/Area.php @@ -2,6 +2,7 @@ namespace app\controller\api; +use app\repository\DictionaryRepository; use think\facade\Db; use app\model\Area as AreaModel; /** @@ -13,7 +14,7 @@ use app\model\Area as AreaModel; class Area extends Base { protected $noNeedLogin = [ - 'index', + 'index',"getProvinceDictionaryCity" ]; /** @@ -25,4 +26,50 @@ class Area extends Base $filter = input("filter",false); return json(AreaModel::getByPCode($pcode,$filter)); } + + /** + * 获取 + * */ + public function getProvinceDictionaryCity() + { + $province = AreaModel::getByPCode(86,true); + $provinceCode = array_column($province->toArray(),null,"code"); + $provinceCodeArray = array_keys($provinceCode); + + $city = AreaModel::getByPCodes($provinceCodeArray,true); + $city = array_column($city,null,"code"); + + + $items = DictionaryRepository::getInstance()->getAllBusinessCircleList(); + $items->each(function ($item)use($city) { + $areaText = ''; + if (!empty($item['province_text'])) { + $areaText = $item['province_text'].'·'; + } + if (!empty($item['city_text']) && $item['city_text'] != '市辖区') { + $areaText .= $item['city_text'].'·'; + } + if (!empty($item['county_text'])) { + $areaText .= $item['county_text']; + } + + $item['name_text'] = $item['name']; + if (!empty($areaText)) { + $item['name_text'] = $item['name'] . '「'.$areaText.'」'; + } + return $item; + }); + foreach ($items->toArray() as $item){ + if(isset($city[$item["city"]])){ + $city[$item["city"]]["children"][]=$item; + } + } + + foreach ($city as $item){ + if (isset($provinceCode[$item["pcode"]])){ + $provinceCode[$item["pcode"]]["children"][] =$item; + } + } + return $this->json(0,"success",$provinceCode); + } } \ No newline at end of file diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 873a676..620a603 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -366,6 +366,7 @@ class Business extends Base $data["businessAddress"] = $list['province_text'] . $list['city_text'] . $list['county_text'] . $business['business_address']; $data["businessName"] = $list['business_name']; + $data["businessSubtitle"] = $business['business_subtitle']; $data["count"] = $couponMain->count; $data["couponName"] = $couponMain->name; $data["deductionMoney"] = $couponMain->deduction_money; diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 1ffbf01..8790e7e 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -776,7 +776,9 @@ class Coupon extends Base { $couponMainId = input("couponMainId/d"); $couponMain = CouponMain::findById($couponMainId,[],function ($q){ - return $q->with("usingRule"); + return $q->with(["usingRule","business"=>function($q){ + $q->field("code,business_subtitle"); + }]); }); if(empty($couponMain)){ return $this->json(4001,"优惠券不存在"); diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 6e76ed6..2d16312 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -310,7 +310,6 @@ class Coupon extends Base } $business = BusinessRepository::getInstance()->getBusinessAccount($data["business_code"], true); - if (empty($business)) { return $this->json(4001, '商家不存在'); } diff --git a/app/model/Area.php b/app/model/Area.php index 5fa5f66..691f9e4 100644 --- a/app/model/Area.php +++ b/app/model/Area.php @@ -19,10 +19,32 @@ class Area extends Base */ public static function getByPCode($PCode,bool $filter = false) { - return self::where("pcode",$PCode) ->when($filter,function ($q){ + return self::where("pcode",$PCode)->when($filter,function ($q){ $q->where("status",self::COMMON_ON); - })->order("id asc")->select(); + }) + ->field("id,code,pcode,name,status") + ->order("id asc")->select(); } +/** + * + * @param $PCode + * @param $filter bool 是否过滤屏蔽的地区 + * @return Area[]|array|\think\Collection + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function getByPCodes($PCodes,bool $filter = false) + { + return self::where("pcode","in",$PCodes) ->when($filter,function ($q){ + $q->where("status",self::COMMON_ON); + }) + ->field("id,code,pcode,name,status") + ->order("id asc") + ->select() + ->toArray(); + } + // 获取列表 diff --git a/app/repository/BusinessRepository.php b/app/repository/BusinessRepository.php index 4446295..db75910 100644 --- a/app/repository/BusinessRepository.php +++ b/app/repository/BusinessRepository.php @@ -157,13 +157,13 @@ class BusinessRepository extends Repository */ public function getBusinessAccount($businessCode, bool $lock = false) { - $Flow = Business::with(["account"])->where("code", $businessCode)->when($lock, function ($q) { + $business = Business::where("code", $businessCode)->when($lock, function ($q) { $q->lock(true); })->find(); - if (empty($Flow) || empty($Flow->account)) { + if (empty($business)) { return null; } - return $Flow; + return $business; } diff --git a/view/manager/coupon/edit.html b/view/manager/coupon/edit.html index 9f6f51d..c892f9d 100644 --- a/view/manager/coupon/edit.html +++ b/view/manager/coupon/edit.html @@ -16,7 +16,7 @@