#### 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进行比较。两者不一致,报错。
~~~
if($goods['order_id'] !== $order_id)
{
$flag2 = false;
}
~~~
2.判断订单状态,只有已付款订单才可进去“退款/退货”
~~~
if ($order['order_status'] < Order_StateModel::ORDER_PAYED)
{
$flag2 = false;
}
~~~
3.确定return_type的值,判断此次的“退款/退货”究竟是退款,还是退货。
~~~
if ($order['order_is_virtual'])
{
$field['return_type'] = Order_ReturnModel::RETURN_TYPE_VIRTUAL;
}
else
{
switch ($order['order_status'])
{
case Order_StateModel::ORDER_PAYED:$field['return_type'] = Order_ReturnModel::RETURN_TYPE_ORDER ; //退款
break;
case Order_StateModel::ORDER_FINISH:$field['return_type'] = Order_ReturnModel::RETURN_TYPE_GOODS ; //退货
break;
}
}
~~~
4.如果是货到付款,确认收货(付款)后才能退款
~~~
if($order['payment_id'] == PaymentChannlModel::PAY_CONFIRM)
{
if($order['order_status'] < Order_StateModel::ORDER_RECEIVED)
{
$flag2 = false;
}
}
~~~
5.根据订单状态,确定return_goods_return值。
退款(货到付款只支持退货,不支持退款)
~~~
if($goods['order_goods_status'] == Order_StateModel::ORDER_PAYED && $order['payment_id'] !== PaymentChannlModel::PAY_CONFIRM)
{
//白条支付不支持退款和退货
if(strstr($order['payment_name'],'白条支付')){
$flag2 = false;
}
$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
));
}
~~~
退货
~~~
if ($goods['order_goods_status'] == Order_StateModel::ORDER_FINISH)
{
if(strstr($order['payment_name'],'白条支付')){
$flag2 = false;
}
$field['return_goods_return'] = 1; //需要退货
//查询是否存在该订单商品的退货申请信息,且该申请未被卖家拒绝,以此判断是否重新提交退货申请
//只有以前没有提交过该商品的退货申请,且未被卖家拒绝的情况下,才可以提交退货申请
$return = $this->orderReturnModel->getByWhere(array(
'order_goods_id' => $goods_id,
'return_type' => Order_ReturnModel::RETURN_TYPE_GOODS,
'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS
));
}
~~~
6.计算生成“退款/退货”订单所需要的各种金额
//判断这件“退款/退货”商品是否还有可退数量(退款,退货都会退还商品数量)
~~~
$this_goods_return = $this->orderReturnModel->getByWhere(array(
'order_goods_id' => $goods_id,
'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS
));
~~~
* $this_goods_return_num :“退款/退货”商品总的已退还件数
* $this_goods_return_cash :“退款/退货”商品总的已退金额(包含正在审核中的金额)
//查找该笔订单已经进行过或正进行中的的退款,退货
~~~
$order_return = $this->orderReturnModel->getByWhere(array(
'order_number' => $order['order_id'],
'return_state:!=' => Order_ReturnModel::RETURN_SELLER_UNPASS
));
~~~
//订单已经退款退货的金额(包括与同意的退款和正在审核中的退款)
~~~
$order_return_cash = array_sum(array_column($order_return, 'return_cash'));
~~~
//订单已经退还的商品数量
~~~
$order_return_num = array_sum(array_column($order_return, 'order_goods_num'));
~~~
//订单还可退还的金额 = 订单实付金额 - 订单已退金额
//如果没有发货,可以退运费
~~~
if (Order_StateModel::ORDER_PAYED == $order['order_status'])
{
$order_can_return_cash = $order['order_payment_amount'] - $order_return_cash;
}
else
{
$order_can_return_cash = $order['order_payment_amount'] - $order_return_cash - $order['order_shipping_fee'];
}
/*
* $data['order']['order_refund_amount'] 与 $order_return_cash 的区别
* $data['order']['order_refund_amount']:表示商家已经同意的退款金额
* $order_return_cash:表示买家已经申请的退款,除被商家拒绝的退款外,正在审核的退款也包含在内
*/
//订单已退还的金额
$return_limit = $order['order_refund_amount'];
//订单可退金额
$cash_limit = $order_can_return_cash;
//订单可退商品数量
$goods_can_return_nums = $order_all_goods_num - $order_return_num;
//该件商品可退的总金额
$return_goods_cash = $goods['order_goods_amount'] - $this_goods_return_cash;
//该件商品还可退还商品数量
$return_goods_nums = $goods['order_goods_num'] - $this_goods_return_num;
~~~
//实际该件商品可退还的金额(有时可能包含运费)
//该件商品全部“退款/退货” //return_goods_nums
~~~
if($goods_can_return_nums == $nums && Order_StateModel::ORDER_PAYED == $order['order_status'])
{
//加上运费(未发货)
$return_cash = $return_goods_cash + $order['order_shipping_fee'];
}
else
{
$return_cash = floor($nums * $goods['order_goods_payment_amount'] * 100) / 100;
}
//如果订单为已付款状态,并且所有商品都退款,则将运费退还
if(Order_StateModel::ORDER_PAYED == $order['order_status'] && $nums == $goods_can_return_nums)
{
$return_cash = $cash_limit;
}
~~~
/*退款退货走同样的流程。区别是:退款时可能会退还运费,退货不可能退还运费。*/
7.订单商品表中插入订单商品的“退款/退货”状态
~~~
if($field['return_goods_return'] == 0)
{
//退款
$goods_field['goods_return_status'] = Order_GoodsModel::REFUND_IN;
$edit_flag = $this->orderGoodsModel->editGoods($goods_id, $goods_field);
check_rs($edit_flag, $rs_row);
}
else
{
//退货
$goods_field['goods_refund_status'] = Order_GoodsModel::REFUND_IN;
$edit_flag = $this->orderGoodsModel->editGoods($goods_id, $goods_field);
check_rs($edit_flag, $rs_row);
}
~~~
#### 2.商家审核退款退货
文件路径:
shop\controllers\Seller\Service\ReturnCtl.php
方法:
agreeReturn()
参数:
order_return_id:退单id
return_shop_message:商家处理备注
1.判断此退单是否已经被处理。
~~~
if($return['return_state'] == Order_ReturnModel::RETURN_SELLER_PASS)
{
$msg = __('已经退款,请刷新页面。');
$status = 200;
$this->data->addBody(-140, array(), $msg, $status);
return false;
}
~~~
2.判断商家处理备注是都存在违禁词
~~~
if (Text_Filter::checkBanned($return_shop_message, $matche_row))
{
$msg = __('含有违禁词');
$status = 250;
$this->data->addBody(-140, array(), $msg, $status);
return false;
}
~~~
3.判读订单是否已经收获,如果没有收货,不扣除卖家资金。已确认收货则扣除卖家资金。
$order_finish:订单是否已经完成确认收货
false :已收货
true:未收货
4.获取用户的账户资金信息
~~~
$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 = $money['user_money']; //账户余额
$user_money_frozen = $money['user_money_frozen']; //账户冻结资金
//判断订单是否已经结算
if($settlement_unixtime >= $order_finish_unixtime )
{
//结算时间大于订单完成时间。需要扣除卖家的现金账户
$money = $user_money;
$pay_type = 'cash';
}
else
{
//结算时间小于订单完成时间。需要扣除卖家的冻结资金,如果冻结资金不足就扣除账户余额
$money = $user_money_frozen + $user_money;
$pay_type = 'frozen_cash';
}
~~~
5.判断该退单是否是当前商家的订单
6.当退款金额小于用户资金时,或者订单为未收货订单时流程继续,否则报错。
~~~
$shop_return_amount = $return['return_cash'] - $return['return_commision_fee'];
~~~
$shop_return_amount:退款金额
$money:用户资金
修改退货单状态
~~~
$data['return_shop_message'] = $return_shop_message;
if ($return['return_goods_return'] == Order_ReturnModel::RETURN_GOODS_RETURN)
{
$data['return_state'] = Order_ReturnModel::RETURN_SELLER_PASS;
}
else
{
$data['return_state'] = Order_ReturnModel::RETURN_SELLER_GOODS;
}
$data['return_shop_time'] = get_date_time();
$flag = $this->orderReturnModel->editReturn($order_return_id, $data);
~~~
修改退货单成功后,如果订单为已收货订单,则修改商家金额。
~~~
if($flag && !$order_finish)
{
//扣除卖家的金额
$key = Yf_Registry::get('shop_api_key');
$formvars = array();
$user_id = Perm::$userId;
$formvars['user_id'] = $user_id;
$formvars['user_name'] = Perm::$row['user_name'];
$formvars['app_id'] = Yf_Registry::get('shop_app_id');
$formvars['money'] = $shop_return_amount * (-1);
$formvars['pay_type'] = $pay_type;
$formvars['reason'] = '退款';
$formvars['order_id'] = $order_base['order_id'];
$formvars['goods_id'] = $return['order_goods_id'];
$rs = get_url_with_encrypt($key, sprintf('%s?ctl=Api_User_Info&met=editReturnUserResourceInfo&typ=json', Yf_Registry::get('paycenter_api_url')), $formvars);
$dist_rs['status'] = 200;
//分销
if(isset($dist_return_order) && !empty($dist_return_order)){
$key = Yf_Registry::get('shop_api_key');
$formvars = array();
$user_id = Perm::$userId;
$formvars['user_id'] = $dist_order['seller_user_id'];
$formvars['user_name'] = $dist_order['seller_user_name'];
$formvars['money'] = ($dist_return_order['return_cash']-$dist_return_order['return_commision_fee'])*(-1);
$formvars['order_id'] = $dist_order['order_id'];
$formvars['goods_id'] =0;
$formvars['app_id'] = Yf_Registry::get('shop_app_id');
$formvars['pay_type'] = $pay_type;
$formvars['reason'] = '退款';
$dist_rs = get_url_with_encrypt($key, sprintf('%s?ctl=Api_User_Info&met=editReturnUserResourceInfo&typ=json', Yf_Registry::get('paycenter_api_url')), $formvars);
}
if($rs['status'] == 200 && $dist_rs['status']==200)
{
$flag = true;
}
else
{
$flag = false;
}
}
~~~
#### 3.平台审核退款退货
文件路径:
shop\controllers\Api\Trade\ReturnCtl.php
方法:
agree()
参数:
order_return_id:退单id
return_platform_message:处理备注
1.判断商家是否同意此退单,如果不同意则只修改订单状态,不修改商家金额。如果商家同意,则修改订单状态并修改商家金额。
~~~
if($return['return_state'] == Order_ReturnModel::RETURN_SELLER_UNPASS)
{
//不同意
$data['return_platform_message'] = $return_platform_message;
$data['return_state'] = Order_ReturnModel::RETURN_PLAT_PASS;
$data['return_finish_time'] = get_date_time();
$rs_row = array();
$this->Order_ReturnModel->sql->startTransactionDb();
$edit_flag = $this->Order_ReturnModel->editReturn($order_return_id, $data);
check_rs($edit_flag, $rs_row);
if ($return['return_goods_return'])
{
//商品退换情况为完成2
$goods_data['goods_refund_status'] = Order_GoodsModel::REFUND_COM;
$edit_flag = $this->Order_GoodsModel->editGoods($return['order_goods_id'], $goods_data);
check_rs($edit_flag, $rs_row);
}
else
{
$goods_data['goods_return_status'] = Order_GoodsModel::REFUND_COM;
$edit_flag = $this->Order_GoodsModel->editGoods($return['order_goods_id'], $goods_data);
check_rs($edit_flag, $rs_row);
}
}
~~~
2.商家同意退款的情况
(1)修改退单的状态
~~~
$data['return_platform_message'] = $return_platform_message;
$data['return_state'] = Order_ReturnModel::RETURN_PLAT_PASS;
$data['return_finish_time'] = get_date_time();
$rs_row = array();
$this->Order_ReturnModel->sql->startTransactionDb();
$edit_flag = $this->Order_ReturnModel->editReturn($order_return_id, $data);
~~~
(2)根据退款/退货情况,修改订单商品的状态
~~~
if ($return['return_goods_return'])
{
//商品退换情况为完成2
$goods_data['goods_refund_status'] = Order_GoodsModel::REFUND_COM;
$edit_flag = $this->Order_GoodsModel->editGoods($return['order_goods_id'], $goods_data);
check_rs($edit_flag, $rs_row);
}
else
{
$goods_data['goods_return_status'] = Order_GoodsModel::REFUND_COM;
$edit_flag = $this->Order_GoodsModel->editGoods($return['order_goods_id'], $goods_data);
check_rs($edit_flag, $rs_row);
}
~~~
(3)将退款金额,退还佣金,退还红包,退货数量等写入订单表
~~~
$order_edit['order_refund_amount'] = $return['return_cash'];
$order_edit['order_return_num'] = $return['order_goods_num'];
$order_edit['order_commission_return_fee'] = $return['return_commision_fee'];
$order_edit['order_rpt_return'] = $return['return_rpt_cash'];
$edit_flag = $this->Order_BaseModel->editBase($return['order_number'], $order_edit,true);
~~~
(4)如果此订单为退款订单,并且将所有商品退还,则就订单状态修改为完成状态
~~~
if($order_all_goods_num == $order_return_num && $order_base['order_status'] !== $Order_StateModel::ORDER_FINISH)
{
$order_edit_row = array();
$order_edit_row['order_status'] = $Order_StateModel::ORDER_FINISH;
$edit_flag2 = $this->Order_BaseModel->editBase($return['order_number'], $order_edit_row);
check_rs($edit_flag2, $rs_row);
}
~~~
(5)在paycenter中增加退款流水
判断该笔订单是否是主账号支付,如果是主账号支付,则将退款金额退还主账号
~~~
if($order_base['order_sub_pay'] == Order_StateModel::SUB_SELF_PAY)
{
$return_user_id = $return['buyer_user_id'];
$return_user_name = $return['buyer_user_account'];
}
if($order_base['order_sub_pay'] == Order_StateModel::SUB_USER_PAY)
{
//查找主管账户用户名
$User_BaseModel = new User_BaseModel();
$sub_user_base = $User_BaseModel->getOne($order_base['order_sub_user']);
$return_user_id = $order_base['order_sub_user'];
$return_user_name = $sub_user_base['user_account'];
}
$key = Yf_Registry::get('shop_api_key');
$url = Yf_Registry::get('paycenter_api_url');
$shop_app_id = Yf_Registry::get('shop_app_id');
$formvars = array();
$formvars['app_id'] = $shop_app_id;
$formvars['user_id'] = $return_user_id;
$formvars['user_account'] = $return_user_name;
$formvars['seller_id'] = $return['seller_user_id'];
$formvars['seller_account'] = $return['seller_user_account'];
$formvars['amount'] = $return['return_cash'];
$formvars['return_commision_fee'] = $return['return_commision_fee'];
$formvars['order_id'] = $return['order_number'];
$formvars['goods_id'] = $return['order_goods_id'];
$formvars['uorder_id'] = $order_base['payment_other_number'];
$formvars['payment_id'] = $order_base['payment_id'];
//平台同意退款(只增加买家的流水)
$rs = get_url_with_encrypt($key, sprintf('%s?ctl=Api_Pay_Pay&met=refundBuyerTransfer&typ=json', $url), $formvars);
~~~
(6)如果订单金额全数退还需要将订单商品,支付中心的订单状态修改为订单完成(未发货)
~~~
if($order_all_goods_num == $order_return_num && $order_base['order_status'] == Order_StateModel::ORDER_PAYED)
{
$goods_data['order_goods_status'] = $Order_StateModel::ORDER_FINISH;
$order_goods_ids = $this->Order_GoodsModel->getByWhere(array('order_id'=>$return['order_number']));
$ed_flag = $this->Order_GoodsModel->editGoods($order_goods_ids, $goods_data);
check_rs($ed_flag, $rs_row);
//将需要确认的订单号远程发送给Paycenter修改订单状态
//远程修改paycenter中的订单状态
$key = Yf_Registry::get('shop_api_key');
$url = Yf_Registry::get('paycenter_api_url');
$shop_app_id = Yf_Registry::get('shop_app_id');
$formvars = array();
$formvars['order_id'] = $return['order_number'];
$formvars['app_id'] = $shop_app_id;
$formvars['from_app_id'] = Yf_Registry::get('shop_app_id');
$rs = get_url_with_encrypt($key, sprintf('%s?ctl=Api_Pay_Pay&met=confirmOrder&typ=json', $url), $formvars);
if($rs['status'] == 250)
{
$rs_flag = false;
check_rs($rs_flag,$rs_row);
}
}
~~~
- 序言
- 系统要求
- 版本更新日志
- 远丰商城技术对接说明
- 开发指导
- 系统架构
- 负载集群
- 云存储
- 框架内容
- 基础
- 开发规范
- 目录结构
- 架构
- 架构总览
- 数据库
- 数据库连接
- 基本使用
- 缓存
- 配置
- 路由
- 数据字典
- ucenter
- shop
- paycenter
- ucenter_admin
- shop_admin
- paycenter_admin
- shop1
- shop2
- shop3
- 通讯内容
- 商家中心
- 顶部导航栏
- 店铺信息栏
- 店铺及商品提示栏
- 交易提示栏
- 销售情况统计栏
- 集群架构图
- 单品销量排行栏
- 店铺运营推广栏
- 平台联系方式栏
- 订单物流
- 商品
- 商品列表
- 商品详情
- 商品发布与编辑
- 分销商品
- 关联版式
- 商品规格
- 图片空间
- 淘宝导入
- 订单流程
- 交易订单
- 订单退款/退货
- 促销
- 团购管理
- 加价购
- 限时折扣
- 满即送
- 代金券管理
- 分销
- 店铺
- 店铺设置
- 自销产品供应商
- 实体店铺
- 品牌申请
- 店铺信息
- 消费者保障服务
- 门店账号
- 分销商--产品供应商
- 分销明细
- 批发市场
- 商家微信公众号
- 售后服务
- 咨询管理
- 投诉管理
- 退款管理
- 退货管理
- 杂项
- 远程上传图片
- 接口(废弃,参考最外层接口项)
- 接口说明
- 品牌
- 商品规格
- 商品类型
- 商品分类
- 商品
- 订单
- 商品/店铺收藏
- 足迹
- 退款及退货
- 商家店铺
- 会员
- 入驻协议
- 订单接口
- 商品接口
- 订单物流接口
- 商家中心接口
- 促销接口
- 快递鸟物流接口
- 代金券接口
- 首页版块
- 团购
- 平台红包
- 限时折扣接口
- 拼团接口
- wap首页模板
- JS
- 银联支付
- 多语言
- 商品评分
- 图片加载
- 买家申请退款退货
- 商家退款退货
- 平台退款退货
- 添加发票
- 提交订单
- 确认订单
- 运费销售区域
- 获取会员地址
- 充值
- 导出XLS
- 商城系统集成
- 多语言实现
- 三级分销推广链接发展推广员
- app.ini.php
- 去分销
- 版本更新
- 物流支持
- 运营人员建议
- 业务逻辑
- 统计结算
- 客服消息
- 账号
- 三级分销
- IM
- 配置
- 平台帐号
- 活动数据表说明
- 接口
- 数据库中间键
- MyCat的优势
- 概念说明
- Mycat的下载及安装
- 参数配置案列
- Mycat读写分离
- 基本命令
- 常见错误