| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace app\controller\api; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use app\exception\RepositoryException; | 
					
						
							|  |  |  | use app\repository\BusinessRepository; | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  | use app\repository\CouponRepository; | 
					
						
							|  |  |  | use app\repository\DictionaryRepository; | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  | use think\response\Json; | 
					
						
							|  |  |  | use app\model\{ | 
					
						
							|  |  |  |     Business as BusinessModel | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * APP 数据字典 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Class Dictionary | 
					
						
							|  |  |  |  * @package app\controller\api | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Dictionary extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     protected $noNeedLogin = [ | 
					
						
							|  |  |  |         'getDistanceList', | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |         'getBusinessCircle', | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |         'getAgencyList', | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |         'getBusinessTypeList', | 
					
						
							|  |  |  |         'getCouponTypeList', | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取距离(distance)列表 | 
					
						
							|  |  |  |      * @return Json | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getDisList(): Json | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $list = [ | 
					
						
							|  |  |  |             ['id' => 1, 'name'=> "1km", 'value' => 1], | 
					
						
							|  |  |  |             ['id' => 3, 'name'=> "3km", 'value' => 3], | 
					
						
							|  |  |  |             ['id' => 5, 'name'=> "5km", 'value' => 5], | 
					
						
							|  |  |  |             ['id' => 10, 'name'=> "10km", 'value' => 10], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->json(0, 'success', $list); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取商圈列表 | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |      * @return Json | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |     public function getBusinessCircle(): Json | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |         $items = DictionaryRepository::getInstance()->getAllBusinessCircleList(); | 
					
						
							| 
									
										
										
										
											2021-11-30 18:52:02 +08:00
										 |  |  |         $items->each(function ($item) { | 
					
						
							|  |  |  |             $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; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |         return $this->json(0, 'success', $items); | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-11-30 18:52:02 +08:00
										 |  |  |      * 获取代理机构(代理商)关联的商家列表 | 
					
						
							|  |  |  |      * (来源商家表中的代理商) | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |      * | 
					
						
							|  |  |  |      * $size 0 表示不分页,获取所有数据 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getAgencyList(): Json | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $page = $this->request->param('page/d', 1); | 
					
						
							|  |  |  |             $size = $this->request->param('size/d', 10); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $whereMap   = []; | 
					
						
							|  |  |  |             $whereMap[] = ['is_agency', '=', self::BOOL_TRUE]; | 
					
						
							|  |  |  |             $whereMap[] = ['is_delete', '=', self::BOOL_FALSE]; | 
					
						
							|  |  |  |             $whereMap[] = ['state', '=', BusinessModel::state_on]; | 
					
						
							|  |  |  |             $whereMap[] = ['enable', '=', self::BOOL_FALSE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $sortOrder  = ['id'=>"asc"]; | 
					
						
							|  |  |  |             $fields = ['id', 'code', 'business_name', 'business_subtitle', 'business_license', | 
					
						
							|  |  |  |                 'lat', 'lng', 'business_address', 'contact_name', 'contact_phone', | 
					
						
							|  |  |  |                 'create_time', 'type', 'type_name', 'characteristic', 'intro', | 
					
						
							| 
									
										
										
										
											2021-11-30 18:52:02 +08:00
										 |  |  |                 'business_circle', 'business_circle_id', 'background', 'score', | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  |             ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $repo   = BusinessRepository::getInstance(); | 
					
						
							|  |  |  |             $res    = $repo->findList($whereMap, $fields, $page, $size, null, $sortOrder); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $this->json(0 , 'success', $res); | 
					
						
							|  |  |  |         } catch (RepositoryException | \Exception $e) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $this->json(0 , 'success', []); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * 获取商家分类 | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getBusinessTypeList(): Json | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-29 16:43:47 +08:00
										 |  |  |         $pid    = $this->request->param('pid/d', 0); | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 16:43:47 +08:00
										 |  |  |         $whereMap   = []; | 
					
						
							|  |  |  |         if ($pid > 0) { | 
					
						
							|  |  |  |             $whereMap[] = ['pid', '=', $pid]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $repo       = DictionaryRepository::getInstance(); | 
					
						
							|  |  |  |         $items      = $repo->getBusinessTypeList($whereMap, [], null, ['pid'=>'asc']); | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 16:43:47 +08:00
										 |  |  |         $list       = $items->toArray(); | 
					
						
							| 
									
										
										
										
											2021-12-02 11:01:51 +08:00
										 |  |  |         $list       = $repo->recursionChildrenList($list, $pid, 'pid', 'id'); | 
					
						
							| 
									
										
										
										
											2021-11-29 16:34:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this->json(0, 'success', $list); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取优惠卷类型列表 | 
					
						
							|  |  |  |      * @return Json | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getCouponTypeList(): Json | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $items = CouponRepository::getInstance()->getCouponTypeAll(['id', 'name'],['id'=>'asc']); | 
					
						
							|  |  |  |         return $this->json(0, 'success', $items); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 13:59:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |