|
|
@ -43,7 +43,12 @@ class IndustryOrderController extends AdminController |
|
|
$grid->column('mobile', '预留手机'); |
|
|
$grid->column('mobile', '预留手机'); |
|
|
$grid->column('title'); |
|
|
$grid->column('title'); |
|
|
$grid->column('picture')->image('', 80, 80); |
|
|
$grid->column('picture')->image('', 80, 80); |
|
|
$grid->column('status')->using(OrderStatus::array()); |
|
|
|
|
|
|
|
|
$grid->column('status') |
|
|
|
|
|
->using(OrderStatus::array()) |
|
|
|
|
|
->if(fn() => $this->status == OrderStatus::UNPAID) |
|
|
|
|
|
->display(fn() => '<a class="btn btn-sm btn-primary" href="' . admin_url('industry_order/list', $this->id) . '">付款</a>') |
|
|
|
|
|
->if(fn() => $this->status == OrderStatus::PAY_EARNEST) |
|
|
|
|
|
->display(fn() => '<a class="btn btn-sm btn-primary" href="' . admin_url('industry_order/list', $this->id) . '">付尾款</a>'); |
|
|
$grid->column('paid_at', '订单确认时间'); |
|
|
$grid->column('paid_at', '订单确认时间'); |
|
|
$grid->column('verify_qrcode', '核销二维码') |
|
|
$grid->column('verify_qrcode', '核销二维码') |
|
|
->if(fn() => $this->verify_code) |
|
|
->if(fn() => $this->verify_code) |
|
|
@ -102,25 +107,95 @@ class IndustryOrderController extends AdminController |
|
|
*/ |
|
|
*/ |
|
|
protected function detail($id) |
|
|
protected function detail($id) |
|
|
{ |
|
|
{ |
|
|
/* return Show::make($id, new IndustryOrder(), function (Show $show) { |
|
|
|
|
|
|
|
|
return Show::make($id, new IndustryOrder(['supplier:id,company_name', 'spec']), function (Show $show) { |
|
|
|
|
|
$show->disableEditButton(); |
|
|
|
|
|
$show->disableDeleteButton(); |
|
|
|
|
|
|
|
|
$show->field('id'); |
|
|
$show->field('id'); |
|
|
$show->field('supplier_id'); |
|
|
|
|
|
$show->field('agent_id'); |
|
|
|
|
|
|
|
|
$show->field('supplier.company_name', '供应商'); |
|
|
$show->field('order_no'); |
|
|
$show->field('order_no'); |
|
|
|
|
|
$show->field('status')->using(OrderStatus::array())->label(); |
|
|
|
|
|
$show->field('pay_type')->using(PayType::array()); |
|
|
|
|
|
$show->field('spec', '规格')->as(fn() => ($this->spec->name ?? '') . ' | ' . ($this->spec->date ?? '')); |
|
|
$show->field('num'); |
|
|
$show->field('num'); |
|
|
$show->field('price'); |
|
|
$show->field('price'); |
|
|
$show->field('name'); |
|
|
|
|
|
|
|
|
$show->field('name', '姓名'); |
|
|
$show->field('mobile'); |
|
|
$show->field('mobile'); |
|
|
$show->field('title'); |
|
|
$show->field('title'); |
|
|
$show->field('picture')->image('', 80, 80); |
|
|
$show->field('picture')->image('', 80, 80); |
|
|
$show->field('status'); |
|
|
|
|
|
$show->field('pay_type'); |
|
|
|
|
|
$show->field('paid_at'); |
|
|
$show->field('paid_at'); |
|
|
$show->field('verify_code'); |
|
|
|
|
|
$show->field('timeout'); |
|
|
|
|
|
$show->field('created_at'); |
|
|
|
|
|
$show->field('updated_at'); |
|
|
|
|
|
});*/ |
|
|
|
|
|
|
|
|
$show->field('created_at', '下单时间'); |
|
|
|
|
|
|
|
|
|
|
|
//付款对话框 weixin://wxpay/bizpayurl?pr=sk9zOCwzz
|
|
|
|
|
|
if (in_array($show->model()->status, [OrderStatus::UNPAID, OrderStatus::PAY_EARNEST])) { |
|
|
|
|
|
$pay_config = $this->payConfig($show->model()->id); |
|
|
|
|
|
if (empty($pay_config['code_url'])) { |
|
|
|
|
|
if (isset($pay_config['result_code'], $pay_config['err_code_des']) && $pay_config['result_code'] != 'SUCCESS') { |
|
|
|
|
|
$msg = $pay_config['err_code_des']; |
|
|
|
|
|
} else { |
|
|
|
|
|
$msg = $pay_config['return_msg'] ?? '获取支付信息失败'; |
|
|
|
|
|
} |
|
|
|
|
|
Admin::script("Dcat.swal.info('支付失败:$msg', null);"); |
|
|
|
|
|
} else { |
|
|
|
|
|
Admin::js('@qrcode'); |
|
|
|
|
|
Admin::script(<<<JS |
|
|
|
|
|
Dcat.swal.info(null, null, { |
|
|
|
|
|
type: null, |
|
|
|
|
|
html: '<div id="qrcode" style="margin-top:1rem;"></div>', |
|
|
|
|
|
imageWidth: 240, |
|
|
|
|
|
imageHeight: 240, |
|
|
|
|
|
animation: false, |
|
|
|
|
|
confirmButtonText: '我已支付,刷新页面', |
|
|
|
|
|
allowOutsideClick: false, |
|
|
|
|
|
allowEscapeKey: false, |
|
|
|
|
|
onOpen: function () { |
|
|
|
|
|
$('#qrcode').qrcode({text:'{$pay_config['code_url']}', width:240, height:240}); |
|
|
|
|
|
}, |
|
|
|
|
|
onClose: function() { |
|
|
|
|
|
window.location.reload(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
JS |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
redirect(admin_url('industry_order/list'))->send(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//付款
|
|
|
|
|
|
private function payConfig($order_id) |
|
|
|
|
|
{ |
|
|
|
|
|
$order = \App\Models\IndustryOrder::where('agent_id', Admin::user()->id) |
|
|
|
|
|
->whereIn('status', [OrderStatus::UNPAID, OrderStatus::PAY_EARNEST])->find($order_id); |
|
|
|
|
|
if (!$order) { |
|
|
|
|
|
Admin::exit('订单不存在或已支付'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$config = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); |
|
|
|
|
|
$config = [ |
|
|
|
|
|
'app_id' => $config['payee_appid'], |
|
|
|
|
|
'mch_id' => $config['payee_mchid'], |
|
|
|
|
|
'key' => $config['payee_mchkey'], |
|
|
|
|
|
'notify_url' => route('industry_product_wxpay_notify'), |
|
|
|
|
|
]; |
|
|
|
|
|
$app = Factory::payment($config); |
|
|
|
|
|
|
|
|
|
|
|
//计算价格
|
|
|
|
|
|
if ($order->status == OrderStatus::PAY_EARNEST) { |
|
|
|
|
|
$price = $order->price - $order->paid_money; |
|
|
|
|
|
} else { |
|
|
|
|
|
$price = $order->price; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $app->order->unify([ |
|
|
|
|
|
'product_id' => $order->industry_product_id, |
|
|
|
|
|
'body' => mb_strcut($order->title, 0, 127), |
|
|
|
|
|
'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付
|
|
|
|
|
|
'total_fee' => round($price * 100), //支付金额单位为分
|
|
|
|
|
|
'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
|
|
|
|
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -138,7 +213,7 @@ class IndustryOrderController extends AdminController |
|
|
|
|
|
|
|
|
return Form::make(new IndustryOrder(), function (Form $form) use ($industry) { |
|
|
return Form::make(new IndustryOrder(), function (Form $form) use ($industry) { |
|
|
if (!$industry) { |
|
|
if (!$industry) { |
|
|
Admin::exit('产品已下架或库存不足'); |
|
|
|
|
|
|
|
|
Admin::exit('订单不允许编辑'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$form->selectTable('industry_product_spec_id', '选择产品规格') |
|
|
$form->selectTable('industry_product_spec_id', '选择产品规格') |
|
|
@ -155,6 +230,16 @@ class IndustryOrderController extends AdminController |
|
|
$form->text('name')->default(Admin::user()->director)->required(); |
|
|
$form->text('name')->default(Admin::user()->director)->required(); |
|
|
$form->mobile('mobile')->default(Admin::user()->contact_phone)->required(); |
|
|
$form->mobile('mobile')->default(Admin::user()->contact_phone)->required(); |
|
|
|
|
|
|
|
|
|
|
|
$pay_type = [PayType::ONLINE, PayType::OFFLINE]; |
|
|
|
|
|
if ($industry->deposit) { //订金支付
|
|
|
|
|
|
$pay_type = [...$pay_type, PayType::DEPOSIT_PAY]; |
|
|
|
|
|
} |
|
|
|
|
|
if ($industry->earnest) { //定金支付
|
|
|
|
|
|
$pay_type = [...$pay_type, PayType::EARNEST_PAY]; |
|
|
|
|
|
} |
|
|
|
|
|
$options = array_filter(PayType::array(), fn($k) => in_array($k, $pay_type), ARRAY_FILTER_USE_KEY); |
|
|
|
|
|
$form->select('pay_type')->options($options)->default(PayType::ONLINE)->required(); |
|
|
|
|
|
|
|
|
$form->divider(); |
|
|
$form->divider(); |
|
|
$form->text('', '购买产品')->default($industry->title)->disable(); |
|
|
$form->text('', '购买产品')->default($industry->title)->disable(); |
|
|
$form->text('', '单价')->default($industry->price)->disable(); |
|
|
$form->text('', '单价')->default($industry->price)->disable(); |
|
|
@ -204,14 +289,22 @@ class IndustryOrderController extends AdminController |
|
|
$form->price = $form->num * $spec->price; |
|
|
$form->price = $form->num * $spec->price; |
|
|
$form->title = $industry->title; |
|
|
$form->title = $industry->title; |
|
|
$form->picture = $industry->pictures[0] ?? '' ; |
|
|
$form->picture = $industry->pictures[0] ?? '' ; |
|
|
$form->status = OrderStatus::OFFLINE_UNPAID; |
|
|
|
|
|
$form->pay_type = PayType::OFFLINE; |
|
|
|
|
|
|
|
|
$form->status = $form->pay_type == PayType::OFFLINE ? OrderStatus::OFFLINE_UNPAID : OrderStatus::UNPAID; |
|
|
$form->paid_at = null; |
|
|
$form->paid_at = null; |
|
|
$form->verify_code = ''; |
|
|
$form->verify_code = ''; |
|
|
$form->trade_deposit = $form->num * $industry->single_deposit; |
|
|
$form->trade_deposit = $form->num * $industry->single_deposit; |
|
|
|
|
|
$form->single_price = $industry->single_deposit; |
|
|
$form->timeout = null; |
|
|
$form->timeout = null; |
|
|
|
|
|
|
|
|
|
|
|
if ($form->pay_type == PayType::DEPOSIT_PAY) { |
|
|
|
|
|
$form->prepay_price = $industry->deposit; |
|
|
|
|
|
} else if ($form->pay_type == PayType::EARNEST_PAY) { |
|
|
|
|
|
$form->prepay_price = $industry->earnest; |
|
|
|
|
|
} else { |
|
|
|
|
|
$form->prepay_price = 0; |
|
|
|
|
|
} |
|
|
})->saved(function (Form $form) { |
|
|
})->saved(function (Form $form) { |
|
|
return $form->response()->success('下单成功,请等待供应商审核订单')->script('history.go(-1)'); |
|
|
|
|
|
|
|
|
return $form->response()->success('下单成功,请等待供应商审核订单')->redirect(admin_url('industry_order/list')); |
|
|
})->deleting(function (Form $form) { |
|
|
})->deleting(function (Form $form) { |
|
|
return $form->response()->error('操作禁止'); |
|
|
return $form->response()->error('操作禁止'); |
|
|
}); |
|
|
}); |
|
|
|