You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/controller/Wholesaler.php

263 lines
9.8 KiB

8 months ago
<?php
namespace app\api\controller;
8 months ago
use app\api\model\wholesaler\Apply;
8 months ago
use app\api\model\wholesaler\Set;
5 months ago
use app\common\enum\WholesalerEnum;
8 months ago
use cores\exception\BaseException;
8 months ago
use Exception;
8 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
8 months ago
use yiovo\captcha\facade\CaptchaApi;
8 months ago
class Wholesaler extends Controller
{
/**
* @notes:
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function price(): Json
{
$client = $this->request->post('client');
if (!$client) {
return $this->renderError('客户端不能为空');
}
$model = new \app\api\service\wholesaler\Wholesaler();
$list = $model->setClient($client)->center();
return $this->renderSuccess($list);
}
/**
* @notes:创建订单并支付
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function submit(): Json
{
$method = $this->request->post('method');
if (!$method) {
return $this->renderError('支付方式不能为空');
}
$client = $this->request->post('client');
if (!$client) {
return $this->renderError('客户端不能为空');
}
$priceInfo = Set::detail();
if ($priceInfo->isEmpty()) {
return $this->renderError('后台价格未设置');
}
$priceInfo = $priceInfo->toArray();
$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('经营类目不能为空');
}
8 months ago
$avatar_id = intval($this->request->post('avatar_id'));
if (!$avatar_id) {
return $this->renderError('头像不能为空');
}
8 months ago
try {
CaptchaApi::checkSms($mobile_code, $mobile);
} catch (Exception $e) {
return $this->renderError($e->getMessage() ?: '短信验证码不正确');
}
5 months ago
$model = new Apply();
5 months ago
if ($model->where(['card_no' => $card_no])->value('id')) {
5 months ago
return $this->renderError('该身份证号已存在');
}
5 months ago
if ($model->where(['credit_code' => $credit_code])->value('id')) {
5 months ago
return $this->renderError('营业执照已存在');
}
8 months ago
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
8 months ago
$data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id'));
$data['total_price'] = $priceInfo['price'];
$data['pay_price'] = $priceInfo['price'];
$data['year'] = $priceInfo['year'];
$service = new \app\api\service\wholesaler\Wholesaler();
$data = $service->setMethod($method)
->setClient($client)
->orderPay($data);
return $this->renderSuccess($data, $service->getMessage() ?: '申请成功');
}
8 months ago
/**
* @notes:申请记录详情
* @return Json
* @throws BaseException
* @author: wanghousheng
*/
public function applyInfo(): Json
{
8 months ago
$info = Apply::info(['cardFrontImg', 'cardBackImg', 'licenseImg', 'doorImg', 'avatarImg']);
8 months ago
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);
}
8 months ago
if (!empty($info->avatarImg)) {
unset($info->avatarImg);
}
8 months ago
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('经营类目不能为空');
}
8 months ago
$avatar_id = intval($this->request->post('avatar_id'));
if (!$avatar_id) {
return $this->renderError('头像不能为空');
}
5 months ago
$info = Apply::info();
5 months ago
if (empty($info->id) || empty($info->status)) {
5 months ago
return $this->renderError('信息不存在');
}
5 months ago
if ($info->status == WholesalerEnum::ADOPT) {
return $this->renderError('申请已通过');
}
5 months ago
$model = new Apply();
$exists_id = $model->where(['card_no' => $card_no])->value('id');
if ($exists_id && $info->id != $exists_id) {
return $this->renderError('该身份证号已存在');
}
5 months ago
$exists_id = $model->where(['credit_code' => $credit_code])->value('id');
if ($exists_id && $info->id != $exists_id) {
return $this->renderError('营业执照已存在');
}
8 months ago
try {
CaptchaApi::checkSms($mobile_code, $mobile);
} catch (Exception $e) {
return $this->renderError($e->getMessage() ?: '短信验证码不正确');
}
8 months ago
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
8 months ago
$data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id'));
5 months ago
$data['status'] = WholesalerEnum::AUDITING;
5 months ago
$data['remake'] = null;
5 months ago
if ((new Apply())->edit($data)) {
8 months ago
return $this->renderSuccess('操作成功');
}
return $this->renderError('操作失败');
}
8 months ago
}