# 买家申请退款退货
文件路径:
shop/controllers/Buyer/Service/ReturnCtl.php
方法:
addReturn()
参数:
order\_id:“退款/退货”的订单号
goods\_id:“退款/退货”的订单商品id
return\_message:“退款/退货”说明
return\_reason\_id:“退款/退货”原因id
nums:“退款/退货”商品数量
# 1.根据goods\_id查找订单信息,将查找出的订单id与传递参数订单id进行比较。两者不一致,报错。
```
<pre class="calibre14">```
<span class="token2">if</span><span class="token1">(</span>$goods<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span> <span class="token">!==</span> $order_id<span class="token1">)</span>
<span class="token1">{</span>
$flag2 <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
# 2.判断订单状态,只有已付款订单才可进去“退款/退货”
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span> <span class="token"><</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED<span class="token1">)</span>
<span class="token1">{</span>
$flag2 <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
# 3.确定return\_type的值,判断此次的“退款/退货”究竟是退款,还是退货。
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'order_is_virtual'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$field<span class="token1">[</span><span class="token4">'return_type'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_VIRTUAL<span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
switch <span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
case Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED<span class="token1">:</span>$field<span class="token1">[</span><span class="token4">'return_type'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_ORDER <span class="token1">;</span> <span class="token5">//退款</span>
<span class="token2">break</span><span class="token1">;</span>
case Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_FINISH<span class="token1">:</span>$field<span class="token1">[</span><span class="token4">'return_type'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_GOODS <span class="token1">;</span> <span class="token5">//退货</span>
<span class="token2">break</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
```
```
# 4.如果是货到付款,确认收货(付款)后才能退款
```
<pre class="calibre14">```
<span class="token2">if</span><span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'payment_id'</span><span class="token1">]</span> <span class="token">==</span> PaymentChannlModel<span class="token1">:</span><span class="token1">:</span>PAY_CONFIRM<span class="token1">)</span><span class="token1">{</span>
<span class="token2">if</span><span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span> <span class="token"><</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_RECEIVED<span class="token1">)</span>
<span class="token1">{</span>
$flag2 <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
```
```
# 5.根据订单状态,确定return\_goods\_return值。
退款(货到付款只支持退货,不支持退款)
```
<pre class="calibre14">```
<span class="token2">if</span><span class="token1">(</span>$goods<span class="token1">[</span><span class="token4">'order_goods_status'</span><span class="token1">]</span> <span class="token">==</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED <span class="token">&&</span> $order<span class="token1">[</span><span class="token4">'payment_id'</span><span class="token1">]</span> <span class="token">!==</span> PaymentChannlModel<span class="token1">:</span><span class="token1">:</span>PAY_CONFIRM<span class="token1">)</span>
<span class="token1">{</span>
<span class="token5">//白条支付不支持退款和退货</span>
<span class="token2">if</span><span class="token1">(</span><span class="token3">strstr</span><span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'payment_name'</span><span class="token1">]</span><span class="token1">,</span><span class="token4">'白条支付'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">{</span>
$flag2 <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
$field<span class="token1">[</span><span class="token4">'return_goods_return'</span><span class="token1">]</span> <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span> <span class="token5">//是否需要退货 0-不需要 1-需要</span>
$<span class="token2">return</span> <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderReturnModel<span class="token">-</span><span class="token">></span><span class="token3">getByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span>
<span class="token4">'order_goods_id'</span> <span class="token">=</span><span class="token">></span> $goods_id<span class="token1">,</span>
<span class="token4">'return_type'</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_ORDER<span class="token1">,</span>
<span class="token4">'return_state:!='</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS
<span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
退货
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span>$goods<span class="token1">[</span><span class="token4">'order_goods_status'</span><span class="token1">]</span> <span class="token">==</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_FINISH<span class="token1">)</span>
<span class="token1">{</span>
<span class="token2">if</span><span class="token1">(</span><span class="token3">strstr</span><span class="token1">(</span>$order<span class="token1">[</span><span class="token4">'payment_name'</span><span class="token1">]</span><span class="token1">,</span><span class="token4">'白条支付'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">{</span>
$flag2 <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span>
$field<span class="token1">[</span><span class="token4">'return_goods_return'</span><span class="token1">]</span> <span class="token">=</span> <span class="token6">1</span><span class="token1">;</span> <span class="token5">//需要退货</span>
<span class="token5">//查询是否存在该订单商品的退货申请信息,且该申请未被卖家拒绝,以此判断是否重新提交退货申请</span>
<span class="token5">//只有以前没有提交过该商品的退货申请,且未被卖家拒绝的情况下,才可以提交退货申请</span>
$<span class="token2">return</span> <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderReturnModel<span class="token">-</span><span class="token">></span><span class="token3">getByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span>
<span class="token4">'order_goods_id'</span> <span class="token">=</span><span class="token">></span> $goods_id<span class="token1">,</span>
<span class="token4">'return_type'</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_GOODS<span class="token1">,</span>
<span class="token4">'return_state:!='</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS
<span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
# 6.计算生成“退款/退货”订单所需要的各种金额
//判断这件“退款/退货”商品是否还有可退数量(退款,退货都会退还商品数量)
```
<pre class="calibre14">```
$this_goods_return <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderReturnModel<span class="token">-</span><span class="token">></span><span class="token3">getByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span>
<span class="token4">'order_goods_id'</span> <span class="token">=</span><span class="token">></span> $goods_id<span class="token1">,</span>
<span class="token4">'return_state:!='</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS
<span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
```
```
- $this\_goods\_return\_num :“退款/退货”商品总的已退还件数
- $this\_goods\_return\_cash :“退款/退货”商品总的已退金额(包含正在审核中的金额)
//查找该笔订单已经进行过或正进行中的的退款,退货
```
<pre class="calibre14">```
$order_return <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderReturnModel<span class="token">-</span><span class="token">></span><span class="token3">getByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span>
<span class="token4">'order_number'</span> <span class="token">=</span><span class="token">></span> $order<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span><span class="token1">,</span>
<span class="token4">'return_state:!='</span> <span class="token">=</span><span class="token">></span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS
<span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
```
```
//订单已经退款退货的金额(包括与同意的退款和正在审核中的退款)
```
<pre class="calibre14">```
$order_return_cash <span class="token">=</span> <span class="token3">array_sum</span><span class="token1">(</span><span class="token3">array_column</span><span class="token1">(</span>$order_return<span class="token1">,</span> <span class="token4">'return_cash'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
```
```
//订单已经退还的商品数量
```
<pre class="calibre14">```
$order_return_num <span class="token">=</span> <span class="token3">array_sum</span><span class="token1">(</span><span class="token3">array_column</span><span class="token1">(</span>$order_return<span class="token1">,</span> <span class="token4">'order_goods_num'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
```
```
//订单还可退还的金额 = 订单实付金额 - 订单已退金额
//如果没有发货,可以退运费
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span>Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED <span class="token">==</span> $order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$order_can_return_cash <span class="token">=</span> $order<span class="token1">[</span><span class="token4">'order_payment_amount'</span><span class="token1">]</span> <span class="token">-</span> $order_return_cash<span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$order_can_return_cash <span class="token">=</span> $order<span class="token1">[</span><span class="token4">'order_payment_amount'</span><span class="token1">]</span> <span class="token">-</span> $order_return_cash <span class="token">-</span> $order<span class="token1">[</span><span class="token4">'order_shipping_fee'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/*
* $data['order']['order_refund_amount'] 与 $order_return_cash 的区别
* $data['order']['order_refund_amount']:表示商家已经同意的退款金额
* $order_return_cash:表示买家已经申请的退款,除被商家拒绝的退款外,正在审核的退款也包含在内
*/</span>
<span class="token5">//订单已退还的金额</span>
$return_limit <span class="token">=</span> $order<span class="token1">[</span><span class="token4">'order_refund_amount'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token5">//订单可退金额</span>
$cash_limit <span class="token">=</span> $order_can_return_cash<span class="token1">;</span>
<span class="token5">//订单可退商品数量</span>
$goods_can_return_nums <span class="token">=</span> $order_all_goods_num <span class="token">-</span> $order_return_num<span class="token1">;</span>
<span class="token5">//该件商品可退的总金额</span>
$return_goods_cash <span class="token">=</span> $goods<span class="token1">[</span><span class="token4">'order_goods_amount'</span><span class="token1">]</span> <span class="token">-</span> $this_goods_return_cash<span class="token1">;</span>
<span class="token5">//该件商品还可退还商品数量</span>
$return_goods_nums <span class="token">=</span> $goods<span class="token1">[</span><span class="token4">'order_goods_num'</span><span class="token1">]</span> <span class="token">-</span> $this_goods_return_num<span class="token1">;</span>
```
```
//实际该件商品可退还的金额(有时可能包含运费)
//该件商品全部“退款/退货” //return\_goods\_nums
```
<pre class="calibre14">```
<span class="token2">if</span><span class="token1">(</span>$goods_can_return_nums <span class="token">==</span> $nums <span class="token">&&</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED <span class="token">==</span> $order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token5">//加上运费(未发货)</span>
$return_cash <span class="token">=</span> $return_goods_cash <span class="token">+</span> $order<span class="token1">[</span><span class="token4">'order_shipping_fee'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$return_cash <span class="token">=</span> <span class="token3">floor</span><span class="token1">(</span>$nums <span class="token">*</span> $goods<span class="token1">[</span><span class="token4">'order_goods_payment_amount'</span><span class="token1">]</span> <span class="token">*</span> <span class="token6">100</span><span class="token1">)</span> <span class="token">/</span> <span class="token6">100</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">//如果订单为已付款状态,并且所有商品都退款,则将运费退还</span>
<span class="token2">if</span><span class="token1">(</span>Order_StateModel<span class="token1">:</span><span class="token1">:</span>ORDER_PAYED <span class="token">==</span> $order<span class="token1">[</span><span class="token4">'order_status'</span><span class="token1">]</span> <span class="token">&&</span> $nums <span class="token">==</span> $goods_can_return_nums<span class="token1">)</span>
<span class="token1">{</span>
$return_cash <span class="token">=</span> $cash_limit<span class="token1">;</span>
<span class="token1">}</span>
<span class="token5">/*退款退货走同样的流程。区别是:退款时可能会退还运费,退货不可能退还运费。*/</span>
```
```
# 7.订单商品表中插入订单商品的“退款/退货”状态
```
<pre class="calibre15">```
<span class="token2">if</span><span class="token1">(</span>$field<span class="token1">[</span><span class="token4">'return_goods_return'</span><span class="token1">]</span> <span class="token">==</span> <span class="token6">0</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token5">//退款</span>
$goods_field<span class="token1">[</span><span class="token4">'goods_return_status'</span><span class="token1">]</span> <span class="token">=</span> Order_GoodsModel<span class="token1">:</span><span class="token1">:</span>REFUND_IN<span class="token1">;</span>
$edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderGoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$goods_id<span class="token1">,</span> $goods_field<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$edit_flag<span class="token1">,</span> $rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
<span class="token5">//退货</span>
$goods_field<span class="token1">[</span><span class="token4">'goods_refund_status'</span><span class="token1">]</span> <span class="token">=</span> Order_GoodsModel<span class="token1">:</span><span class="token1">:</span>REFUND_IN<span class="token1">;</span>
$edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderGoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$goods_id<span class="token1">,</span> $goods_field<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$edit_flag<span class="token1">,</span> $rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
- 序言
- 系统要求
- 版本更新日志
- 远丰商城技术对接说明
- 开发指导
- 框架内容
- 基础
- 开发规范
- 目录结构
- 架构
- 架构总览
- 数据库
- 数据库连接
- 基本使用
- 缓存
- 配置
- 路由
- 数据字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- 通讯内容
- 商家中心
- 顶部导航栏
- 店铺信息栏
- 店铺及商品提示栏
- 交易提示栏
- 销售情况统计栏
- 单品销量排行栏
- 店铺运营推广栏
- 平台联系方式栏
- 订单物流
- 商品
- 商品列表
- 商品详情
- 商品发布与编辑
- 分销商品
- 关联版式
- 商品规格
- 图片空间
- 淘宝导入
- 订单流程
- 交易订单
- 订单退款/退货
- 促销
- 团购管理
- 加价购
- 限时折扣
- 满即送
- 代金券管理
- 分销
- 店铺
- 店铺设置
- 自销产品供应商
- 实体店铺
- 品牌申请
- 店铺信息
- 消费者保障服务
- 门店账号
- 分销商--产品供应商
- 分销明细
- 批发市场
- 售后服务
- 咨询管理
- 投诉管理
- 退款管理
- 退货管理
- 云方案架构
- 负载集群
- 云存储
- 接口
- Api接口说明
- 品牌
- 商品规格
- 商品类型
- 商品分类
- 商品
- 订单
- 商品/店铺收藏
- 足迹
- 退款及退货
- 商家店铺
- 会员
- 入驻协议
- 订单接口
- 商品接口
- 订单物流接口
- 商家中心接口
- 促销接口
- 快递鸟物流接口
- 代金券接口
- 首页版块
- 团购
- 平台红包
- 限时折扣接口
- 拼团接口
- wap首页模板
- 杂项
- 远程上传图片
- JS
- 银联支付
- 多语言
- 商品评分
- 图片加载
- 买家申请退款退货
- 商家退款退货
- 平台退款退货
- 添加发票
- 提交订单
- 确认订单
- 运费销售区域
- 获取会员地址
- 充值
- 导出XLS
- 商城系统集成
- 多语言实现
- 三级分销推广链接发展推广员
- app.ini.php
- 去分销
- 版本更新
- 物流支持
- 运营人员建议
- 业务逻辑
- 统计结算
- 客服消息
- 账号
- 三级分销
- IM
- 配置
- 平台帐号
- 活动数据表说明