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.
|
|
<?php
namespace App\Controller;
use App\Constants\ErrorCode;use App\Model\OrderMain;use App\Model\Users;use App\Request\WxminiPayRequest;
use EasyWeChat\Factory;use Hyperf\Guzzle\CoroutineHandler;
class PaymentController extends BaseController{
public function wxminiPay(WxminiPayRequest $request){
$data = $request->validated();
$config = config('wxpay'); $app = Factory::payment($config); $app['guzzle_handler'] = CoroutineHandler::class;
// 待支付的,类型一致的,未超时(15min,900sec)的订单
$orderMain = OrderMain::query() ->where(['state' => OrderMain::ORDER_STATE_UNPAY, 'id' => $data['order_id']]) ->where('time', '<=', date('Y-m-d H:i:s', (time()-900))) ->first();
if (empty($orderMain)) { return $this->result(ErrorCode::PAY_FAILURE, ['order_id' => $data['order_id']],'订单不存在或已失效'); }
if (floatval($orderMain->money) != floatval($data['money'])) { return $this->result(ErrorCode::PAY_FAILURE, ['order_id' => $data['order_id']],'订单金额有误'); }
$result = $app->order->unify([ 'body' => '懒族生活 - 外卖下单', 'out_trade_no' => $orderMain->global_order_id, 'total_fee' => bcmul(floatval($orderMain->money), 100), 'notify_url' => config('site_host') . '/v1/notify/wxminiOnline', 'trade_type' => 'JSAPI', 'openid' => $data['openid'], ]);
return $this->success($result); }
}
|