82 lines
2.6 KiB
PHP
82 lines
2.6 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
namespace app\common\service;
|
|||
|
|
|||
|
use app\common\model\BiddingOrder;
|
|||
|
use app\common\model\DepositOrder;
|
|||
|
use app\common\model\Requirement;
|
|||
|
use app\common\model\User;
|
|||
|
use app\constant\ResponseCode;
|
|||
|
use think\Exception;
|
|||
|
|
|||
|
class DepositOrderService
|
|||
|
{
|
|||
|
/**
|
|||
|
* 需求保证金回调地址
|
|||
|
*/
|
|||
|
const NOTIFY_URL = '/notify/WechatPayNotify/requirement_deposit_notify';
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @desc 竞价订单支付定金
|
|||
|
* @param $request
|
|||
|
* @return array
|
|||
|
*/
|
|||
|
public function payBidOrder($request)
|
|||
|
{
|
|||
|
try {
|
|||
|
$requestData = $request->post();
|
|||
|
$bidding_order = BiddingOrder::where(['id' => $requestData['bidding_order_id']])->findOrEmpty();
|
|||
|
if ($bidding_order->isEmpty()) {
|
|||
|
throw new Exception('未找到出价订单');
|
|||
|
}
|
|||
|
if ($bidding_order->bind_status != 1) {
|
|||
|
throw new Exception('该出价订单未中标,支付失败');
|
|||
|
}
|
|||
|
if ($bidding_order->pay_final_status != 0) {
|
|||
|
throw new Exception('订单状态异常,支付失败');
|
|||
|
}
|
|||
|
$requirement = Requirement::where(['id' => $bidding_order->requirement_id])->findOrEmpty();
|
|||
|
//@todo:判断是否需要支付定金
|
|||
|
if(1){
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
$trade_no = generate_order_no('B');
|
|||
|
//创建订单
|
|||
|
DepositOrder::create([
|
|||
|
'user_id' => $bidding_order->user_id,
|
|||
|
'photographer_id' => $bidding_order->photographer_id,
|
|||
|
'detail' => json_encode($requirement->toArray()),
|
|||
|
'order_type' => 'requirement',
|
|||
|
'deposit_amount' => $requirement->deposit_amount,
|
|||
|
'trade_no' => $trade_no,
|
|||
|
'pay_status' => 0,
|
|||
|
]);
|
|||
|
|
|||
|
$pay_data = [
|
|||
|
'trade_no' => $trade_no,
|
|||
|
'total_amount' => $bidding_order->bidding_price,
|
|||
|
'desc' => $requirement->requirement_trade_no . '-定金',
|
|||
|
'notify_url' => getenv('SERVER_DOMAIN') . self::NOTIFY_URL,//回调地址
|
|||
|
'openid' => $request->user->openid,
|
|||
|
];
|
|||
|
$result = (new PayService())->payment($pay_data);
|
|||
|
|
|||
|
if(isset($result['code'])){
|
|||
|
throw new Exception($result['msg']);
|
|||
|
}
|
|||
|
|
|||
|
return [
|
|||
|
'code' => ResponseCode::SUCCESS,
|
|||
|
'data' => $result,
|
|||
|
];
|
|||
|
} catch (Exception $e) {
|
|||
|
return [
|
|||
|
'code' => ResponseCode::FAIL,
|
|||
|
'msg' => $e->getMessage()
|
|||
|
];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|