ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 订单退款/退货 #### 1.买家申请退款退货 文件路径: 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> ``` ``` ``` <pre class="calibre14">``` <span class="token5">/*退款退货走同样的流程。区别是:退款时可能会退还运费,退货不可能退还运费。*/</span> ``` ``` 7.订单商品表中插入订单商品的“退款/退货”状态 ``` <pre class="calibre14">``` <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> ``` ``` #### 2.商家审核退款退货 文件路径: shop\\controllers\\Seller\\Service\\ReturnCtl.php 方法: agreeReturn() 参数: order\_return\_id:退单id return\_shop\_message:商家处理备注 1.判断此退单是否已经被处理。 ``` <pre class="calibre14">``` <span class="token2">if</span><span class="token1">(</span>$<span class="token2">return</span><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> $msg <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">'已经退款,请刷新页面。'</span><span class="token1">)</span><span class="token1">;</span> $status <span class="token">=</span> <span class="token6">200</span><span class="token1">;</span> $this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> $msg<span class="token1">,</span> $status<span class="token1">)</span><span class="token1">;</span> <span class="token2">return</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>Text_Filter<span class="token1">:</span><span class="token1">:</span><span class="token3">checkBanned</span><span class="token1">(</span>$return_shop_message<span class="token1">,</span> $matche_row<span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span> $msg <span class="token">=</span> <span class="token3">__</span><span class="token1">(</span><span class="token4">'含有违禁词'</span><span class="token1">)</span><span class="token1">;</span> $status <span class="token">=</span> <span class="token6">250</span><span class="token1">;</span> $this<span class="token">-</span><span class="token">></span>data<span class="token">-</span><span class="token">></span><span class="token3">addBody</span><span class="token1">(</span><span class="token">-</span><span class="token6">140</span><span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> $msg<span class="token1">,</span> $status<span class="token1">)</span><span class="token1">;</span> <span class="token2">return</span> <span class="token6">false</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` 3.判读订单是否已经收获,如果没有收货,不扣除卖家资金。已确认收货则扣除卖家资金。 $order\_finish:订单是否已经完成确认收货 false :已收货 true:未收货 4.获取用户的账户资金信息 ``` <pre class="calibre14">``` $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> $money<span class="token1">[</span><span class="token4">'user_money'</span><span class="token1">]</span><span class="token1">;</span> <span class="token5">//账户余额</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="token5">//账户冻结资金</span> <span class="token5">//判断订单是否已经结算</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> ``` ``` 5.判断该退单是否是当前商家的订单 6.当退款金额小于用户资金时,或者订单为未收货订单时流程继续,否则报错。 ``` <pre class="calibre14">``` $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> ``` ``` $shop\_return\_amount:退款金额 $money:用户资金 修改退货单状态 ``` <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_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> ``` ``` 修改退货单成功后,如果订单为已收货订单,则修改商家金额。 ``` <pre class="calibre14">``` <span class="token2">if</span><span class="token1">(</span>$flag <span class="token">&&</span> <span class="token">!</span>$order_finish<span class="token1">)</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">'user_name'</span><span class="token1">]</span> <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$row<span class="token1">[</span><span class="token4">'user_name'</span><span class="token1">]</span><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> $formvars<span class="token1">[</span><span class="token4">'money'</span><span class="token1">]</span> <span class="token">=</span> $shop_return_amount <span class="token">*</span> <span class="token1">(</span><span class="token">-</span><span class="token6">1</span><span class="token1">)</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'pay_type'</span><span class="token1">]</span> <span class="token">=</span> $pay_type<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'reason'</span><span class="token1">]</span> <span class="token">=</span> <span class="token4">'退款'</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span> <span class="token">=</span> $order_base<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'goods_id'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">;</span> $rs <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=editReturnUserResourceInfo&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> $dist_rs<span class="token1">[</span><span class="token4">'status'</span><span class="token1">]</span> <span class="token">=</span> <span class="token6">200</span><span class="token1">;</span> <span class="token5">//分销</span> <span class="token2">if</span><span class="token1">(</span><span class="token3">isset</span><span class="token1">(</span>$dist_return_order<span class="token1">)</span> <span class="token">&&</span> <span class="token">!</span><span class="token3">empty</span><span class="token1">(</span>$dist_return_order<span class="token1">)</span><span class="token1">)</span><span class="token1">{</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> $dist_order<span class="token1">[</span><span class="token4">'seller_user_id'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'user_name'</span><span class="token1">]</span> <span class="token">=</span> $dist_order<span class="token1">[</span><span class="token4">'seller_user_name'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'money'</span><span class="token1">]</span> <span class="token">=</span> <span class="token1">(</span>$dist_return_order<span class="token1">[</span><span class="token4">'return_cash'</span><span class="token1">]</span><span class="token">-</span>$dist_return_order<span class="token1">[</span><span class="token4">'return_commision_fee'</span><span class="token1">]</span><span class="token1">)</span><span class="token">*</span><span class="token1">(</span><span class="token">-</span><span class="token6">1</span><span class="token1">)</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</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> $formvars<span class="token1">[</span><span class="token4">'goods_id'</span><span class="token1">]</span> <span class="token">=</span><span class="token6">0</span><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> $formvars<span class="token1">[</span><span class="token4">'pay_type'</span><span class="token1">]</span> <span class="token">=</span> $pay_type<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'reason'</span><span class="token1">]</span> <span class="token">=</span> <span class="token4">'退款'</span><span class="token1">;</span> $dist_rs <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=editReturnUserResourceInfo&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> <span class="token1">}</span> <span class="token2">if</span><span class="token1">(</span>$rs<span class="token1">[</span><span class="token4">'status'</span><span class="token1">]</span> <span class="token">==</span> <span class="token6">200</span> <span class="token">&&</span> $dist_rs<span class="token1">[</span><span class="token4">'status'</span><span class="token1">]</span><span class="token">==</span><span class="token6">200</span><span class="token1">)</span> <span class="token1">{</span> $flag <span class="token">=</span> <span class="token6">true</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> $flag <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` #### 3.平台审核退款退货 文件路径: shop\\controllers\\Api\\Trade\\ReturnCtl.php 方法: agree() 参数: order\_return\_id:退单id return\_platform\_message:处理备注 1.判断商家是否同意此退单,如果不同意则只修改订单状态,不修改商家金额。如果商家同意,则修改订单状态并修改商家金额。 ``` <pre class="calibre14">``` <span class="token2">if</span><span class="token1">(</span>$<span class="token2">return</span><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> <span class="token1">{</span> <span class="token5">//不同意</span> $data<span class="token1">[</span><span class="token4">'return_platform_message'</span><span class="token1">]</span> <span class="token">=</span> $return_platform_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_PLAT_PASS<span class="token1">;</span> $data<span class="token1">[</span><span class="token4">'return_finish_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>Order_ReturnModel<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>Order_ReturnModel<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>$edit_flag<span class="token1">,</span> $rs_row<span class="token1">)</span><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="token1">)</span> <span class="token1">{</span> <span class="token5">//商品退换情况为完成2</span> $goods_data<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_COM<span class="token1">;</span> $edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">,</span> $goods_data<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> $goods_data<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_COM<span class="token1">;</span> $edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">,</span> $goods_data<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="token1">}</span> ``` ``` 2.商家同意退款的情况 (1)修改退单的状态 ``` <pre class="calibre14">``` $data<span class="token1">[</span><span class="token4">'return_platform_message'</span><span class="token1">]</span> <span class="token">=</span> $return_platform_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_PLAT_PASS<span class="token1">;</span> $data<span class="token1">[</span><span class="token4">'return_finish_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>Order_ReturnModel<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>Order_ReturnModel<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> ``` ``` (2)根据退款/退货情况,修改订单商品的状态 ``` <pre class="calibre14">``` <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="token1">)</span> <span class="token1">{</span> <span class="token5">//商品退换情况为完成2</span> $goods_data<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_COM<span class="token1">;</span> $edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">,</span> $goods_data<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> $goods_data<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_COM<span class="token1">;</span> $edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">,</span> $goods_data<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> ``` ``` (3)将退款金额,退还佣金,退还红包,退货数量等写入订单表 ``` <pre class="calibre14">``` $order_edit<span class="token1">[</span><span class="token4">'order_refund_amount'</span><span class="token1">]</span> <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="token1">;</span> $order_edit<span class="token1">[</span><span class="token4">'order_return_num'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_num'</span><span class="token1">]</span><span class="token1">;</span> $order_edit<span class="token1">[</span><span class="token4">'order_commission_return_fee'</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> $order_edit<span class="token1">[</span><span class="token4">'order_rpt_return'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'return_rpt_cash'</span><span class="token1">]</span><span class="token1">;</span> $edit_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_BaseModel<span class="token">-</span><span class="token">></span><span class="token3">editBase</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> $order_edit<span class="token1">,</span><span class="token6">true</span><span class="token1">)</span><span class="token1">;</span> ``` ``` (4)如果此订单为退款订单,并且将所有商品退还,则就订单状态修改为完成状态 ``` <pre class="calibre14">``` <span class="token2">if</span><span class="token1">(</span>$order_all_goods_num <span class="token">==</span> $order_return_num <span class="token">&&</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_edit_row <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $order_edit_row<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> $edit_flag2 <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_BaseModel<span class="token">-</span><span class="token">></span><span class="token3">editBase</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> $order_edit_row<span class="token1">)</span><span class="token1">;</span> <span class="token3">check_rs</span><span class="token1">(</span>$edit_flag2<span class="token1">,</span> $rs_row<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` (5)在paycenter中增加退款流水 判断该笔订单是否是主账号支付,如果是主账号支付,则将退款金额退还主账号 ``` <pre class="calibre14">``` <span class="token2">if</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_SELF_PAY<span class="token1">)</span> <span class="token1">{</span> $return_user_id <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'buyer_user_id'</span><span class="token1">]</span><span class="token1">;</span> $return_user_name <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'buyer_user_account'</span><span class="token1">]</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">if</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="token1">)</span> <span class="token1">{</span> <span class="token5">//查找主管账户用户名</span> $User_BaseModel <span class="token">=</span> <span class="token2">new</span> <span class="token3">User_BaseModel</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $sub_user_base <span class="token">=</span> $User_BaseModel<span class="token">-</span><span class="token">></span><span class="token3">getOne</span><span class="token1">(</span>$order_base<span class="token1">[</span><span class="token4">'order_sub_user'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> $return_user_id <span class="token">=</span> $order_base<span class="token1">[</span><span class="token4">'order_sub_user'</span><span class="token1">]</span><span class="token1">;</span> $return_user_name <span class="token">=</span> $sub_user_base<span class="token1">[</span><span class="token4">'user_account'</span><span class="token1">]</span><span class="token1">;</span> <span class="token1">}</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> $url <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">'paycenter_api_url'</span><span class="token1">)</span><span class="token1">;</span> $shop_app_id <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> $formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'app_id'</span><span class="token1">]</span> <span class="token">=</span> $shop_app_id<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'user_id'</span><span class="token1">]</span> <span class="token">=</span> $return_user_id<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'user_account'</span><span class="token1">]</span> <span class="token">=</span> $return_user_name<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'seller_id'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'seller_user_id'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'seller_account'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'seller_user_account'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'amount'</span><span class="token1">]</span> <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="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'return_commision_fee'</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> $formvars<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_number'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'goods_id'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_goods_id'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'uorder_id'</span><span class="token1">]</span> <span class="token">=</span> $order_base<span class="token1">[</span><span class="token4">'payment_other_number'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'payment_id'</span><span class="token1">]</span> <span class="token">=</span> $order_base<span class="token1">[</span><span class="token4">'payment_id'</span><span class="token1">]</span><span class="token1">;</span> <span class="token5">//平台同意退款(只增加买家的流水)</span> $rs <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_Pay_Pay&met=refundBuyerTransfer&typ=json'</span><span class="token1">,</span> $url<span class="token1">)</span><span class="token1">,</span> $formvars<span class="token1">)</span><span class="token1">;</span> ``` ``` (6)如果订单金额全数退还需要将订单商品,支付中心的订单状态修改为订单完成(未发货) ``` <pre class="calibre15">``` <span class="token2">if</span><span class="token1">(</span>$order_all_goods_num <span class="token">==</span> $order_return_num <span class="token">&&</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_PAYED<span class="token1">)</span> <span class="token1">{</span> $goods_data<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> $order_goods_ids <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<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_id'</span><span class="token">=</span><span class="token">></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="token1">;</span> $ed_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>Order_GoodsModel<span class="token">-</span><span class="token">></span><span class="token3">editGoods</span><span class="token1">(</span>$order_goods_ids<span class="token1">,</span> $goods_data<span class="token1">)</span><span class="token1">;</span> <span class="token3">check_rs</span><span class="token1">(</span>$ed_flag<span class="token1">,</span> $rs_row<span class="token1">)</span><span class="token1">;</span> <span class="token5">//将需要确认的订单号远程发送给Paycenter修改订单状态</span> <span class="token5">//远程修改paycenter中的订单状态</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> $url <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">'paycenter_api_url'</span><span class="token1">)</span><span class="token1">;</span> $shop_app_id <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> $formvars <span class="token">=</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'order_id'</span><span class="token1">]</span> <span class="token">=</span> $<span class="token2">return</span><span class="token1">[</span><span class="token4">'order_number'</span><span class="token1">]</span><span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'app_id'</span><span class="token1">]</span> <span class="token">=</span> $shop_app_id<span class="token1">;</span> $formvars<span class="token1">[</span><span class="token4">'from_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> $rs <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_Pay_Pay&met=confirmOrder&typ=json'</span><span class="token1">,</span> $url<span class="token1">)</span><span class="token1">,</span> $formvars<span class="token1">)</span><span class="token1">;</span> <span class="token2">if</span><span class="token1">(</span>$rs<span class="token1">[</span><span class="token4">'status'</span><span class="token1">]</span> <span class="token">==</span> <span class="token6">250</span><span class="token1">)</span> <span class="token1">{</span> $rs_flag <span class="token">=</span> <span class="token6">false</span><span class="token1">;</span> <span class="token3">check_rs</span><span class="token1">(</span>$rs_flag<span class="token1">,</span>$rs_row<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ```