diff --git a/app/api/controller/dealer/Apply.php b/app/api/controller/dealer/Apply.php index f9937ce4..0f3c3fb0 100644 --- a/app/api/controller/dealer/Apply.php +++ b/app/api/controller/dealer/Apply.php @@ -12,11 +12,15 @@ declare (strict_types=1); namespace app\api\controller\dealer; -use think\response\Json; use app\api\controller\Controller; -use app\api\model\dealer\User as DealerUserModel; use app\api\model\dealer\Apply as DealerApplyModel; +use app\api\model\dealer\User as DealerUserModel; use app\api\service\User as UserService; +use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\response\Json; /** * 分销商申请 @@ -28,7 +32,7 @@ class Apply extends Controller /** * 分销商申请状态 * @return Json - * @throws \cores\exception\BaseException + * @throws BaseException */ public function status(): Json { @@ -45,10 +49,10 @@ class Apply extends Controller /** * 提交分销商申请 * @return Json - * @throws \cores\exception\BaseException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException */ public function submit(): Json { @@ -58,4 +62,44 @@ class Apply extends Controller } return $this->renderError($model->getError() ?: '提交失败'); } + + /** + * @notes:申请服务商 + * @return Json + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function applyProviders(): Json + { + $real_name = $this->request->post('real_name'); + if (!$real_name) { + return $this->renderError('联系人不能为空'); + } + $mobile = $this->request->post('mobile'); + if (empty($mobile)) { + return $this->renderError('联系电话不能为空'); + } + $shop_type = intval($this->request->post('shop_type', 10)); + $shop_name = $this->request->post('shop_name'); + if (empty($shop_name)) { + return $this->renderError('店铺名称不能为空'); + } + $business = $this->request->post('business'); + if (empty($business)) { + return $this->renderError('经营类型不能为空'); + } + $city = $this->request->post('city'); + if (empty($city)) { + return $this->renderError('所在城市不能为空'); + } + $data = compact('business', 'city', 'real_name', 'mobile', 'shop_type', 'shop_name', 'business', 'city'); + $model = new DealerApplyModel; + if ($model->applyServiceProviders($data)) { + return $this->renderSuccess('提交成功'); + } + return $this->renderError($model->getError() ?: '提交失败'); + } } \ No newline at end of file diff --git a/app/api/model/dealer/Apply.php b/app/api/model/dealer/Apply.php index e671aa26..a91d853a 100644 --- a/app/api/model/dealer/Apply.php +++ b/app/api/model/dealer/Apply.php @@ -13,10 +13,13 @@ declare (strict_types=1); namespace app\api\model\dealer; use app\api\service\User as UserService; -use app\common\enum\dealer\apply\ApplyType as ApplyTypeEnum; use app\common\enum\dealer\apply\ApplyStatus as ApplyStatusEnum; +use app\common\enum\dealer\apply\ApplyType as ApplyTypeEnum; use app\common\model\dealer\Apply as ApplyModel; use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; /** * 分销商申请模型 @@ -50,9 +53,9 @@ class Apply extends ApplyModel * @param array $data 表单数据 * @return mixed * @throws \cores\exception\BaseException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException * @throws BaseException */ public function submit(array $data) @@ -79,6 +82,47 @@ class Apply extends ApplyModel return $this->add($data); } + /** + * @notes:申请服务商 + * @param $data + * @return bool + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function applyServiceProviders($data): bool + { + // 当前用户ID + $userId = UserService::getCurrentLoginUserId(); + // 成为分销商条件 + $config = Setting::getItem('condition'); + if ($this->where(['user_id' => $userId])->exists()) { + throwError('您已申请服务商,请勿重复提交'); + } + // 数据整理 + $data = [ + 'user_id' => $userId, + 'real_name' => trim($data['real_name']), + 'mobile' => trim($data['mobile']), + 'referee_id' => Referee::getRefereeUserId($userId, 1), + 'apply_type' => $config['become'], + 'apply_time' => time(), + 'store_id' => self::$storeId, + 'shop_type' => $data['shop_type'], + 'shop_name' => $data['shop_name'], + 'business' => $data['business'], + 'city' => $data['city'], + ]; + if ($config['become'] == ApplyTypeEnum::AUDIT) { + $data['apply_status'] = ApplyStatusEnum::WAIT; + } elseif ($config['become'] == ApplyTypeEnum::PASS) { + $data['apply_status'] = ApplyStatusEnum::PASS; + } + return $this->add($data); + } + /** * 更新分销商申请信息 * @param array $data