🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 平台退款退货 文件路径: 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> ``` ```