合并冲突
commit
8999c4d911
|
@ -9,7 +9,11 @@ use app\repository\BusinessRepository;
|
|||
use app\repository\DictionaryRepository;
|
||||
use app\validate\BusinessValidate;
|
||||
use think\exception\ValidateException;
|
||||
use app\model\Business as BusinessModel;
|
||||
use app\model\{
|
||||
Business as BusinessModel,
|
||||
Account as AccountModel
|
||||
};
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 商家端:商家
|
||||
|
@ -20,14 +24,11 @@ use app\model\Business as BusinessModel;
|
|||
class Business extends Base
|
||||
{
|
||||
/**
|
||||
* 商家注册
|
||||
*
|
||||
* 方式1:注册为自然商家
|
||||
* 由系统后台工作人员审核
|
||||
* 商家认证注册
|
||||
*
|
||||
* 重新编辑注册则覆盖之前的审核信息,并重新进行审核
|
||||
*/
|
||||
public function registerByNormal()
|
||||
public function registerBusiness()
|
||||
{
|
||||
$params = [
|
||||
'type'=> $this->request->param('type/d', 0),
|
||||
|
@ -43,6 +44,7 @@ class Business extends Base
|
|||
'county'=> $this->request->param('county', ''),
|
||||
'business_address' => $this->request->param('business_address', ''),
|
||||
'business_circle_id' => $this->request->param('business_circle_id/d', 0),
|
||||
'agency_code' => $this->request->param('agency_code', ''),
|
||||
];
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
@ -59,7 +61,7 @@ class Business extends Base
|
|||
throw new ValidateException('无效请求!');
|
||||
}
|
||||
|
||||
if (!$validate->scene('registerByNormal')->check($params)) {
|
||||
if (!$validate->scene('apiRegister')->check($params)) {
|
||||
throw new ValidateException($validate->getError());
|
||||
}
|
||||
|
||||
|
@ -76,6 +78,15 @@ class Business extends Base
|
|||
$params['business_circle'] = $businessCircle['name'];
|
||||
}
|
||||
|
||||
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) {
|
||||
throw new ValidateException('没有相关的代理商记录!');
|
||||
} elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) {
|
||||
throw new ValidateException('该代理商已被封禁!');
|
||||
}
|
||||
}
|
||||
|
||||
$business = null;
|
||||
if (isset($account['business_code']) && !empty($account['business_code'])) {
|
||||
$business = $busRepo->findOneByWhere(['code'=> $account['business_code']]);
|
||||
|
@ -118,110 +129,78 @@ class Business extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* 商家注册
|
||||
*
|
||||
* 方式2:注册为平台代理商下的商家
|
||||
* 由平台代理商工作人员审核
|
||||
*
|
||||
* 重新编辑注册则覆盖之前的审核信息,并重新进行审核
|
||||
* 获取当前账号所属商家的信息
|
||||
* 适用范围:商户账号 或 商户员工账号
|
||||
*/
|
||||
public function registerByAgency()
|
||||
public function getMyBusinessInfo()
|
||||
{
|
||||
$params = [
|
||||
'type'=> $this->request->param('type/d', 0),
|
||||
'business_name'=> $this->request->param('business_name', ''),
|
||||
'business_subtitle'=> $this->request->param('business_subtitle', ''),
|
||||
'business_license'=> $this->request->param('business_license', ''),
|
||||
'contact_name'=> $this->request->param('contact_name', ''),
|
||||
'contact_phone'=> $this->request->param('contact_phone', ''),
|
||||
'lat'=> $this->request->param('lat', ''),
|
||||
'lng'=> $this->request->param('lng', ''),
|
||||
'province'=> $this->request->param('province', ''),
|
||||
'city'=> $this->request->param('city', ''),
|
||||
'county'=> $this->request->param('county', ''),
|
||||
'business_address' => $this->request->param('business_address', ''),
|
||||
'business_circle_id' => $this->request->param('business_circle_id/d', 0),
|
||||
'agency_code' => $this->request->param('agency_code', ''),
|
||||
];
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
try {
|
||||
$validate = new BusinessValidate();
|
||||
$busRepo = BusinessRepository::getInstance();
|
||||
$dicRepo = DictionaryRepository::getInstance();
|
||||
$accountRepo = AccountRepository::getInstance();
|
||||
|
||||
$account = $accountRepo->findById($accountId);
|
||||
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business', 'parent']);
|
||||
});
|
||||
if (empty($account)) {
|
||||
throw new ValidateException('无效请求!');
|
||||
return $this->json(4004, '无效请求!');
|
||||
}
|
||||
|
||||
if (!$validate->scene('registerByAgency')->check($params)) {
|
||||
throw new ValidateException($validate->getError());
|
||||
}
|
||||
|
||||
$businessCategory = $dicRepo->findBusinessTypeById($params['type']);
|
||||
if (empty($businessCategory)) {
|
||||
throw new ValidateException('请选择正确的商家分类信息!');
|
||||
}
|
||||
|
||||
if ($params['business_circle_id'] > 0) {
|
||||
$businessCircle = $dicRepo->findBusinessCircleById($params['business_circle_id']);
|
||||
if (empty($businessCircle)) {
|
||||
throw new ValidateException('请选择正确的商圈信息!');
|
||||
}
|
||||
$params['business_circle'] = $businessCircle['name'];
|
||||
}
|
||||
|
||||
$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) {
|
||||
throw new ValidateException('没有相关的平台商记录!');
|
||||
} elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) {
|
||||
throw new ValidateException('该平台商已被封禁!');
|
||||
}
|
||||
|
||||
$business = null;
|
||||
if (isset($account['business_code']) && !empty($account['business_code'])) {
|
||||
$business = $busRepo->findOneByWhere(['code'=> $account['business_code']]);
|
||||
}
|
||||
|
||||
$params['create_time'] = date('Y-m-d H:i:s');
|
||||
$params['is_delete'] = 0;
|
||||
$params['state'] = BusinessModel::state_reviewing;
|
||||
$params['enable'] = 0;
|
||||
$params['type_name'] = $businessCategory['name'];
|
||||
|
||||
if ($business) {
|
||||
if ($business['state'] == BusinessModel::state_reviewing) {
|
||||
throw new ValidateException('商户认证审批中,请勿重复提交!');
|
||||
$result = [];
|
||||
if ($account['type'] == AccountModel::type_staff) {
|
||||
// 员工账号
|
||||
$businessCode = $account['parent']['business_code'] ?? '';
|
||||
if (!empty($businessCode)) {
|
||||
$business = BusinessRepository::getInstance()->findOneByWhere(['code' => $businessCode]);
|
||||
if ($business) {
|
||||
$result = $business->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新审批信息,重新审批
|
||||
$params['update_time'] = date('Y-m-d H:i:s');
|
||||
$business = $business->save($params);
|
||||
$result = arrayKeysExcludeFilter($result, ['pay_account', 'total_recharge']);
|
||||
|
||||
} else {
|
||||
// 添加审批记录
|
||||
$businessCode = createUuid();
|
||||
$params['code'] = $businessCode;
|
||||
$business = $busRepo->create($params);
|
||||
if (!$business) {
|
||||
throw new RepositoryException('服务器繁忙!商户认证申请提交失败!');
|
||||
}
|
||||
|
||||
$account->save(['business_code' => $businessCode]);
|
||||
} elseif(!empty($account['business'])) {
|
||||
// 商户认证信息
|
||||
$result = $account['business']->toArray();
|
||||
}
|
||||
|
||||
$result = $busRepo->formatFrontBusinessInfo($business->toArray(), [2]);
|
||||
if (count($result)) {
|
||||
$result = DictionaryRepository::getInstance()->parseAreaText($result);
|
||||
}
|
||||
|
||||
$result = arrayKeysExcludeFilter($result, ['update_time']);
|
||||
return $this->json(0, 'success', $result);
|
||||
} catch (ValidateException $e) {
|
||||
return $this->json(4001, $e->getError());
|
||||
} catch (RepositoryException | \Exception $e) {
|
||||
return $this->json(5001, '服务器繁忙!商户认证申请提交失败!');
|
||||
} catch (\Exception $e) {
|
||||
return $this->json(5001, '商家信息查询失败!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商家信息(已认证通过的商户)
|
||||
* @return Json
|
||||
*/
|
||||
public function getBusinessInfo()
|
||||
{
|
||||
$businessCode = $this->request->param('businessCode/s', '');
|
||||
|
||||
$busRepo = BusinessRepository::getInstance();
|
||||
try {
|
||||
$business = $busRepo->findOneByWhere(['code' => $businessCode, 'state' => BusinessModel::state_on]);
|
||||
if (empty($business)) {
|
||||
return $this->json(4004, '没有相关的商户!');
|
||||
}
|
||||
|
||||
$list = $business->toArray();
|
||||
$list = DictionaryRepository::getInstance()->parseAreaText($list);
|
||||
$disableFields = ['is_delete', 'update_time', 'total_recharge', 'balance', 'is_assign', 'agency_code',
|
||||
'reason', 'pay_account', 'business_license'
|
||||
];
|
||||
$result = arrayKeysExcludeFilter($list, $disableFields);
|
||||
return $this->json(0, 'success', $result);
|
||||
} catch (\Exception $e) {
|
||||
return $this->json(5004, '商家信息查询失败!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商家类型
|
||||
* */
|
||||
|
@ -239,3 +218,5 @@ class Business extends Base
|
|||
return $this->json(1,"ok",$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,19 +42,18 @@ class Consumer extends Base
|
|||
try {
|
||||
$repo = CouponRepository::getInstance();
|
||||
$nowDate = date('Y-m-d H:i:s');
|
||||
$sumPoint = $params['lng'] + $params['lat'];
|
||||
|
||||
|
||||
$lngRange = [];
|
||||
$latRange = [];
|
||||
$whereMap = [];
|
||||
$sortOrder = ['square'=> 'asc', 'start_time'=>'asc'];
|
||||
|
||||
// $whereMap[] = ['status', '=', CouponMain::status_on];
|
||||
// $whereMap[] = ['on_shelf', '=', CouponMain::on_shelf_on];
|
||||
// $whereMap[] = ['start_time', '> TIME', $nowDate];
|
||||
// $whereMap[] = ['end_time', '< TIME', $nowDate];
|
||||
// $whereMap[] = ['using_count', '>', 0];
|
||||
$whereMap[] = ['id', '>', 300];
|
||||
$whereMap[] = ['status', '=', CouponMain::status_on];
|
||||
$whereMap[] = ['on_shelf', '=', CouponMain::on_shelf_on];
|
||||
$whereMap[] = ['start_time', '> TIME', $nowDate];
|
||||
$whereMap[] = ['end_time', '< TIME', $nowDate];
|
||||
$whereMap[] = ['using_count', '>', 0];
|
||||
|
||||
if (!empty($params['keyword'])) {
|
||||
$whereMap[] = ['name', 'like', "%{$params['keyword']}%"];
|
||||
|
|
|
@ -112,7 +112,6 @@ class Dictionary extends Base
|
|||
*/
|
||||
public function getBusinessTypeList(): Json
|
||||
{
|
||||
$recursionChildren = $this->request->param('recursion/d', 0);
|
||||
$pid = $this->request->param('pid/d', 0);
|
||||
|
||||
$whereMap = [];
|
||||
|
@ -124,9 +123,7 @@ class Dictionary extends Base
|
|||
$items = $repo->getBusinessTypeList($whereMap, [], null, ['pid'=>'asc']);
|
||||
|
||||
$list = $items->toArray();
|
||||
if ($recursionChildren > 0) {
|
||||
$list = $repo->recursionChildrenList($list, $pid, 'pid', 'id');
|
||||
}
|
||||
$list = $repo->recursionChildrenList($list, $pid, 'pid', 'id');
|
||||
|
||||
return $this->json(0, 'success', $list);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace app\controller\api;
|
|||
use app\exception\RepositoryException;
|
||||
use app\model\Account;
|
||||
use app\repository\AccountRepository;
|
||||
use app\repository\BusinessRepository;
|
||||
use app\repository\CouponRepository;
|
||||
use app\service\File;
|
||||
use app\service\Jwt;
|
||||
|
@ -132,6 +133,7 @@ class User extends Base
|
|||
try {
|
||||
$accountRepo = AccountRepository::getInstance();
|
||||
$couponRepo = CouponRepository::getInstance();
|
||||
$busRepo = BusinessRepository::getInstance();
|
||||
|
||||
$account = $accountRepo->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business', 'parent']);
|
||||
|
@ -174,26 +176,44 @@ class User extends Base
|
|||
'couponCount' => $couponCount,
|
||||
];
|
||||
|
||||
// 商户认证记录
|
||||
if (!empty($account['business'])) {
|
||||
|
||||
if ($account['type'] == Account::type_staff) {
|
||||
// 员工
|
||||
$businessCode = $account['parent']['business_code'] ?? '';
|
||||
if (!empty($businessCode)) {
|
||||
$business = $busRepo->findOneByWhere(['code' => $businessCode]);
|
||||
if ($business) {
|
||||
$personalRes['business'] = [
|
||||
'code' => $business['code'],
|
||||
'businessName' => $business['business_name'],
|
||||
'state' => $business['state'],
|
||||
'reason' => $business['reason'],
|
||||
'balance' => $business['balance'],
|
||||
'enable' => $business['enable'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$personalRes['parent'] = [];
|
||||
if (!empty($account['parent'])) {
|
||||
$personalRes['parent'] = [
|
||||
'avatar' => File::convertCompleteFileUrl($account['parent']['avatar_url']),
|
||||
'nickName' => $account['parent']['nick_name'],
|
||||
'userType' => $account['parent']['type'],
|
||||
'userTypeDes' => Account::accountTypeDescList()[$account['parent']['type']] ?? '',
|
||||
'couponCount' => 0,
|
||||
'businessCode' => $account['parent']['business_code'],
|
||||
];
|
||||
}
|
||||
|
||||
} elseif(!empty($account['business'])) {
|
||||
// 商户认证记录
|
||||
$personalRes['business'] = [
|
||||
'state' => $account['business']['state'],
|
||||
'reason' => $account['business']['reason'],
|
||||
];
|
||||
}
|
||||
|
||||
// 员工
|
||||
if ($account['type'] == Account::type_staff && !empty($account['parent'])) {
|
||||
$personalRes['parent'] = [
|
||||
'avatar' => File::convertCompleteFileUrl($account['parent']['avatar_url']),
|
||||
'nickName' => $account['parent']['nick_name'],
|
||||
'userType' => $account['parent']['type'],
|
||||
'userTypeDes' => Account::accountTypeDescList()[$account['parent']['type']] ?? '',
|
||||
'couponCount' => 0,
|
||||
'businessCode' => $account['parent']['business_code'],
|
||||
];
|
||||
}
|
||||
|
||||
return $this->json(0, 'success', $personalRes);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Business extends Base
|
|||
const state_off = 2;
|
||||
|
||||
/**
|
||||
* @remarks 代理商、平台代理商、渠道商等词组均描述的是平台商,因此文案统一为【平台商】
|
||||
* @remarks 代理商、平台商、平台代理商、渠道商等词组均描述的是代理商,因此文案统一为【代理商】
|
||||
*/
|
||||
|
||||
public function category()
|
||||
|
@ -19,21 +19,14 @@ class Business extends Base
|
|||
return $this->hasOne(Category::class, 'id',"type");
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的平台商
|
||||
*
|
||||
* @return HasOne
|
||||
*/
|
||||
public function agency()
|
||||
{
|
||||
return $this->hasOne(self::class,"code","agency_code");
|
||||
}
|
||||
|
||||
|
||||
public function account()
|
||||
{
|
||||
return $this->hasOne(Account::class, 'business_code',"code");
|
||||
}
|
||||
|
||||
public function agency()
|
||||
{
|
||||
return $this->hasOne(self::class,"code","agency_code");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
namespace app\repository;
|
||||
|
||||
|
||||
use app\model\Area;
|
||||
use app\model\BusinessCircle;
|
||||
use app\model\Category;
|
||||
use app\model\Model;
|
||||
|
@ -100,4 +101,52 @@ class DictionaryRepository extends Repository
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 省市区地址配置数据
|
||||
*/
|
||||
public function findAreaList(array $where = [])
|
||||
{
|
||||
try {
|
||||
return Area::where($where)->select();
|
||||
} catch (\Exception $e) {
|
||||
return new Collection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过地址编号查询地址信息
|
||||
* @param string $areaCode
|
||||
* @return Area|array|\think\Model|null
|
||||
*/
|
||||
public function findAreaInfo(string $areaCode)
|
||||
{
|
||||
try {
|
||||
return Area::where('code', $areaCode)->find();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析地址编码
|
||||
* [province, city, county]
|
||||
*/
|
||||
public function parseAreaText(array $list, array $areaList = []): array
|
||||
{
|
||||
if (empty($list)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (empty($areaList)) {
|
||||
$areaList = $this->findAreaList()->column('name', 'code');
|
||||
}
|
||||
|
||||
$list['province_text'] = (!isset($list['province']) || empty($list['province'])) ? '' : ($areaList[$list['province']] ?? '');
|
||||
$list['city_text'] = (!isset($list['city']) || empty($list['city'])) ? '' : ($areaList[$list['city']] ?? '');
|
||||
$list['county_text'] = (!isset($list['county']) || empty($list['county'])) ? '' : ($areaList[$list['county']] ?? '');
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,6 @@ class BusinessValidate extends Validate
|
|||
'background|商家背景图' => 'max:250',
|
||||
'business_circle_id' => 'egt:0',
|
||||
|
||||
'agency_code' => 'require|length:32',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
|
@ -38,18 +37,13 @@ class BusinessValidate extends Validate
|
|||
'lng.between' => '地址定位信息错误,请重新定位!',
|
||||
|
||||
'business_circle_id.egt' => '请选择所属商圈!',
|
||||
'agency_code.require' => '请选择需要加入的商家!',
|
||||
'agency_code.length' => '加入的商家参数错误!',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
// 认证商家
|
||||
'registerByNormal' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone',
|
||||
'apiRegister' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone',
|
||||
'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id'],
|
||||
// 加入平台代理商
|
||||
'registerByAgency' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone',
|
||||
'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id', 'agency_code'],
|
||||
// 商家编辑可编辑资料(基本信息修改需要审核通过后才能变更)
|
||||
'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'],
|
||||
'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'],
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue