diff --git a/app/api/controller/Wholesaler.php b/app/api/controller/Wholesaler.php index a32f0b18..fbf6bf72 100644 --- a/app/api/controller/Wholesaler.php +++ b/app/api/controller/Wholesaler.php @@ -2,6 +2,7 @@ namespace app\api\controller; +use app\api\model\wholesaler\Apply; use app\api\model\wholesaler\Set; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; @@ -125,4 +126,96 @@ class Wholesaler extends Controller return $this->renderSuccess($data, $service->getMessage() ?: '申请成功'); } + /** + * @notes:申请记录详情 + * @return Json + * @throws BaseException + * @author: wanghousheng + */ + public function applyInfo(): Json + { + $info = Apply::info(['cardFrontImg', 'cardBackImg', 'licenseImg', 'doorImg']); + if (!empty($info->cardFrontImg)) { + unset($info->cardFrontImg); + } + if (!empty($info->cardBackImg)) { + unset($info->cardBackImg); + } + if (!empty($info->licenseImg)) { + unset($info->licenseImg); + } + if (!empty($info->doorImg)) { + unset($info->doorImg); + } + return $this->renderSuccess(compact('info')); + } + + /** + * @notes:编辑申请记录 + * @return Json + * @throws BaseException + * @author: wanghousheng + */ + public function editApply(): Json + { + $username = $this->request->post('username'); + if (!$username) { + return $this->renderError('姓名不能为空'); + } + $mobile = $this->request->post('mobile'); + if (!$mobile) { + return $this->renderError('手机号不能为空'); + } + $mobile_code = $this->request->post('mobile_code'); + if (!$mobile_code) { + return $this->renderError('手机号验证码不能为空'); + } + $card_front_img_id = intval($this->request->post('card_front_img_id')); + if (!$card_front_img_id) { + return $this->renderError('身份证正面不能为空'); + } + $card_back_img_id = intval($this->request->post('card_back_img_id')); + if (!$card_back_img_id) { + return $this->renderError('身份证反面不能为空'); + } + $license_img_id = intval($this->request->post('license_img_id')); + if (!$license_img_id) { + return $this->renderError('营业执照不能为空'); + } + $card_no = $this->request->post('card_no'); + if (!$card_no) { + return $this->renderError('身份证号不能为空'); + } + $door_img_id = intval($this->request->post('door_img_id')); + if (!$door_img_id) { + return $this->renderError('门口照片不能为空'); + } + $province_id = intval($this->request->post('province_id')); + if (!$province_id) { + return $this->renderError('省份不能为空'); + } + $city_id = intval($this->request->post('city_id')); + if (!$city_id) { + return $this->renderError('城市不能为空'); + } + $company_name = $this->request->post('company_name'); + if (!$company_name) { + return $this->renderError('公司名称不能为空'); + } + $credit_code = $this->request->post('credit_code'); + if (!$credit_code) { + return $this->renderError('社会信用代码不能为空'); + } + $business = $this->request->post('business'); + if (!$business) { + return $this->renderError('经营类目不能为空'); + } + $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no'); + $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); + if ((new Apply())->edit($data)) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError('操作失败'); + } + } \ No newline at end of file diff --git a/app/api/model/wholesaler/Apply.php b/app/api/model/wholesaler/Apply.php index 15e6d875..83037f27 100644 --- a/app/api/model/wholesaler/Apply.php +++ b/app/api/model/wholesaler/Apply.php @@ -2,6 +2,10 @@ namespace app\api\model\wholesaler; +use app\api\service\User as UserService; +use app\common\enum\WholesalerEnum; +use cores\exception\BaseException; + class Apply extends \app\common\model\wholesaler\Apply { /** @@ -12,6 +16,9 @@ class Apply extends \app\common\model\wholesaler\Apply 'create_time', 'update_time', 'store_id', + 'id', + 'order_id', + 'year' ]; /** @@ -24,4 +31,37 @@ class Apply extends \app\common\model\wholesaler\Apply { return $this->save($data); } + + /** + * @notes:详情 + * @throws BaseException + * @author: wanghousheng + */ + public static function info($with = []) + { + $userId = UserService::getCurrentLoginUserId(); + return self::detail(['user_id' => $userId], $with); + } + + /** + * @notes:更新记录 + * @param array $data + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function edit(array $data): bool + { + $info = self::info(); + empty($info) && throwError('申请记录不存在'); + $info = $info->toArray(); + if ($info['status'] == WholesalerEnum::ADOPT) { + throwError('申请已通过无法编辑'); + } + $userId = UserService::getCurrentLoginUserId(); + if ($this->where(['user_id' => $userId])->update($data)) { + return true; + } + return false; + } } \ No newline at end of file diff --git a/app/common/enum/WholesalerEnum.php b/app/common/enum/WholesalerEnum.php new file mode 100644 index 00000000..422d7c30 --- /dev/null +++ b/app/common/enum/WholesalerEnum.php @@ -0,0 +1,35 @@ + [ + 'name' => '待审核', + 'value' => self::AUDITING, + ], + self::ADOPT => [ + 'name' => '已通过', + 'value' => self::ADOPT, + ], + self::REFUSE => [ + 'name' => '已拒绝', + 'value' => self::REFUSE, + ], + ]; + } +} \ No newline at end of file diff --git a/app/common/model/wholesaler/Apply.php b/app/common/model/wholesaler/Apply.php index 00c9df5e..8e00df78 100644 --- a/app/common/model/wholesaler/Apply.php +++ b/app/common/model/wholesaler/Apply.php @@ -2,7 +2,14 @@ namespace app\common\model\wholesaler; +use app\common\enum\WholesalerEnum; +use app\common\model\Region as RegionModel; +use app\common\model\UploadFile; use cores\BaseModel; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; +use think\model\relation\HasOne; class Apply extends BaseModel { @@ -12,8 +19,81 @@ class Apply extends BaseModel // 定义主键 protected $pk = 'id'; - public static function detail($where) + protected $append = ['region', 'status_text']; + + public static function detail($where, $with = []) + { + return static::get($where, $with); + } + + + /** + * 身份证正面图片 + * @return HasOne + */ + public function cardFrontImg(): HasOne + { + return $this->hasOne(UploadFile::class, 'file_id', 'card_front_img_id') + ->bind(['card_front_img' => 'preview_url']); + } + + /** + * 身份证反面图片 + * @return HasOne + */ + public function cardBackImg(): HasOne + { + return $this->hasOne(UploadFile::class, 'file_id', 'card_back_img_id') + ->bind(['card_back_img' => 'preview_url']); + } + + /** + * 营业执照 + * @return HasOne + */ + public function licenseImg(): HasOne { - return self::get($where); + return $this->hasOne(UploadFile::class, 'file_id', 'license_img_id') + ->bind(['license_img' => 'preview_url']); } + + /** + * 门头照片 + * @return HasOne + */ + public function doorImg(): HasOne + { + return $this->hasOne(UploadFile::class, 'file_id', 'door_img_id') + ->bind(['door_img' => 'preview_url']); + } + + /** + * @notes:地区名称 + * @param $value + * @param $data + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function getRegionAttr($value, $data): array + { + return [ + 'province' => RegionModel::getNameById($data['province_id']), + 'city' => RegionModel::getNameById($data['city_id']), + ]; + } + + public function getStatusTextAttr($value, $data) + { + // 状态 + $result = WholesalerEnum::data(); + if (!empty($result[$data['status']]['name'])) { + return $result[$data['status']]['name']; + } + return '未知'; + } + + } \ No newline at end of file