diff --git a/app/common/repositories/marketing/AgentRepository.php b/app/common/repositories/marketing/AgentRepository.php index 8f8f354..864f000 100644 --- a/app/common/repositories/marketing/AgentRepository.php +++ b/app/common/repositories/marketing/AgentRepository.php @@ -138,7 +138,8 @@ class AgentRepository extends BaseRepository{ "address", "lat", "lng", - "mer_id" + "mer_id", + 'is_headquarters' ]); $updateInfo = array_intersect_key($data, $keys); Agent::update($updateInfo,['id'=>$agentId]); @@ -178,7 +179,8 @@ class AgentRepository extends BaseRepository{ "address", "lat", "lng", - "mer_id" + "mer_id", + 'is_headquarters' ]); // 循环:区分对应的操作 foreach($childrenList as $childrenItem){ diff --git a/app/controller/admin/marketing/Agent.php b/app/controller/admin/marketing/Agent.php index 003caff..48bff0a 100644 --- a/app/controller/admin/marketing/Agent.php +++ b/app/controller/admin/marketing/Agent.php @@ -64,6 +64,7 @@ class Agent extends BaseController{ 'lng', ['mer_id', 0], ['mer_id_list', []], + ['is_headquarters', 0] ]); $agentId = (int)$this->request->param('id'); $childrenList = $this->request->param('children_list'); @@ -86,21 +87,21 @@ class Agent extends BaseController{ case 2: case 3: case 4: - if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 5: case 6: - if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 7: - if((float)$childrenItem['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['street_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if(empty($childrenItem['address'])) throw new ValidateException('请完善地区信息!'); - if((float)$childrenItem['lat'] <= 0 || (float)$childrenItem['lng'] <= 0) throw new ValidateException('请选择定位信息!'); + if((float)$childrenItem['province_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['city_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['area_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$childrenItem['street_id'] <= 0 && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if(empty($childrenItem['address']) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if(((float)$childrenItem['lat'] <= 0 || (float)$childrenItem['lng'] <= 0) && $childrenItem['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); if((float)$childrenItem['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); break; case 8: @@ -147,21 +148,21 @@ class Agent extends BaseController{ case 2: case 3: case 4: - if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 5: case 6: - if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); break; case 7: - if((float)$data['province_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['city_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['area_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if((float)$data['street_id'] <= 0) throw new ValidateException('请完善地区信息!'); - if(empty($data['address'])) throw new ValidateException('请完善地区信息!'); - if((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0) throw new ValidateException('请选择定位信息!'); + if((float)$data['province_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['city_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['area_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if((float)$data['street_id'] <= 0 && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if(empty($data['address']) && $data['is_headquarters'] == 0) throw new ValidateException('请完善地区信息!'); + if(((float)$data['lat'] <= 0 || (float)$data['lng'] <= 0) && $data['is_headquarters'] == 0) throw new ValidateException('请选择定位信息!'); if((float)$data['mer_id'] <= 0) throw new ValidateException('餐厅必须关联商户!'); break; case 8: diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index e252137..bdd9758 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -147,14 +147,18 @@ class Merchant extends BaseController return app('json')->fail('商户名已存在'); if ($data['mer_phone'] && isPhone($data['mer_phone'])) return app('json')->fail('请输入正确的手机号'); - if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) + if ((!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) && $data['merchant_type'] == 0) return app('json')->fail('商户分类不存在'); unset($data['mer_account'], $data['mer_password']); - $margin = $this->repository->checkMargin($id, $data['type_id']); - $data['margin'] = $margin['margin']; - $data['is_margin'] = $margin['is_margin']; - $data['ot_margin'] = $margin['ot_margin']; + $typeId = $data['type_id'] ?? 0; + if($typeId > 0){ + $margin = $this->repository->checkMargin($id, $data['type_id']); + $data['margin'] = $margin['margin'] ?? 0; + $data['is_margin'] = $margin['is_margin'] ?? 0; + $data['ot_margin'] = $margin['ot_margin'] ?? 0; + } + $this->repository->update($id, $data); return app('json')->success('编辑成功'); } diff --git a/app/validate/admin/MerchantValidate.php b/app/validate/admin/MerchantValidate.php index 2d3a8c1..f66a0cb 100644 --- a/app/validate/admin/MerchantValidate.php +++ b/app/validate/admin/MerchantValidate.php @@ -25,8 +25,8 @@ class MerchantValidate extends Validate * @var array */ protected $rule = [ - 'category_id|商户分类' => 'require', - 'type_id|店铺类型' => 'integer', + // 'category_id|商户分类' => 'require', + // 'type_id|店铺类型' => 'integer', 'mer_name|商户名称' => 'require|max:32', 'mer_account|商户账号' => 'require|alphaNum|min:4|max:16', 'mer_password|商户密码' => 'require|min:4|max:16',