【类 型】:feat

【原  因】:小程序端 请求 退款接口
【过  程】:refundOrder 订单申请退款接口 数据检验 ;更新数据订单状态;返回修改状态
【影  响】:
This commit is contained in:
air 2025-01-15 12:43:52 +08:00
parent 4df3ce7d3d
commit b58e30b2af

View File

@ -180,12 +180,36 @@ class CheckController extends PublicController
*/
public function refundOrder()
{
$orderDb = D('order');
$where['order_sn'] = $_REQUEST['order_sn'];
$where['shop_id'] = $_REQUEST['shop_id'];
$where['openid'] = $this->openid;
$n = $orderDb->where($where)->select();
echo json_encode(array('status' => 0, 'msg' => $this->openid));
if ($_REQUEST['order_sn'] && $_REQUEST['shop_id'] && $_REQUEST['refund_remark']) {
$orderDb = D('order');
$where['order_sn'] = $_REQUEST['order_sn'];
$where['shop_id'] = $_REQUEST['shop_id'];
$where['openid'] = $this->openid;
$order = $orderDb->where($where)->find();
// 获取 apply_price 并强制转换为浮动类型,保留两位小数
$applyPrice = round(floatval($_REQUEST['apply_price']), 2);
// 获取订单的 total_price 并强制转换为浮动类型,保留两位小数
$totalPrice = round(floatval($order['total_price']), 2);
// 比较时确保两者都是浮动类型并且格式一致
if ($applyPrice > $totalPrice) {
echo json_encode(array('status' => 0, 'msg' => '申请退款金额不能超过订单总额'));
exit();
}
$data['apply_price'] = $applyPrice;
$data['refund_remark'] = $_REQUEST['refund_remark'];
$data['refundapply_time'] = time();
$data['refund_status'] = '申请中';
$isRefund = $orderDb->where($where)->data($data)->save();
if ($isRefund) {
echo json_encode(array('status' => 1, 'msg' => '申请退款成功'));
} else {
echo json_encode(array('status' => 0, 'msg' => '申请退款失败'));
}
} else {
echo json_encode(array('status' => 0, 'msg' => '参数错误'));
exit();
}
}
/**
* @description: 对应用户的订单列表