Browse Source

金额格式优化

yijia
v-Brocloni 3 years ago
parent
commit
b8e936dc09
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      application/admin/controller/unishop/Order.php

+ 21
- 0
application/admin/controller/unishop/Order.php View File

@@ -668,6 +668,9 @@ class Order extends Backend
public function doRefund(){ public function doRefund(){
$order_id = $this->request->get('id'); $order_id = $this->request->get('id');
$refund_fee = $this->request->get("refund_fee",0); $refund_fee = $this->request->get("refund_fee",0);
if (!$this->isAmount($refund_fee)) {
$this->error("退款金额格式错误");
}
$order = $this->model->where([ $order = $this->model->where([
'id' => $order_id, 'id' => $order_id,
'status'=>1,//订单状态正常 'status'=>1,//订单状态正常
@@ -693,6 +696,24 @@ class Order extends Backend
$this->success("提交成功", null); $this->success("提交成功", null);


} }
/**
* 金额校验函数
* @param $value
* @param bool $isZero
* @param bool $negative
* @return bool
*/
function isAmount($value){
// 必须是整数或浮点数,且允许为负
if (!preg_match("/^[-]?\d+(.\d{1,2})?$/", $value)){
return false;
}
// 不为负数
if ((int)($value * 100) < 0){
return false;
}
return true;
}


static function refundOrder($order,$refund_fee){ static function refundOrder($order,$refund_fee){
if ($refund_fee == 0) {//如果未传入金额,则使用总金额 if ($refund_fee == 0) {//如果未传入金额,则使用总金额


Loading…
Cancel
Save