🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
一、买家申请退款 文件路径:shop/controllers/Buyer/Service/ReturnCtl.php ~~~ //根据URL参数act,判断视图 if ($act == "detail") { $data = $this->detail(); $this->view->setMet('detail'); $d = $data; } elseif ($act == "add") { $data = $this->add(); if ($data == -3) { $this->view->setMet('error3'); }elseif($data == -4){ $this->view->setMet('error4'); } elseif ($data == -1) { $this->view->setMet('error2'); } elseif ($data == 0) { $this->view->setMet('error'); } else { $this->view->setMet('add'); } } ~~~ 视图:shop/views/default/Buyer/Service/ReturnCtl/add.php 退款表单提交: ~~~ $('#form').validator({ ...... }).on("click", "#handle_submit", function (e) { submit_trigger ? $(e.delegateTarget).trigger("validate") : submit_trigger = false; }); ~~~ 方法:addReturn() ~~~ //如果是货到付款,确认收货(付款)后才能退款 if($order['payment_id'] == PaymentChannlModel::PAY_CONFIRM){ if($order['order_status'] < Order_StateModel::ORDER_RECEIVED) { $flag2 = false; } fb($flag2); fb('flag22'); } //退款(货到付款只支持退货,不支持退款) if($goods['order_goods_status'] == Order_StateModel::ORDER_PAYED && $order['payment_id'] !== PaymentChannlModel::PAY_CONFIRM) { //白条支付不支持退款和退货 if(strstr($order['payment_name'],'白条支付')){ $flag2 = false; } fb($flag2); fb('flag23'); $field['return_goods_return'] = 0; //是否需要退货 0-不需要 1-需要 $return = $this->orderReturnModel->getByWhere(array( 'order_goods_id' => $goods_id, 'return_type' => Order_ReturnModel::RETURN_TYPE_ORDER, 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); } ~~~ 二、买家审核退款 文件路径:shop/controllers/Seller/Service/ReturnCtl.php 视图:shop/views/default/Seller/Service/ReturnCtl/detail.php 处理结果表单提交: ~~~ $('#form').validator({ ignore: ':hidden', theme: 'yellow_right', timely: 1, stopOnError: false, fields: {return_shop_message: "required"}, valid: function (form) { //表单验证通过,提交表单 ...... }).on("click", "#handle_submit", function (e) { //同意 ajax_url = SITE_URL + '?ctl=Seller_Service_Return&met=agreeReturn&typ=json'; $(e.delegateTarget).trigger("validate"); }).on("click", "#handle_close", function (e) { //不同意 ajax_url = SITE_URL + '?ctl=Seller_Service_Return&met=closeReturn&typ=json'; $(e.delegateTarget).trigger("validate"); }); ~~~ 三、平台审核,退款完成 文件路径:shop/controllers/Api/Trade/ReturnCtl.php 视图:shop_admin/view/default/Trade/ReturnCtl/detail.php JS:shop_admin/static/default/js/controllers/trade/return/detail.js 四、买家退款管理 文件路径:shop/controllers/Seller/Service/ReturnCtl.php * 退款流程:申请退款->卖家同意->平台同意->退款成功 * 退款状态: ~~~ //模型:shop/models/Order/ReturnModel.php public function __construct() { parent::__construct(); $this->return_state = array( '1' => __("等待卖家审核"), '2' => __("卖家审核通过"), '3' => __("卖家审核未通过"), '4' => __("等待平台审核"), '5' => __("退款/货完成"), ); $this->return_type = array( '1' => __("退款"), '2' => __("退货"), '3' => __("虚拟订单退款") ); } ~~~ * 视图:根据URL获得参数act的值,判断视图 ~~~ if ($act == "detail") { $data = $this->detail(); $this->view->setMet('detail'); } else { //orderReturn.php } ~~~ 1.退款管理列表 方法:orderReturn()、listReturn() ~~~ $data = $this->listReturn(Order_ReturnModel::RETURN_TYPE_ORDER); public function listReturn($type) { $data = $this->orderReturnModel->getReturnList($cond_row, array('return_add_time' => 'DESC'), $page, $rows); } ~~~ 2.查看退款详情 视图:shop/views/default/Seller/Service/ReturnCtl/detail.php * 卖家同意退款方法:agreeReturn() ~~~ //判断该笔退款金额的订单是否已经结算 $Order_BaseModel = new Order_BaseModel(); $order_base = $Order_BaseModel->getOne($return['order_number']); //判断该笔订单是否已经收货,如果没有收货的话,不扣除卖家资金。已确认收货则扣除卖家资金 if($order_base['order_status'] == $Order_StateModel::ORDER_FINISH ) { $order_finish = false; //获取用户的账户资金资源 $key = Yf_Registry::get('shop_api_key'); $formvars = array(); $user_id = Perm::$userId; $formvars['user_id'] = $user_id; $formvars['app_id'] = Yf_Registry::get('shop_app_id'); $money_row = get_url_with_encrypt($key, sprintf('%s?ctl=Api_User_Info&met=getUserResourceInfo&typ=json', Yf_Registry::get('paycenter_api_url')), $formvars); $user_money = 0; $user_money_frozen = 0; if ($money_row['status'] == '200') { $money = $money_row['data']; $user_money = $money['user_money']; $user_money_frozen = $money['user_money_frozen']; } $shop_return_amount = $return['return_cash'] - $return['return_commision_fee']; //获取该店铺最新的结算结束日期 $Order_SettlementModel = new Order_SettlementModel(); $settlement_last_info = $Order_SettlementModel->getLastSettlementByShopid(Perm::$shopId, $return['order_is_virtual']); if($settlement_last_info) { $settlement_unixtime = $settlement_last_info['os_end_date'] ; } else { $settlement_unixtime = ''; } $settlement_unixtime = strtotime($settlement_unixtime); $order_finish_time = $order_base['order_finished_time']; $order_finish_unixtime = strtotime($order_finish_time); fb($settlement_unixtime); if($settlement_unixtime >= $order_finish_unixtime ) { //结算时间大于订单完成时间。需要扣除卖家的现金账户 $money = $user_money; $pay_type = 'cash'; } else { //结算时间小于订单完成时间。需要扣除卖家的冻结资金,如果冻结资金不足就扣除账户余额 $money = $user_money_frozen + $user_money; $pay_type = 'frozen_cash'; } } else { $order_finish = true; } ~~~ * 卖家不同意退款方法:closeReturn() `$edit_flag = $this->orderReturnModel->editReturn($order_return_id, $data);` 五、买家退款管理 1.退款申请列表 文件路径:shop/controllers/Buyer/Service/ReturnCtl.php 视图:shop/views/default/Buyer/Service/ReturnCtl/index.php `$data = $this->orderReturnModel->getReturnList($cond_row, array('return_add_time' => 'DESC'), $page, $rows);` 2.退款详情 文件路径:shop/controllers/Buyer/Service/ReturnCtl.php 视图:shop/views/default/Buyer/Service/ReturnCtl/detail.php ~~~ //查找退货单信息 $data = $this->orderReturnModel->getReturn($cond_row); //查找订单信息 $order_base = $this->orderBaseModel->getOne($data['order_number']); //如果下单这为当前用户 或者此订单是主管账号支付订单并且当前用户是主管账号,则当前用户可以查看该笔订单的退款退货状态 if($order_base['buyer_user_id'] == Perm::$userId || ($order_base['order_sub_pay'] == Order_StateModel::SUB_USER_PAY && $order_base['order_sub_user'] == Perm::$userId)) { if ($data['return_type'] == Order_ReturnModel::RETURN_TYPE_GOODS) { $data['text'] = __("退货"); } else { $data['text'] = __("退款"); } if($data['order_goods_id']) { $data['refund_goods'] = $this->orderGoodsModel->getOne($data['order_goods_id']); } $data['order'] = $order_base; $return_limit = $this->orderReturnModel->getByWhere(array( 'order_number' => $data['order']['order_id'], 'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS )); $cash = 0; foreach ($return_limit as $v) { $cash += $v['return_cash']; } $data['return_limit'] = $cash; ~~~