525 lines
20 KiB
PHP
Executable File
525 lines
20 KiB
PHP
Executable File
<?php
|
||
/**
|
||
* @createtime 2023/5/20
|
||
* @author wild
|
||
* @copyright PhpStorm
|
||
*/
|
||
|
||
|
||
namespace App\Http\Controllers\Api\Seller;
|
||
|
||
|
||
use App\Enums\AuditState;
|
||
use App\Enums\BoolEnum;
|
||
use App\Enums\PayType;
|
||
use App\Model\ProvinceCityArea;
|
||
use App\Model\Seller\Seller;
|
||
use App\Model\Seller\Shop;
|
||
use App\Model\Seller\ShopExtra;
|
||
use App\Model\Seller\ShopPayChannel;
|
||
use App\Utils\Helps;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
|
||
class ShopController extends BaseController
|
||
{
|
||
/**
|
||
* @api {POST} /api/seller/shop/certify_get 店铺-店铺认证查看
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "id":2003,
|
||
* "individual":1,
|
||
* "shop_id":2000,
|
||
* "apply_id":1000,
|
||
* "apply_at":"2023-07-20 20:00:21",
|
||
* "auditor_id":0,
|
||
* "audit_at":null,
|
||
* "state":0, //
|
||
* "audit_msg":"",
|
||
* "business_type":0,
|
||
* "business_door":"xxxxxxxxxxx",
|
||
* "sale_proxy":"xxxxxxxxxxx",
|
||
* "sale_proxy_hand":"xxxxxxxxxxx",
|
||
* "identity_pros":"xxxxxxxxxxx",
|
||
* "identity_cons":"xxxxxxxxxxx",
|
||
* "identity_hand":"xxxxxxxxxxx",
|
||
* "created_at":"2023-07-20 20:00:21",
|
||
* "updated_at":"2023-07-20 20:00:21",
|
||
* "deleted_at":null,
|
||
* "individual_url":"http://jingcai.quickfly.eu.org:3000/1",
|
||
* "business_door_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx",
|
||
* "sale_proxy_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx",
|
||
* "sale_proxy_hand_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx",
|
||
* "identity_pros_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx",
|
||
* "identity_cons_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx",
|
||
* "identity_hand_url":"http://jingcai.quickfly.eu.org:3000/xxxxxxxxxxx"
|
||
* }
|
||
* }
|
||
*/
|
||
public function certifyGet(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$se = ShopExtra::where('shop_id', $this->shopId())->first();
|
||
return $this->jsonSuccess($se);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/shop/certify_apply 店铺-店铺认证申请
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {Int} individual 1 1代表个体经营,传1
|
||
* @apiParam {String} business_door 门头照
|
||
* @apiParam {String} sale_proxy 代销证
|
||
* @apiParam {String} sale_proxy_hand 代销证
|
||
* @apiParam {String} identity_pros 身份证正面
|
||
* @apiParam {String} identity_cons 身份证反面
|
||
* @apiParam {String} identity_hand 手持身份证
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data":[]
|
||
* }
|
||
*
|
||
*/
|
||
public function certifyApply(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$individual = $request->input('individual', 1);
|
||
$business_door = $request->input('business_door');
|
||
$sale_proxy = $request->input('sale_proxy');
|
||
$sale_proxy_hand = $request->input('sale_proxy_hand');
|
||
$identity_pros = $request->input('identity_pros');
|
||
$identity_cons = $request->input('identity_cons');
|
||
$identity_hand = $request->input('identity_hand');
|
||
|
||
ThrowException::isTrue(!$business_door, '店铺门头照必传');
|
||
ThrowException::isTrue(!$sale_proxy, '代销证必传');
|
||
ThrowException::isTrue(!$sale_proxy_hand, '手持代销证必传');
|
||
ThrowException::isTrue(!$identity_pros, '身份证正面必传');
|
||
ThrowException::isTrue(!$identity_cons, '身份证反面必传');
|
||
ThrowException::isTrue(!$identity_hand, '手持身份证必传');
|
||
|
||
|
||
$se = ShopExtra::where('shop_id', $this->shopId())->first();
|
||
if ($se) {
|
||
ThrowException::isTrue($se->state == AuditState::SUCCESS, '已认证,无需重复认证');
|
||
ThrowException::isTrue($se->state == AuditState::PENDING, '认证中,请等待处理');
|
||
}
|
||
if (!$se) {
|
||
$se = new ShopExtra();
|
||
}
|
||
$se->apply_id = $this->sellerId();
|
||
$se->shop_id = $this->shopId();
|
||
$se->apply_at = date('Y-m-d H:i:s');
|
||
$se->state = AuditState::PENDING;
|
||
$se->individual = $individual;
|
||
$se->business_door = $business_door;
|
||
$se->sale_proxy = $sale_proxy;
|
||
$se->sale_proxy_hand = $sale_proxy_hand;
|
||
$se->identity_pros = $identity_pros;
|
||
$se->identity_cons = $identity_cons;
|
||
$se->identity_hand = $identity_hand;
|
||
$se->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/seller/shop/setting 店铺信息-设置
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} [announcement] 公告内容
|
||
* @apiParam {String} [announcement_img_url] 公告图片(使用/api/seller/material/upload_other结果中的path)
|
||
* @apiParam {String} [wechat] 微信号
|
||
* @apiParam {Int} [keep_secret] 1保密;0不保密
|
||
* @apiParam {Array} [withdraw_type] [1,2]提现方式,1支付宝,2银行卡
|
||
* @apiParam {String} [phone] 手机号
|
||
* @apiParam {String} [password] 登录密码(手机号时,密码必填)
|
||
* @apiParam {Int} [province_id] 省id (详细地址时,必填)
|
||
* @apiParam {Int} [city_id] 市id(详细地址时,必填)
|
||
* @apiParam {String} [addr] 详细地址
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data":[]
|
||
* }
|
||
*
|
||
*/
|
||
public function setting(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$announcement = $request->input('announcement');
|
||
$name = $request->input('name');
|
||
$announcementImgUrl = $request->input('announcement_img_url');
|
||
$shop = Shop::find($this->shopId());
|
||
if ($announcement !== null) {
|
||
$shop->announcement = $announcement;
|
||
$shop->announcement_img_url = strval($announcementImgUrl);
|
||
}
|
||
|
||
$wechat = $request->input('wechat');
|
||
if ($wechat !== null) {
|
||
$shop->seller_wechat = $wechat;
|
||
}
|
||
|
||
$keep_secret = $request->input('keep_secret');
|
||
if ($keep_secret !== null) {
|
||
$shop->keep_secret = $keep_secret ? BoolEnum::YES : BoolEnum::NO;
|
||
}
|
||
|
||
$withdraw_type = $request->input('withdraw_type');
|
||
if ($withdraw_type !== null) {
|
||
if ($withdraw_type) {
|
||
$withdraw_type = array_map('intval', $withdraw_type);
|
||
}
|
||
$shop->withdraw_type = $withdraw_type;
|
||
}
|
||
|
||
$phone = $request->input('phone');
|
||
if ($phone !== null) {
|
||
$password = $request->input('password');
|
||
ThrowException::isTrue(!$phone, '请填写店铺手机号');
|
||
ThrowException::isTrue(!Helps::validPhone($phone), '手机号格式错误');
|
||
$seller = Seller::find($this->sellerId());
|
||
ThrowException::isTrue(!Seller::checkPassword($password, $seller->password), '密码错误');
|
||
$shop->seller_phone = $phone;
|
||
}
|
||
|
||
$provinceId = $request->input('province_id');
|
||
$cityId = $request->input('city_id');
|
||
$addrDetail = $request->input('addr');
|
||
$hideWinpost = $request->input('hide_winpost');
|
||
if ($hideWinpost !== null) {
|
||
$shop->hide_winpost = $hideWinpost == BoolEnum::YES ? BoolEnum::YES : BoolEnum::NO;
|
||
}
|
||
if ($addrDetail !== null) {
|
||
ThrowException::isTrue(!$addrDetail, '请填写详细地址');
|
||
ThrowException::isTrue($shop->addr, '地址不可更改');
|
||
|
||
$province = ProvinceCityArea::find($provinceId);
|
||
ThrowException::isTrue(!$province, '省不存在');
|
||
$city = ProvinceCityArea::find($cityId);
|
||
ThrowException::isTrue(!$province, '市不存在');
|
||
$shop->province_id = $provinceId;
|
||
$shop->province_name = $province->name;
|
||
$shop->city_id = $cityId;
|
||
$shop->city_name = $city->name;
|
||
$shop->addr = $addrDetail;
|
||
}
|
||
if ($name) {
|
||
$shop->name = $name;
|
||
}
|
||
$shop->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {GET} /api/seller/shop/pay_channel_list 收款管理-列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":[
|
||
* {
|
||
* "title":"支付宝", // 标题
|
||
* "pay_type":"alipay", // 支付方式
|
||
* "pay_channels":[
|
||
* {
|
||
* "pay_channel":1, // 支付渠道
|
||
* "title":"渠道1", // 名称
|
||
* "description":"实时到账,费率0.60%", // 描述
|
||
* "opened":0, // 是否开启
|
||
* "state":0 // 状态:0未开通,1已开通,2已提交,3申请失败
|
||
* }
|
||
* ]
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
public function payChannelList(Request $request)
|
||
{
|
||
$channel1 = ShopPayChannel::where('pay_type', PayType::ALIPAY)
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_channel', 1)
|
||
->first();
|
||
$channel2 = ShopPayChannel::where('pay_type', PayType::ALIPAY)
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_channel', 2)
|
||
->first();
|
||
$channel3 = ShopPayChannel::where('pay_type', PayType::ALIPAY)
|
||
->where('shop_id', $this->shopId())
|
||
->where('pay_channel', 3)
|
||
->first();
|
||
$qrcode = ShopPayChannel::where('pay_type', PayType::QRCOE)
|
||
->where('shop_id', $this->shopId())
|
||
->first();
|
||
$list = [
|
||
[
|
||
'title' => '支付宝',
|
||
'pay_type' => PayType::ALIPAY,
|
||
'pay_channels' => [
|
||
[
|
||
'pay_channel' => 1,
|
||
'title' => '渠道一',
|
||
'description' => '实时到账,费率0.60%',
|
||
'opened' => $channel1 ? $channel1->opened : 0,
|
||
'state' => $channel1 ? $channel1->state : 0,
|
||
'id' => $channel1 ? $channel1->id : 0,
|
||
],
|
||
[
|
||
'pay_channel' => 2,
|
||
'title' => '渠道二',
|
||
'description' => '实时到账,费率0.60%',
|
||
'opened' => $channel2 ? $channel2->opened : 0,
|
||
'state' => $channel2 ? $channel2->state : 0,
|
||
'id' => $channel2 ? $channel2->id : 0,
|
||
],
|
||
|
||
[
|
||
'pay_channel' => 3,
|
||
'title' => '渠道三',
|
||
'description' => '实时到账,费率0.60%',
|
||
'opened' => $channel3 ? $channel3->opened : 0,
|
||
'state' => $channel3 ? $channel3->state : 0,
|
||
'id' => $channel3 ? $channel3->id : 0,
|
||
]
|
||
]
|
||
],
|
||
[
|
||
'title' => '二维码收款',
|
||
'pay_type' => PayType::QRCOE,
|
||
'pay_channels' => [
|
||
[
|
||
'pay_channel' => 1,
|
||
'title' => '二维码收款',
|
||
'opened' => $qrcode ? $qrcode->opened : 0,
|
||
'remind_after' => $qrcode ? $qrcode->remind_after : '',
|
||
'remind_before' => $qrcode ? $qrcode->remind_before : '',
|
||
'alipay_qrcode' => $qrcode ? $qrcode->alipay_qrcode_url : '',
|
||
'wechat_qrcode' => $qrcode ? $qrcode->wechat_qrcode_url : '',
|
||
'id' => $qrcode ? $qrcode->id : 0,
|
||
]
|
||
]
|
||
],
|
||
];
|
||
return $this->jsonSuccess($list);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/seller/shop/pay_channel_update 授权管理-更新
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {Int} id 支付渠道id
|
||
* @apiParam {String} [opened] 是否开启
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*/
|
||
public function payChannelUpdate(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$id = $request->input('id');
|
||
$opened = $request->input('opened');
|
||
|
||
$collectMoney = ShopPayChannel::where('shop_id', $this->shopId())->find($id);
|
||
ThrowException::isTrue(!$collectMoney, '数据不存在');
|
||
if ($collectMoney->state != ShopPayChannel::STATE_SUCCESS) {
|
||
ThrowException::run('请审核通过之后,再进行操作!');
|
||
}
|
||
|
||
$collectMoney->opened = $opened == BoolEnum::YES ? BoolEnum::YES : BoolEnum::NO;
|
||
$collectMoney->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/seller/shop/pay_channel 收款管理-收款认证
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} pay_type 支付方式(alipay,qrcode)
|
||
*
|
||
* @apiParam {String} [remind_after] 付款前提醒
|
||
* @apiParam {String} [remind_before] 付款后提醒
|
||
* @apiParam {String} [opened] 是否开启
|
||
* @apiParam {String} [alipay_qrcode] 支付宝二维码
|
||
* @apiParam {String} [wechat_qrcode] 微信二维码
|
||
*
|
||
* @apiParam {String} [pay_channel] 支付渠道 --以下为支付宝的
|
||
* @apiParam {String} [real_name] 姓名
|
||
* @apiParam {String} [email] 邮箱
|
||
* @apiParam {String} [phone] 手机号
|
||
* @apiParam {String} [alipay] 支付宝账号
|
||
* @apiParam {String} [shop_addr] 店铺地址
|
||
* @apiParam {String} [business_door] 门头照
|
||
* @apiParam {String} [business_site] 经营场所/店内照
|
||
* @apiParam {String} [sale_proxy] 营业执照
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": []
|
||
* }
|
||
*
|
||
*/
|
||
public function payChannelStore(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$paytype = $request->input('pay_type');
|
||
$id = $request->input('id');
|
||
|
||
if ($paytype == PayType::QRCOE) {
|
||
return $this->payChannelQrcodeStore($request);
|
||
}
|
||
|
||
$real_name = $request->input('real_name');
|
||
$email = $request->input('email');
|
||
$phone = $request->input('phone');
|
||
$shop_addr = $request->input('shop_addr');
|
||
$alipay = $request->input('alipay');
|
||
|
||
$business_door = strval($request->input('business_door'));
|
||
$business_site = strval($request->input('business_site'));
|
||
$sale_proxy = strval($request->input('sale_proxy'));
|
||
$payChannel = strval($request->input('pay_channel'));
|
||
|
||
ThrowException::isTrue(!in_array($payChannel, [1,2,3]), '不支持该渠道!');
|
||
|
||
ThrowException::isTrue(!PayType::hasValue($paytype), '不支持支付方式');
|
||
ThrowException::isTrue(!$real_name, '姓名不能为空');
|
||
ThrowException::isTrue(!$email, '邮箱不能为空');
|
||
ThrowException::isTrue(!$phone, '手机号不能为空');
|
||
ThrowException::isTrue(!Helps::validPhone($phone), '手机号格式有误');
|
||
ThrowException::isTrue(!$shop_addr, '店铺地址不能为空');
|
||
ThrowException::isTrue(!$alipay, '支付宝账号不能为空');
|
||
|
||
if ($id > 0) {
|
||
$collectMoney = ShopPayChannel::where('shop_id', $this->shopId())->find($id);
|
||
ThrowException::isTrue(!$collectMoney, '数据不存在');
|
||
if ($collectMoney->pay_type != $paytype) {
|
||
ThrowException::run('不可更改支付方式');
|
||
}
|
||
|
||
if ($collectMoney->state == ShopPayChannel::STATE_SUCCESS) {
|
||
ThrowException::run('审核成功后,不可修改');
|
||
}
|
||
ThrowException::isTrue($collectMoney->state == ShopPayChannel::STATE_SUBMIT, '不可重复提交');
|
||
} else {
|
||
$exist = ShopPayChannel::where('shop_id', $this->shopId())
|
||
->where('pay_type', $paytype)
|
||
->where('pay_channel', $payChannel)
|
||
->first();
|
||
ThrowException::isTrue($exist, '该渠道无法重复申请!');
|
||
$collectMoney = new ShopPayChannel();
|
||
|
||
}
|
||
|
||
$collectMoney->shop_id = $this->shopId();
|
||
$collectMoney->seller_id = $this->sellerId();
|
||
$collectMoney->channel_name = $paytype == PayType::ALIPAY ? '支付宝' : '';
|
||
$collectMoney->pay_type = $paytype;
|
||
$collectMoney->pay_channel = $payChannel;
|
||
$collectMoney->real_name = $real_name;
|
||
$collectMoney->email = $email;
|
||
$collectMoney->phone = $phone;
|
||
$collectMoney->alipay = $alipay;
|
||
$collectMoney->shop_addr = $shop_addr;
|
||
$collectMoney->business_door = $business_door;
|
||
$collectMoney->business_site = $business_site;
|
||
$collectMoney->sale_proxy = $sale_proxy;
|
||
$collectMoney->state = ShopPayChannel::STATE_SUBMIT;
|
||
$collectMoney->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
private function payChannelQrcodeStore(Request $request)
|
||
{
|
||
$remind_after = $request->input('remind_after');
|
||
$remind_before = $request->input('remind_before');
|
||
$opened = $request->input('opened');
|
||
$alipay_qrcode = $request->input('alipay_qrcode');
|
||
$wechat_qrcode = $request->input('wechat_qrcode');
|
||
|
||
$payChannel = ShopPayChannel::where('shop_id', $this->shopId())
|
||
->where('pay_type', PayType::QRCOE)
|
||
->first();
|
||
if (!$payChannel) {
|
||
$payChannel = new ShopPayChannel();
|
||
}
|
||
$payChannel->shop_id = $this->shopId();
|
||
$payChannel->seller_id = $this->sellerId();
|
||
$payChannel->channel_name = '二维码支付';
|
||
$payChannel->pay_type = PayType::QRCOE;
|
||
$payChannel->pay_channel = 1;
|
||
if ($remind_before !== null) {
|
||
$payChannel->remind_before = strval($remind_before);
|
||
}
|
||
if ($remind_after !== null) {
|
||
$payChannel->remind_after = strval($remind_after);
|
||
}
|
||
if ($opened !== null) {
|
||
$payChannel->opened = $opened == BoolEnum::YES ? BoolEnum::YES : BoolEnum::NO;
|
||
}
|
||
if ($alipay_qrcode !== null) {
|
||
$payChannel->alipay_qrcode = $alipay_qrcode;
|
||
}
|
||
if ($wechat_qrcode !== null) {
|
||
$payChannel->wechat_qrcode = $wechat_qrcode;
|
||
}
|
||
$payChannel->state = ShopPayChannel::STATE_SUCCESS;
|
||
$payChannel->save();
|
||
return $this->jsonSuccess();
|
||
}
|
||
|
||
/**
|
||
* @api {GET} /api/seller/shop/pay_channel 收款管理-查看收款认证
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 店主
|
||
*
|
||
* @apiParam {String} pay_type 支付方式
|
||
* @apiParam {String} pay_channel 支付渠道
|
||
*
|
||
* @apiSuccessExample {json} 返回结果参考提交的参数
|
||
* {}
|
||
*
|
||
*/
|
||
public function payChannelShow(Request $request)
|
||
{
|
||
$this->checkMasterNext();
|
||
$payChannel = $request->input('pay_channel');
|
||
$paytype = $request->input('pay_type');
|
||
$query = ShopPayChannel::where('shop_id', $this->shopId())
|
||
->where('pay_type', $paytype);
|
||
if ($paytype == PayType::ALIPAY) {
|
||
$query->where('pay_channel', $payChannel);
|
||
}
|
||
|
||
$exist = $query->first();
|
||
ThrowException::isTrue(!$exist, '该渠道不存在');
|
||
return $this->jsonSuccess($exist);
|
||
}
|
||
}
|