# 退货管理
一、买家申请退货
文件路径:shop/controllers/Buyer/Service/ReturnCtl.php
```
<pre class="calibre14">```
<span class="token5">//根据URL参数act,判断视图</span>
<span class="token2">if</span> <span class="token1">(</span>$act <span class="token">==</span> <span class="token4">"detail"</span><span class="token1">)</span>
<span class="token1">{</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">detail</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'detail'</span><span class="token1">)</span><span class="token1">;</span>
$d <span class="token">=</span> $data<span class="token1">;</span>
<span class="token1">}</span>
elseif <span class="token1">(</span>$act <span class="token">==</span> <span class="token4">"add"</span><span class="token1">)</span>
<span class="token1">{</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">add</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$data <span class="token">==</span> <span class="token">-</span><span class="token6">3</span><span class="token1">)</span>
<span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'error3'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token3">elseif</span><span class="token1">(</span>$data <span class="token">==</span> <span class="token">-</span><span class="token6">4</span><span class="token1">)</span><span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'error4'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
elseif <span class="token1">(</span>$data <span class="token">==</span> <span class="token">-</span><span class="token6">1</span><span class="token1">)</span>
<span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'error2'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
elseif <span class="token1">(</span>$data <span class="token">==</span> <span class="token6">0</span><span class="token1">)</span>
<span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'error'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'add'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
```
```
视图:shop/views/default/Buyer/Service/ReturnCtl/add.php
退货表单提交:
```
<pre class="calibre14">```
$<span class="token1">(</span><span class="token4">'#form'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">validator</span><span class="token1">(</span><span class="token1">{</span>
<span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">"click"</span><span class="token1">,</span> <span class="token4">"#handle_submit"</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span>e<span class="token1">)</span>
<span class="token1">{</span>
submit_trigger
<span class="token">?</span> $<span class="token1">(</span>e<span class="token1">.</span>delegateTarget<span class="token1">)</span><span class="token1">.</span><span class="token3">trigger</span><span class="token1">(</span><span class="token4">"validate"</span><span class="token1">)</span>
<span class="token1">:</span> submit_trigger <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
```
```
方法:addReturn()
```
<pre class="calibre14">```
<span class="token5">//退货</span>
<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>
```
```
二、卖家审核退货申请Seller\_Service\_Return&met=goodsReturn&act=detail
文件路径:shop/controllers/Seller/Service/ReturnCtl.php
```
<pre class="calibre14">```
<span class="token5">//根据URL参数act,判断视图</span>
<span class="token2">if</span> <span class="token1">(</span>$act <span class="token">==</span> <span class="token4">"detail"</span><span class="token1">)</span>
<span class="token1">{</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">detail</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'detail'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
视图:shop/views/default/Seller/Service/ReturnCtl/detail.php
卖家审核表单提交:
```
<pre class="calibre14">```
$<span class="token1">(</span><span class="token4">'#form'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">validator</span><span class="token1">(</span><span class="token1">{</span>
<span class="token5">//审核</span>
<span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">"click"</span><span class="token1">,</span> <span class="token4">"#handle_submit"</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span>e<span class="token1">)</span>
<span class="token1">{</span>
ajax_url <span class="token">=</span> SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Seller_Service_Return&met=agreeReturn&typ=json'</span><span class="token1">;</span>
$<span class="token1">(</span>e<span class="token1">.</span>delegateTarget<span class="token1">)</span><span class="token1">.</span><span class="token3">trigger</span><span class="token1">(</span><span class="token4">"validate"</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">"click"</span><span class="token1">,</span> <span class="token4">"#handle_close"</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span>e<span class="token1">)</span>
<span class="token1">{</span>
ajax_url <span class="token">=</span> SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Seller_Service_Return&met=closeReturn&typ=json'</span><span class="token1">;</span>
$<span class="token1">(</span>e<span class="token1">.</span>delegateTarget<span class="token1">)</span><span class="token1">.</span><span class="token3">trigger</span><span class="token1">(</span><span class="token4">"validate"</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
```
```
审核同意方法:agreeReturn()
```
<pre class="calibre14">```
$data<span class="token1">[</span><span class="token4">'return_shop_message'</span><span class="token1">]</span> <span class="token">=</span> $return_shop_message<span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_goods_return'</span><span class="token1">]</span> <span class="token">==</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_GOODS_RETURN<span class="token1">)</span>
<span class="token1">{</span>
$data<span class="token1">[</span><span class="token4">'return_state'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_PASS<span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$data<span class="token1">[</span><span class="token4">'return_state'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_GOODS<span class="token1">;</span>
<span class="token1">}</span>
$data<span class="token1">[</span><span class="token4">'return_shop_handle'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_PASS<span class="token1">;</span>
$data<span class="token1">[</span><span class="token4">'return_shop_time'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">get_date_time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$flag <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">editReturn</span><span class="token1">(</span>$order_return_id<span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
```
```
审核不同意方法:closeReturn()
```
<pre class="calibre14">```
$data<span class="token1">[</span><span class="token4">'return_shop_message'</span><span class="token1">]</span> <span class="token">=</span> $return_shop_message<span class="token1">;</span>
$data<span class="token1">[</span><span class="token4">'return_state'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS<span class="token1">;</span>
$data<span class="token1">[</span><span class="token4">'return_shop_handle'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_UNPASS<span class="token1">;</span>
$data<span class="token1">[</span><span class="token4">'return_shop_time'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">get_date_time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$rs_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>orderReturnModel<span class="token">-</span><span class="token">></span>sql<span class="token">-</span><span class="token">></span><span class="token3">startTransactionDb</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$edit_flag <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">editReturn</span><span class="token1">(</span>$order_return_id<span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
```
```
三、卖家确认收获
文件路径:shop/controllers/Seller/Service/ReturnCtl.php
视图:shop/views/default/Seller/Service/ReturnCtl/detail.php
```
<pre class="calibre14">```
$<span class="token1">(</span><span class="token4">'#form2'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">validator</span><span class="token1">(</span><span class="token1">{</span>
ignore<span class="token1">:</span> <span class="token4">':hidden'</span><span class="token1">,</span>
theme<span class="token1">:</span> <span class="token4">'yellow_right'</span><span class="token1">,</span>
timely<span class="token1">:</span> <span class="token6">1</span><span class="token1">,</span>
stopOnError<span class="token1">:</span> <span class="token6">false</span><span class="token1">,</span>
fields<span class="token1">:</span> <span class="token1">{</span><span class="token1">}</span><span class="token1">,</span>
valid<span class="token1">:</span> <span class="token2">function</span> <span class="token1">(</span>form<span class="token1">)</span>
<span class="token1">{</span>
<span class="token5">//表单验证通过,提交表单</span>
$<span class="token1">.</span><span class="token3">ajax</span><span class="token1">(</span><span class="token1">{</span>
url<span class="token1">:</span> SITE_URL <span class="token">+</span> <span class="token4">'?ctl=Seller_Service_Return&met=agreeGoods&typ=json'</span><span class="token1">,</span>
data<span class="token1">:</span> $<span class="token1">(</span><span class="token4">"#form2"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">serialize</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span>
success<span class="token1">:</span> <span class="token2">function</span> <span class="token1">(</span>a<span class="token1">)</span>
<span class="token1">{</span>
<span class="token2">if</span> <span class="token1">(</span>a<span class="token1">.</span>status <span class="token">==</span> <span class="token6">200</span><span class="token1">)</span>
<span class="token1">{</span>
location<span class="token1">.</span>href <span class="token">=</span> "<span class="token1">.</span><span class="token">/</span>index<span class="token1">.</span>php<span class="token">?</span>ctl<span class="token">=</span>Seller_Service_Return<span class="token">&</span>met<span class="token">=</span><span class="token"><</span><span class="token">?</span>php <span class="token2">if</span> <span class="token1">(</span>$data<span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
echo <span class="token4">"goodsReturn"</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
echo <span class="token4">"orderReturn"</span><span class="token1">;</span>
<span class="token1">}</span><span class="token">?</span><span class="token">></span><span class="token">&</span>act<span class="token">=</span>detail<span class="token">&</span>id<span class="token">=</span>" <span class="token">+</span> order_return_id<span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
Public<span class="token1">.</span>tips<span class="token1">.</span><span class="token3">error</span><span class="token1">(</span><span class="token4">'<?=__('</span>操作失败!<span class="token4">')?>'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">"click"</span><span class="token1">,</span> <span class="token4">"#handle_goods"</span><span class="token1">,</span> <span class="token2">function</span> <span class="token1">(</span>e<span class="token1">)</span>
<span class="token1">{</span>
$<span class="token1">(</span>e<span class="token1">.</span>delegateTarget<span class="token1">)</span><span class="token1">.</span><span class="token3">trigger</span><span class="token1">(</span><span class="token4">"validate"</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span><span class="token1">)</span><span class="token1">;</span>
```
```
方法:agreeGoods()
```
<pre class="calibre14">```
$data<span class="token1">[</span><span class="token4">'return_state'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_GOODS<span class="token1">;</span>
$flag <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">editReturn</span><span class="token1">(</span>$order_return_id<span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$flag<span class="token1">,</span>$rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//如果订单为分销商采购单,扣除分销商的钱</span>
<span class="token2">if</span><span class="token1">(</span>$order_base<span class="token1">[</span><span class="token4">'order_source_id'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$dist_order <span class="token">=</span> $Order_BaseModel <span class="token">-</span><span class="token">></span> <span class="token3">getOneByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span><span class="token4">'order_id'</span><span class="token">=</span><span class="token">></span>$order_base<span class="token1">[</span><span class="token4">'order_source_id'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span><span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$dist_order<span class="token1">)</span><span class="token1">)</span><span class="token1">{</span>
$dist_return_order <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">getOneByWhere</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>$dist_order<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span><span class="token1">,</span><span class="token4">'return_type'</span><span class="token">=</span><span class="token">></span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_type'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
$flag <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">editReturn</span><span class="token1">(</span>$dist_return_order<span class="token1">[</span><span class="token4">'order_return_id'</span><span class="token1">]</span><span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$flag<span class="token1">,</span>$rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
四、平台审核
文件路径:shop/controllers/Api/Trade/ReturnCtl.php
视图:shop\_admin/view/default/Trade/ReturnCtl/detail.php
JS:shop\_admin/static/default/js/controllers/trade/return/detail.js
五、卖家退货管理
文件路径:shop/controllers/Seller/Service/ReturnCtl.php
- 退货流程:申请退货->卖家同意->买家退货->退货成功
- 退货状态:
```
<pre class="calibre14">```
<span class="token5">//模型:shop/models/Order/ReturnModel.php</span>
public <span class="token2">function</span> <span class="token3">__construct</span><span class="token1">(</span><span class="token1">)</span>
<span class="token1">{</span>
parent<span class="token1">:</span><span class="token1">:</span><span class="token3">__construct</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>return_state <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span>
<span class="token4">'1'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"等待卖家审核"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'2'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"卖家审核通过"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'3'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"卖家审核未通过"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'4'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"等待平台审核"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'5'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"退款/货完成"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>return_type <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span>
<span class="token4">'1'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"退款"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'2'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"退货"</span><span class="token1">)</span><span class="token1">,</span>
<span class="token4">'3'</span> <span class="token">=</span><span class="token">></span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"虚拟订单退款"</span><span class="token1">)</span>
<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
- 视图:根据URL获得参数act的值,判断视图
```
<pre class="calibre14">```
<span class="token2">if</span> <span class="token1">(</span>$act <span class="token">==</span> <span class="token4">"detail"</span><span class="token1">)</span>
<span class="token1">{</span>
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">detail</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'detail'</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
<span class="token5">//goodsReturn.php</span>
<span class="token1">}</span>
```
```
1.退货管理列表
方法:goodsReturn()、listReturn()
```
<pre class="calibre14">```
$data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span><span class="token3">listReturn</span><span class="token1">(</span>Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_TYPE_ORDER<span class="token1">)</span><span class="token1">;</span>
public <span class="token2">function</span> <span class="token3">listReturn</span><span class="token1">(</span>$type<span class="token1">)</span>
<span class="token1">{</span>
$data <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">getReturnList</span><span class="token1">(</span>$cond_row<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'return_add_time'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'DESC'</span><span class="token1">)</span><span class="token1">,</span> $page<span class="token1">,</span> $rows<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
2.查看退货详情
视图:shop/views/default/Seller/Service/ReturnCtl/detail.php
- 卖家同意退货方法:agreeReturn()
```
<pre class="calibre14">```
<span class="token5">//判断该笔退款金额的订单是否已经结算</span>
$Order_BaseModel <span class="token">=</span> <span class="token2">new</span> <span class="token3">Order_BaseModel</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$order_base <span class="token">=</span> $Order_BaseModel<span class="token">-</span><span class="token">></span><span class="token3">getOne</span><span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_number'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
<span class="token5">//判断该笔订单是否已经收货,如果没有收货的话,不扣除卖家资金。已确认收货则扣除卖家资金</span>
<span class="token2">if</span><span class="token1">(</span>$order_base<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_FINISH <span class="token1">)</span>
<span class="token1">{</span>
$order_finish <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span>
<span class="token5">//获取用户的账户资金资源</span>
$key <span class="token">=</span> Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'shop_api_key'</span><span class="token1">)</span><span class="token1">;</span>
$formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$user_id <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$userId<span class="token1">;</span>
$formvars<span class="token1">[</span><span class="token4">'user_id'</span><span class="token1">]</span> <span class="token">=</span> $user_id<span class="token1">;</span>
$formvars<span class="token1">[</span><span class="token4">'app_id'</span><span class="token1">]</span> <span class="token">=</span> Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'shop_app_id'</span><span class="token1">)</span><span class="token1">;</span>
$money_row <span class="token">=</span> <span class="token3">get_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> <span class="token3">sprintf</span><span class="token1">(</span><span class="token4">'%s?ctl=Api_User_Info&met=getUserResourceInfo&typ=json'</span><span class="token1">,</span> Yf_Registry<span class="token1">:</span><span class="token1">:</span><span class="token3">get</span><span class="token1">(</span><span class="token4">'paycenter_api_url'</span><span class="token1">)</span><span class="token1">)</span><span class="token1">,</span> $formvars<span class="token1">)</span><span class="token1">;</span>
$user_money <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span>
$user_money_frozen <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span>
<span class="token2">if</span> <span class="token1">(</span>$money_row<span class="token1">[</span><span class="token4">'status'</span><span class="token1">]</span> <span class="token">==</span> <span class="token4">'200'</span><span class="token1">)</span>
<span class="token1">{</span>
$money <span class="token">=</span> $money_row<span class="token1">[</span><span class="token4">'data'</span><span class="token1">]</span><span class="token1">;</span>
$user_money <span class="token">=</span> $money<span class="token1">[</span><span class="token4">'user_money'</span><span class="token1">]</span><span class="token1">;</span>
$user_money_frozen <span class="token">=</span> $money<span class="token1">[</span><span class="token4">'user_money_frozen'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
$shop_return_amount <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_cash'</span><span class="token1">]</span> <span class="token">-</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_commision_fee'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token5">//获取该店铺最新的结算结束日期</span>
$Order_SettlementModel <span class="token">=</span> <span class="token2">new</span> <span class="token3">Order_SettlementModel</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span>
$settlement_last_info <span class="token">=</span> $Order_SettlementModel<span class="token">-</span><span class="token">></span><span class="token3">getLastSettlementByShopid</span><span class="token1">(</span>Perm<span class="token1">:</span><span class="token1">:</span>$shopId<span class="token1">,</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_is_virtual'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span><span class="token1">(</span>$settlement_last_info<span class="token1">)</span>
<span class="token1">{</span>
$settlement_unixtime <span class="token">=</span> $settlement_last_info<span class="token1">[</span><span class="token4">'os_end_date'</span><span class="token1">]</span> <span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$settlement_unixtime <span class="token">=</span> <span class="token4">''</span><span class="token1">;</span>
<span class="token1">}</span>
$settlement_unixtime <span class="token">=</span> <span class="token3">strtotime</span><span class="token1">(</span>$settlement_unixtime<span class="token1">)</span><span class="token1">;</span>
$order_finish_time <span class="token">=</span> $order_base<span class="token1">[</span><span class="token4">'order_finished_time'</span><span class="token1">]</span><span class="token1">;</span>
$order_finish_unixtime <span class="token">=</span> <span class="token3">strtotime</span><span class="token1">(</span>$order_finish_time<span class="token1">)</span><span class="token1">;</span>
<span class="token3">fb</span><span class="token1">(</span>$settlement_unixtime<span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span><span class="token1">(</span>$settlement_unixtime <span class="token">>=</span> $order_finish_unixtime <span class="token1">)</span>
<span class="token1">{</span>
<span class="token5">//结算时间大于订单完成时间。需要扣除卖家的现金账户</span>
$money <span class="token">=</span> $user_money<span class="token1">;</span>
$pay_type <span class="token">=</span> <span class="token4">'cash'</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
<span class="token5">//结算时间小于订单完成时间。需要扣除卖家的冻结资金,如果冻结资金不足就扣除账户余额</span>
$money <span class="token">=</span> $user_money_frozen <span class="token">+</span> $user_money<span class="token1">;</span>
$pay_type <span class="token">=</span> <span class="token4">'frozen_cash'</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$order_finish <span class="token">=</span> <span class="token6">true</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
- 卖家确认收货:agreeGoods()
```
<pre class="calibre14">```
$data<span class="token1">[</span><span class="token4">'return_state'</span><span class="token1">]</span> <span class="token">=</span> Order_ReturnModel<span class="token1">:</span><span class="token1">:</span>RETURN_SELLER_GOODS<span class="token1">;</span>
$flag <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">editReturn</span><span class="token1">(</span>$order_return_id<span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$flag<span class="token1">,</span>$rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//如果订单为分销商采购单,扣除分销商的钱</span>
<span class="token2">if</span><span class="token1">(</span>$order_base<span class="token1">[</span><span class="token4">'order_source_id'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$dist_order <span class="token">=</span> $Order_BaseModel <span class="token">-</span><span class="token">></span> <span class="token3">getOneByWhere</span><span class="token1">(</span><span class="token3">array</span><span class="token1">(</span><span class="token4">'order_id'</span><span class="token">=</span><span class="token">></span>$order_base<span class="token1">[</span><span class="token4">'order_source_id'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
<span class="token2">if</span><span class="token1">(</span><span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$dist_order<span class="token1">)</span><span class="token1">)</span><span class="token1">{</span>
$dist_return_order <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">getOneByWhere</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>$dist_order<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span><span class="token1">,</span><span class="token4">'return_type'</span><span class="token">=</span><span class="token">></span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_type'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span>
$flag <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">editReturn</span><span class="token1">(</span>$dist_return_order<span class="token1">[</span><span class="token4">'order_return_id'</span><span class="token1">]</span><span class="token1">,</span> $data<span class="token1">)</span><span class="token1">;</span>
<span class="token3">check_rs</span><span class="token1">(</span>$flag<span class="token1">,</span>$rs_row<span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
```
```
- 卖家不同意退货方法:closeReturn()
`$edit_flag = $this->orderReturnModel->editReturn($order_return_id, $data);`
六、买家退货管理
1.退货申请列表
文件路径:shop/controllers/Buyer/Service/ReturnCtl.php
视图:shop/views/default/Buyer/Service/ReturnCtl/index.php
`$data = $this->orderReturnModel->getReturnList($cond_row, array('return_add_time' => 'DESC'), $page, $rows);`
2.退货详情
文件路径:shop/controllers/Buyer/Service/ReturnCtl.php
视图:shop/views/default/Buyer/Service/ReturnCtl/detail.php
```
<pre class="calibre15">```
<span class="token5">//查找退货单信息</span>
$data <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">getReturn</span><span class="token1">(</span>$cond_row<span class="token1">)</span><span class="token1">;</span>
<span class="token5">//查找订单信息</span>
$order_base <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>orderBaseModel<span class="token">-</span><span class="token">></span><span class="token3">getOne</span><span class="token1">(</span>$data<span class="token1">[</span><span class="token4">'order_number'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
<span class="token5">//如果下单这为当前用户 或者此订单是主管账号支付订单并且当前用户是主管账号,则当前用户可以查看该笔订单的退款退货状态</span>
<span class="token2">if</span><span class="token1">(</span>$order_base<span class="token1">[</span><span class="token4">'buyer_user_id'</span><span class="token1">]</span> <span class="token">==</span> Perm<span class="token1">:</span><span class="token1">:</span>$userId <span class="token">||</span> <span class="token1">(</span>$order_base<span class="token1">[</span><span class="token4">'order_sub_pay'</span><span class="token1">]</span> <span class="token">==</span> Order_StateModel<span class="token1">:</span><span class="token1">:</span>SUB_USER_PAY <span class="token">&&</span> $order_base<span class="token1">[</span><span class="token4">'order_sub_user'</span><span class="token1">]</span> <span class="token">==</span> Perm<span class="token1">:</span><span class="token1">:</span>$userId<span class="token1">)</span><span class="token1">)</span>
<span class="token1">{</span>
<span class="token2">if</span> <span class="token1">(</span>$data<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="token1">{</span>
$data<span class="token1">[</span><span class="token4">'text'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"退货"</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">else</span>
<span class="token1">{</span>
$data<span class="token1">[</span><span class="token4">'text'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">"退款"</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
<span class="token2">if</span><span class="token1">(</span>$data<span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">)</span>
<span class="token1">{</span>
$data<span class="token1">[</span><span class="token4">'refund_goods'</span><span class="token1">]</span> <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">getOne</span><span class="token1">(</span>$data<span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span>
<span class="token1">}</span>
$data<span class="token1">[</span><span class="token4">'order'</span><span class="token1">]</span> <span class="token">=</span> $order_base<span class="token1">;</span>
$return_limit <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> $data<span class="token1">[</span><span class="token4">'order'</span><span class="token1">]</span><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>
$cash <span class="token">=</span> <span class="token6">0</span><span class="token1">;</span>
foreach <span class="token1">(</span>$return_limit as $v<span class="token1">)</span>
<span class="token1">{</span>
$cash <span class="token">+</span><span class="token">=</span> $v<span class="token1">[</span><span class="token4">'return_cash'</span><span class="token1">]</span><span class="token1">;</span>
<span class="token1">}</span>
$data<span class="token1">[</span><span class="token4">'return_limit'</span><span class="token1">]</span> <span class="token">=</span> $cash<span class="token1">;</span>
```
```
- 序言
- 系统要求
- 版本更新日志
- 远丰商城技术对接说明
- 开发指导
- 框架内容
- 基础
- 开发规范
- 目录结构
- 架构
- 架构总览
- 数据库
- 数据库连接
- 基本使用
- 缓存
- 配置
- 路由
- 数据字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- 通讯内容
- 商家中心
- 顶部导航栏
- 店铺信息栏
- 店铺及商品提示栏
- 交易提示栏
- 销售情况统计栏
- 单品销量排行栏
- 店铺运营推广栏
- 平台联系方式栏
- 订单物流
- 商品
- 商品列表
- 商品详情
- 商品发布与编辑
- 分销商品
- 关联版式
- 商品规格
- 图片空间
- 淘宝导入
- 订单流程
- 交易订单
- 订单退款/退货
- 促销
- 团购管理
- 加价购
- 限时折扣
- 满即送
- 代金券管理
- 分销
- 店铺
- 店铺设置
- 自销产品供应商
- 实体店铺
- 品牌申请
- 店铺信息
- 消费者保障服务
- 门店账号
- 分销商--产品供应商
- 分销明细
- 批发市场
- 售后服务
- 咨询管理
- 投诉管理
- 退款管理
- 退货管理
- 云方案架构
- 负载集群
- 云存储
- 接口
- Api接口说明
- 品牌
- 商品规格
- 商品类型
- 商品分类
- 商品
- 订单
- 商品/店铺收藏
- 足迹
- 退款及退货
- 商家店铺
- 会员
- 入驻协议
- 订单接口
- 商品接口
- 订单物流接口
- 商家中心接口
- 促销接口
- 快递鸟物流接口
- 代金券接口
- 首页版块
- 团购
- 平台红包
- 限时折扣接口
- 拼团接口
- wap首页模板
- 杂项
- 远程上传图片
- JS
- 银联支付
- 多语言
- 商品评分
- 图片加载
- 买家申请退款退货
- 商家退款退货
- 平台退款退货
- 添加发票
- 提交订单
- 确认订单
- 运费销售区域
- 获取会员地址
- 充值
- 导出XLS
- 商城系统集成
- 多语言实现
- 三级分销推广链接发展推广员
- app.ini.php
- 去分销
- 版本更新
- 物流支持
- 运营人员建议
- 业务逻辑
- 统计结算
- 客服消息
- 账号
- 三级分销
- IM
- 配置
- 平台帐号
- 活动数据表说明