多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 商家退款退货 文件路径: 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.当退款金额小于用户资金时,或者订单为未收货订单时流程继续,否则报错。 $shop\_return\_amount = $return\['return\_cash'\] - $return\['return\_commision\_fee'\]; $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="calibre15">``` <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> ``` ```