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.
238 lines
8.7 KiB
238 lines
8.7 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\api\model\wholesaler\Apply;
|
|
use app\api\model\wholesaler\Set;
|
|
use cores\exception\BaseException;
|
|
use Exception;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
use think\response\Json;
|
|
use yiovo\captcha\facade\CaptchaApi;
|
|
|
|
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('经营类目不能为空');
|
|
}
|
|
$avatar_id = intval($this->request->post('avatar_id'));
|
|
if (!$avatar_id) {
|
|
return $this->renderError('头像不能为空');
|
|
}
|
|
try {
|
|
CaptchaApi::checkSms($mobile_code, $mobile);
|
|
} catch (Exception $e) {
|
|
return $this->renderError($e->getMessage() ?: '短信验证码不正确');
|
|
}
|
|
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
|
|
$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() ?: '申请成功');
|
|
}
|
|
|
|
/**
|
|
* @notes:申请记录详情
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @author: wanghousheng
|
|
*/
|
|
public function applyInfo(): Json
|
|
{
|
|
$info = Apply::info(['cardFrontImg', 'cardBackImg', 'licenseImg', 'doorImg', 'avatarImg']);
|
|
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);
|
|
}
|
|
if (!empty($info->avatarImg)) {
|
|
unset($info->avatarImg);
|
|
}
|
|
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('经营类目不能为空');
|
|
}
|
|
$avatar_id = intval($this->request->post('avatar_id'));
|
|
if (!$avatar_id) {
|
|
return $this->renderError('头像不能为空');
|
|
}
|
|
try {
|
|
CaptchaApi::checkSms($mobile_code, $mobile);
|
|
} catch (Exception $e) {
|
|
return $this->renderError($e->getMessage() ?: '短信验证码不正确');
|
|
}
|
|
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
|
|
$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('操作失败');
|
|
}
|
|
|
|
} |