🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
文件路径: shop/controllers/Buyer/Service/ReturnCtl.php 方法: addReturn() 参数: order_id:“退款/退货”的订单号 goods_id:“退款/退货”的订单商品id return_message:“退款/退货”说明 return_reason_id:“退款/退货”原因id nums:“退款/退货”商品数量 # 1.根据goods_id查找订单信息,将查找出的订单id与传递参数订单id进行比较。两者不一致,报错。 if($goods['order_id'] !== $order_id) { $flag2 = false; } # 2.判断订单状态,只有已付款订单才可进去“退款/退货” if ($order['order_status'] < Order_StateModel::ORDER_PAYED) { $flag2 = false; } # 3.确定return_type的值,判断此次的“退款/退货”究竟是退款,还是退货。 if ($order['order_is_virtual']) { $field['return_type'] = Order_ReturnModel::RETURN_TYPE_VIRTUAL; } else { switch ($order['order_status']) { case Order_StateModel::ORDER_PAYED:$field['return_type'] = Order_ReturnModel::RETURN_TYPE_ORDER ; //退款 break; case Order_StateModel::ORDER_FINISH:$field['return_type'] = Order_ReturnModel::RETURN_TYPE_GOODS ; //退货 break; } } # 4.如果是货到付款,确认收货(付款)后才能退款 if($order['payment_id'] == PaymentChannlModel::PAY_CONFIRM){ if($order['order_status'] < Order_StateModel::ORDER_RECEIVED) { $flag2 = false; } } # 5.根据订单状态,确定return_goods_return值。 退款(货到付款只支持退货,不支持退款) if($goods['order_goods_status'] == Order_StateModel::ORDER_PAYED && $order['payment_id'] !== PaymentChannlModel::PAY_CONFIRM) { //白条支付不支持退款和退货 if(strstr($order['payment_name'],'白条支付')){ $flag2 = false; } $field['return_goods_return'] = 0; //是否需要退货 0-不需要 1-需要 $return = $this->orderReturnModel->getByWhere(array( 'order_goods_id' => $goods_id, 'return_type' => Order_ReturnModel::RETURN_TYPE_ORDER, 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); } 退货 if ($goods['order_goods_status'] == Order_StateModel::ORDER_FINISH) { if(strstr($order['payment_name'],'白条支付')){ $flag2 = false; } $field['return_goods_return'] = 1; //需要退货 //查询是否存在该订单商品的退货申请信息,且该申请未被卖家拒绝,以此判断是否重新提交退货申请 //只有以前没有提交过该商品的退货申请,且未被卖家拒绝的情况下,才可以提交退货申请 $return = $this->orderReturnModel->getByWhere(array( 'order_goods_id' => $goods_id, 'return_type' => Order_ReturnModel::RETURN_TYPE_GOODS, 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); } # 6.计算生成“退款/退货”订单所需要的各种金额 //判断这件“退款/退货”商品是否还有可退数量(退款,退货都会退还商品数量) $this_goods_return = $this->orderReturnModel->getByWhere(array( 'order_goods_id' => $goods_id, 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); $this_goods_return_num :“退款/退货”商品总的已退还件数 $this_goods_return_cash :“退款/退货”商品总的已退金额(包含正在审核中的金额) //查找该笔订单已经进行过或正进行中的的退款,退货 $order_return = $this->orderReturnModel->getByWhere(array( 'order_number' => $order['order_id'], 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); //订单已经退款退货的金额(包括与同意的退款和正在审核中的退款) $order_return_cash = array_sum(array_column($order_return, 'return_cash')); //订单已经退还的商品数量 $order_return_num = array_sum(array_column($order_return, 'order_goods_num')); //订单还可退还的金额 = 订单实付金额 - 订单已退金额 //如果没有发货,可以退运费 if (Order_StateModel::ORDER_PAYED == $order['order_status']) { $order_can_return_cash = $order['order_payment_amount'] - $order_return_cash; } else { $order_can_return_cash = $order['order_payment_amount'] - $order_return_cash - $order['order_shipping_fee']; } /* * $data['order']['order_refund_amount'] 与 $order_return_cash 的区别 * $data['order']['order_refund_amount']:表示商家已经同意的退款金额 * $order_return_cash:表示买家已经申请的退款,除被商家拒绝的退款外,正在审核的退款也包含在内 */ //订单已退还的金额 $return_limit = $order['order_refund_amount']; //订单可退金额 $cash_limit = $order_can_return_cash; //订单可退商品数量 $goods_can_return_nums = $order_all_goods_num - $order_return_num; //该件商品可退的总金额 $return_goods_cash = $goods['order_goods_amount'] - $this_goods_return_cash; //该件商品还可退还商品数量 $return_goods_nums = $goods['order_goods_num'] - $this_goods_return_num; //实际该件商品可退还的金额(有时可能包含运费) //该件商品全部“退款/退货” //return_goods_nums if($goods_can_return_nums == $nums && Order_StateModel::ORDER_PAYED == $order['order_status']) { //加上运费(未发货) $return_cash = $return_goods_cash + $order['order_shipping_fee']; } else { $return_cash = floor($nums * $goods['order_goods_payment_amount'] * 100) / 100; } //如果订单为已付款状态,并且所有商品都退款,则将运费退还 if(Order_StateModel::ORDER_PAYED == $order['order_status'] && $nums == $goods_can_return_nums) { $return_cash = $cash_limit; } /*退款退货走同样的流程。区别是:退款时可能会退还运费,退货不可能退还运费。*/ # 7.订单商品表中插入订单商品的“退款/退货”状态 if($field['return_goods_return'] == 0) { //退款 $goods_field['goods_return_status'] = Order_GoodsModel::REFUND_IN; $edit_flag = $this->orderGoodsModel->editGoods($goods_id, $goods_field); check_rs($edit_flag, $rs_row); } else { //退货 $goods_field['goods_refund_status'] = Order_GoodsModel::REFUND_IN; $edit_flag = $this->orderGoodsModel->editGoods($goods_id, $goods_field); check_rs($edit_flag, $rs_row); }