diff --git a/app/common.php b/app/common.php index 2696ec0..74a2cb2 100644 --- a/app/common.php +++ b/app/common.php @@ -580,18 +580,18 @@ if (!function_exists('arrayNullToString')) { * 数组|或数据集中null值转为空字符串,并以数组格式返回 * 通常用于api json 返回内容null转换 * - * @param array $data 【array|collection】 + * @param $data * @return array */ function arrayNullToString($data) { - if ($data instanceof Collection) { + if ($data instanceof Collection || $data instanceof Model) { $data = $data->toArray(); } // 判断是否可以遍历 if (is_iterable($data)) { foreach ($data as $key => $val) { - if ($val instanceof Collection) { + if ($val instanceof Collection || $data instanceof Model) { $val = $val->toArray(); } if (is_iterable($val)) { @@ -606,7 +606,6 @@ if (!function_exists('arrayNullToString')) { return $data; } } - if (!function_exists('arrayKeysExcludeFilter')) { /** * 一维数组键名排除过滤 diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index c864b28..3b09220 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -109,8 +109,12 @@ class Business extends Base } if (!empty($params['agency_code'])) { - $agencyBusiness = $busRepo->findOneByWhere(['code'=> $params['agency_code'], 'is_agency'=> self::BOOL_TRUE, 'state' => BusinessModel::state_on]); - if (empty($agencyBusiness) || $agencyBusiness['is_delete'] == self::BOOL_TRUE) { + $agencyBusiness = $busRepo->findOneByWhere([ + ['code',"=", $params['agency_code']], + ['is_agency',"=", BusinessModel::COMMON_ON], + [ 'state' ,"=", BusinessModel::state_on] + ]); + if (empty($agencyBusiness)) { throw new ValidateException('没有相关的代理商记录!'); } elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) { throw new ValidateException('该代理商已被封禁!'); diff --git a/app/controller/api/Dictionary.php b/app/controller/api/Dictionary.php index ecd3d81..492e970 100644 --- a/app/controller/api/Dictionary.php +++ b/app/controller/api/Dictionary.php @@ -6,9 +6,7 @@ use app\repository\BusinessRepository; use app\repository\CouponRepository; use app\repository\DictionaryRepository; use think\response\Json; -use app\model\{ - Business as BusinessModel -}; +use app\model\{Business as BusinessModel, Member}; /** * APP 数据字典 @@ -81,28 +79,9 @@ class Dictionary extends Base 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', - 'business_circle', 'business_circle_id', 'background', 'score', - ]; - - $repo = BusinessRepository::getInstance(); - $res = $repo->findList($whereMap, $fields, $page, $size, null, $sortOrder); - - return $this->json(0 , 'success', $res); + $data = Member::getAgentAll(); + return $this->json(0 , 'success', $data); } catch (RepositoryException | \Exception $e) { - return $this->json(0 , 'success', []); } } diff --git a/app/controller/manager/Agency.php b/app/controller/manager/Agency.php index bf88441..62ee95e 100644 --- a/app/controller/manager/Agency.php +++ b/app/controller/manager/Agency.php @@ -234,6 +234,10 @@ class Agency extends Base Db::rollback(); return $this->json(4001, "指定商家不存在"); } + if($business->is_agency == BusinessModel::COMMON_ON){ + Db::rollback(); + return $this->json(4001, "该商家已经是代理商,不能重复绑定"); + } $business->save(["is_agency" => BusinessModel::COMMON_ON]); }