pull/1/head
wanghousheng 10 months ago
parent d84eb3b046
commit 227a3c23e1
  1. 2
      app/api/controller/Identity.php
  2. 28
      app/api/controller/Server.php
  3. 4
      app/api/model/Server/ServerOrder.php
  4. 8
      app/api/model/UserCoupon.php
  5. 2
      app/api/service/Identity.php
  6. 21
      app/common/service/server/Order.php

@ -79,7 +79,7 @@ class Identity extends Controller
}
/**
* 交易查询
* 查询第三方支付订单是否付款成功
* @return Json
* @throws BaseException
* @throws DataNotFoundException

@ -54,8 +54,9 @@ class Server extends Controller
if ($category_id) {
$where[] = ['server.category_id', '=', $category_id];
}
$model = new \app\api\model\Server($where);
$list = $model->getList();
$where[] = ['server.status', '=', 1];
$model = new \app\api\model\Server();
$list = $model->getList($where);
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
@ -84,7 +85,7 @@ class Server extends Controller
* @throws BaseException
* @author: wanghousheng
*/
public function userOrderList(): Json
public function orderList(): Json
{
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
@ -146,7 +147,7 @@ class Server extends Controller
{
$serverId = intval($this->request->post('server_id'));
$couponId = intval($this->request->post('coupon_id'));
$remake = $this->request->post('remake');
$remake = (string)$this->request->post('remake');
if (!$serverId) {
return $this->renderError('非法请求');
}
@ -273,9 +274,6 @@ class Server extends Controller
/**
* @notes:交易查询
* @param string $outTradeNo
* @param string $method
* @param string $client
* @return Json
* @throws BaseException
* @throws DataNotFoundException
@ -283,10 +281,22 @@ class Server extends Controller
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function tradeQuery(string $outTradeNo, string $method, string $client): Json
public function tradeQuery(): Json
{
$method = $this->request->post('method');
if (!$method) {
return $this->renderError('支付方式不能为空');
}
$order_no = $this->request->post('order_no');
if (!$order_no) {
return $this->renderError('订单号不能为空');
}
$client = $this->request->post('client');
if (!$client) {
return $this->renderError('客户端不能为空');
}
$paymentService = new ServerPayment;
$result = $paymentService->setMethod($method)->setClient($client)->tradeQuery($outTradeNo);
$result = $paymentService->setMethod($method)->setClient($client)->tradeQuery($order_no);
$message = $result ? '恭喜您,订单已付款成功' : ($paymentService->getError() ?: '很抱歉,订单未支付,请重新发起');
return $this->renderSuccess(['isPay' => $result], $message);
}

@ -113,13 +113,13 @@ class ServerOrder extends Order
// 获取订单详情
$orderInfo = static::getDetail($orderId);
// 验证订单状态
if ($orderInfo['order_status'] != ServerEnum::APPLYPAY || $orderInfo['pay_status'] = PayStatus::SUCCESS) {
if ($orderInfo['order_status'] != ServerEnum::APPLYPAY || $orderInfo['pay_status'] == PayStatus::SUCCESS) {
throwError('当前订单状态不允许支付');
}
// 未支付订单的过期时间
$orderCloseTime = SettingModel::getOrderCloseTime() * 60 * 60;
// 订单超时截止时间
$expirationTime = $orderInfo->getData('create_time') + $orderCloseTime;
$expirationTime = strtotime($orderInfo['create_time']) + $orderCloseTime;
if ($orderCloseTime > 0 && $expirationTime <= time()) {
throwError('当前订单支付已超时,请重新下单');
}

@ -20,6 +20,7 @@ use app\common\enum\coupon\TypeCase;
use app\common\library\helper;
use app\common\model\UserCoupon as UserCouponModel;
use cores\exception\BaseException;
use think\db\exception\DbException;
/**
* 用户优惠券模型
@ -43,7 +44,7 @@ class UserCoupon extends UserCouponModel
* @param int $userId
* @param array $param
* @return \think\Paginator
* @throws \think\db\exception\DbException
* @throws DbException
*/
public function getList(int $userId, array $param): \think\Paginator
{
@ -167,10 +168,11 @@ class UserCoupon extends UserCouponModel
* 订单结算优惠券列表
* @param int $userId 用户id
* @param float $orderPayPrice 订单商品总金额
* @param int $couponType
* @return array
* @throws \think\db\exception\DbException
* @throws DbException
*/
public static function getUserCouponList(int $userId, float $orderPayPrice, $couponType = TypeCase::SHOP): array
public static function getUserCouponList(int $userId, float $orderPayPrice, int $couponType = TypeCase::SHOP): array
{
// 判断订单商品总金额不能为1分
if ($orderPayPrice <= 0.01) {

@ -138,7 +138,7 @@ class Identity extends BaseService
*/
public function tradeQuery(string $outTradeNo): bool
{
$PaymentService = new PaymentService;
$PaymentService = new Payment();
return $PaymentService->setMethod($this->method)->setClient($this->client)->tradeQuery($outTradeNo);
}

@ -89,11 +89,11 @@ class Order extends BaseService
/**
* @notes:是否可以取消
* @param array $order
* @param $order
* @return bool
* @author: wanghousheng
*/
public static function checkCancel(array $order): bool
public static function checkCancel($order): bool
{
if (!empty($order['order_status']) && $order['order_status'] != ServerEnum::COMPLETED || $order['order_status'] != ServerEnum::CANCELLED) {
return true;
@ -103,12 +103,12 @@ class Order extends BaseService
/**
* @notes:是否可以派单
* @param array $order
* @param $order
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public static function checkDispatch(array $order): bool
public static function checkDispatch($order): bool
{
if (!empty($order) && $order['order_status'] == ServerEnum::APPLYDISPATCH && UserService::isStore()) {
return true;
@ -118,12 +118,12 @@ class Order extends BaseService
/**
* @notes:是否可以支付
* @param array $order
* @param $order
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public static function checkPay(array $order): bool
public static function checkPay($order): bool
{
$userId = UserService::getCurrentLoginUserId();
if (!empty($order) && $order['pay_status'] == PayStatus::PENDING && $order['user_id'] == $userId) {
@ -187,6 +187,8 @@ class Order extends BaseService
'coupon_money' => $data['coupon_money'],
'pay_price' => $data['pay_price'],
'buyer_remark' => $buyer_remark,
'create_time' => time(),
'update_time' => time(),
];
$model = new ServerOrder();
$order_id = $model->insertGetId($order_data);
@ -222,7 +224,7 @@ class Order extends BaseService
private function checkOut(): array
{
$info = Server::detail(['server_id' => $this->serverId, 'status' => 1], ['image', 'category']);
if ($info->isEmpty()) {
if (empty($info)) {
throwError('未找到服务信息');
}
$this->serverInfo = $info->toArray();
@ -244,7 +246,7 @@ class Order extends BaseService
/**
* 当前用户可用的优惠券列表
* @return array
* @throws DbException
* @throws DbException|BaseException
*/
private function getUserCouponList(): array
{
@ -252,8 +254,9 @@ class Order extends BaseService
if (!$this->checkoutRule['isCoupon']) {
return [];
}
$userId = UserService::getCurrentLoginUserId();
// 当前用户可用的优惠券列表
$couponList = UserCoupon::getUserCouponList($this->user['user_id'], $this->serverInfo['server_price'], TypeCase::SERVER);
$couponList = UserCoupon::getUserCouponList($userId, (float)$this->serverInfo['server_price'], TypeCase::SERVER);
// 判断当前优惠券是否满足订单使用条件 (优惠券适用范围)
return UserCoupon::couponListApplyRangeServer($couponList, [$this->serverId]);
}

Loading…
Cancel
Save