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.
227 lines
7.8 KiB
227 lines
7.8 KiB
<?php
|
|
|
|
namespace App\AdminSettled\Controllers;
|
|
|
|
use App\Admin\Repositories\Supplier;
|
|
use App\Common\UserStatus;
|
|
use App\Models\AdminSetting;
|
|
use App\Models\SettledOrder;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Widgets\Alert;
|
|
use EasyWeChat\Factory;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class SupplierController extends AdminController
|
|
{
|
|
protected $title = '供应商入驻';
|
|
|
|
public function __construct()
|
|
{
|
|
admin_inject_section(Admin::SECTION['LEFT_SIDEBAR_MENU'], '');
|
|
app('view')->prependNamespace('admin', resource_path('views/admin'));
|
|
}
|
|
|
|
protected function grid()
|
|
{
|
|
config::set('admin.helpers.enable', false);
|
|
$tip = '你可能需要
|
|
《<a href="' . admin_url('supplier/create') . '" style="color:#ef5228;">供应商入驻</a>》
|
|
《<a href="' . admin_url('agent/create') . '" style="color:#ef5228;">代理商入驻</a>》
|
|
《<a href="' . admin_url('guide/create') . '" style="color:#ef5228;">地接入驻</a>》';
|
|
return Alert::make($tip, '页面不存在')->danger();
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
config::set('admin.helpers.enable', false);
|
|
return Alert::make('', '页面不存在')->danger();
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
config::set('admin.helpers.enable', false);
|
|
return Form::make(new Supplier(), function (Form $form) {
|
|
$form->disableListButton();
|
|
$form->disableViewCheck();
|
|
$form->disableCreatingCheck();
|
|
$form->disableEditingCheck();
|
|
$form->disableDeleteButton();
|
|
|
|
$form->text('username')->required();
|
|
$form->password('password')->minLength(6)->required();
|
|
$form->text('name')->required();
|
|
$form->text('company_name')->required();
|
|
$form->text('address')->required();
|
|
$form->distpicker(['province_id', 'city_id', 'area_id'], '请选择区域')->required();
|
|
$form->multipleImage('license')->required()->removable(false)->uniqueName();
|
|
$form->image('business_license')->required()->removable(false)->uniqueName();
|
|
$form->text('credit_codes')->required()->help('请正确填写,保持跟营业执照上的完全一致,如:91440300577652919M');
|
|
$form->text('corporate_account')->required()->help('非常重要,该账号作为默认提现账号');
|
|
$form->text('deposit_bank')->required();
|
|
$form->text('director')->required();
|
|
$form->text('contact_phone')->required()->maxLength(13);
|
|
|
|
$contract_template = Storage::disk('public')->url(AdminSetting::val('settled_supplier_contract'));
|
|
$form->image('contract')->required()->uniqueName()
|
|
->help('请先 <a target="_blank" href="' . $contract_template . '" download="【易游天下】供应商入驻合同模板">下载入驻合同</a> 并打印,填写完毕之后盖好公章再上传。');
|
|
|
|
$agreement_template = Storage::disk('public')->url(AdminSetting::val('settled_supplier_agreement'));
|
|
$form->checkbox('agreement', '')->required()
|
|
->options([1 => '我已认真阅读并完全认同'])->customFormat(fn() => '')
|
|
->script('$(function(){
|
|
$(".field_agreement").parent().css("margin-right", 0).after(\'《<a target="_blank" href="'.$agreement_template.'" download="【易游天下】入驻协议">入驻协议</a>》\');
|
|
});');
|
|
Admin::js('@qrcode');
|
|
})->saving(function (Form $form) {
|
|
//禁止编辑
|
|
if ($form->isEditing()) {
|
|
return $form->response()->error('服务器出错了~~');
|
|
}
|
|
|
|
if (empty(array_filter($form->agreement))) {
|
|
return $form->response()->error('你必须同意入驻协议才能入驻');
|
|
}
|
|
$form->deleteInput('agreement');
|
|
|
|
//判断账号是否唯一
|
|
if ($form->repository()->model()->where('username', $form->username)->exists()) {
|
|
return $form->response()->error($form->username . ' 的账号已经存在');
|
|
}
|
|
|
|
//过滤null字段
|
|
foreach($form->input() as $k => $v) {
|
|
if (is_null($form->$k)) {
|
|
$form->$k = '';
|
|
}
|
|
}
|
|
|
|
//不允许编辑的字段
|
|
$form->ignore(['id', 'remember_token', 'rate', 'created_at', 'created_at', 'deleted_at', 'deleted_at']);
|
|
|
|
//处理特殊字段
|
|
$form->hidden(['status', 'rate']);
|
|
$form->status = UserStatus::UNAUDITED;
|
|
$form->rate = 5;
|
|
})->saved(function (Form $form) {
|
|
$pay = (new SupplierController)->payConfig($form->repository()->model());
|
|
|
|
if (empty($pay['code_url'])) {
|
|
if (isset($pay['result_code'], $pay['err_code_des']) && $pay['result_code'] != 'SUCCESS') {
|
|
$msg = $pay['err_code_des'];
|
|
} else {
|
|
$msg = $pay['return_msg'] ?? '获取支付信息失败';
|
|
}
|
|
$js = "Dcat.swal.info('支付:$msg', null);";
|
|
} else {
|
|
$ajax_url = admin_url('is_pay');
|
|
$cost = AdminSetting::val('settled_supplier_cost');
|
|
$js = <<<JS
|
|
Dcat.swal.info(
|
|
'<div style="margin-top:1rem;"><div id="qrcode"></div><p style="text-align:center;">入驻费:¥{$cost}元</p></div>',
|
|
'<b style="color:red">请微信扫码支付,请勿关闭页面</b>',
|
|
{
|
|
type: null,
|
|
imageWidth: 240,
|
|
imageHeight: 240,
|
|
animation: false,
|
|
// confirmButtonText: '我已完成支付,刷新',
|
|
showConfirmButton: false,
|
|
allowOutsideClick: false,
|
|
allowEscapeKey: false,
|
|
onOpen: function () {
|
|
$('#qrcode').qrcode({text:'{$pay["code_url"]}', width:240, height:240});
|
|
if (window.timer) {
|
|
clearInterval(window.timer);
|
|
}
|
|
window.timer = setInterval(function () {
|
|
$.ajax({
|
|
url: '$ajax_url',
|
|
data: {
|
|
username: '{$form->repository()->model()->username}'
|
|
},
|
|
success: function (res) {
|
|
if (res == 1) {
|
|
clearInterval(window.timer);
|
|
Dcat.swal.success('支付成功,请联系平台审核!', null, {
|
|
onClose: function () {
|
|
window.location.reload();
|
|
}
|
|
}).then(() => {
|
|
window.location.reload();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}, 1000);
|
|
}
|
|
});
|
|
JS;
|
|
}
|
|
return $form->response()->success('操作成功,请等待管理员审核')->script($js);
|
|
})->deleting(function (Form $form) {
|
|
return $form->response()->error('服务器出错了~~');
|
|
});
|
|
}
|
|
|
|
//付款
|
|
private function payConfig($supplier)
|
|
{
|
|
$setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey', 'settled_supplier_cost']);
|
|
$config = [
|
|
'app_id' => $setting['payee_appid'],
|
|
'mch_id' => $setting['payee_mchid'],
|
|
'key' => $setting['payee_mchkey'],
|
|
'notify_url' => route('wxpay_settled_notify'),
|
|
];
|
|
$app = Factory::payment($config);
|
|
|
|
//生成订单号
|
|
list($micro, $sec) = explode(' ', microtime());
|
|
$micro = str_pad(floor($micro * 1000000), 6, 0, STR_PAD_LEFT);
|
|
$order_no = date('ymdHis', $sec) . $micro . mt_rand(1000, 9999);
|
|
|
|
//保存订单记录
|
|
SettledOrder::insertOrIgnore([
|
|
'order_no' => $order_no,
|
|
'user_type' => 1,
|
|
'username' => $supplier->username,
|
|
'money' => $setting['settled_supplier_cost'],
|
|
'status' => 0,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
return $app->order->unify([
|
|
'product_id' => $supplier->id,
|
|
'attach' => $supplier->username,
|
|
'body' => mb_strcut($supplier->company_name . ' 供应商入驻', 0, 127),
|
|
'out_trade_no' => $order_no,
|
|
'total_fee' => round($setting['settled_supplier_cost'] * 100), //支付金额单位为分
|
|
'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
|
|
]);
|
|
}
|
|
|
|
//ajax回调,判断是否已支付
|
|
public function isPay(): int
|
|
{
|
|
$username = request()->input('username');
|
|
$order = SettledOrder::where(['username' => $username, 'user_type' => 1])->first();
|
|
if (!$order) {
|
|
return 0;
|
|
}
|
|
return (int)$order->status;
|
|
}
|
|
}
|