1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\api\controller;
- use app\api\model\card\UserRiceCard;
- use app\api\model\card\UserRiceCardConsume;
- use app\api\model\fullsend\FullSendActivity;
- use app\api\model\member\GoldRice;
- use app\api\model\OrderRefund as OrderRefundModel;
- use app\api\model\user\CommissionsDetail;
- use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
- use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
- use app\common\exception\BaseException;
- use app\common\model\OrderGoods as OrderGoodsModel;
- use app\api\service\User as UserService;
- use app\common\model\Order as OrderModel;
- use app\common\service\Order as OrderService;
- use think\Db;
- use app\common\model\order\RefundHis;
- use app\common\service\order\Refund as RefundService;
- use app\common\library\helper;
- use app\common\model\Express as ExpressModel;
- use app\api\model\card\UserRiceCard as UserRiceCardModel;
- use app\common\service\goods\source\Factory as FactoryStock;
- use app\common\enum\order\OrderSource as OrderSourceEnum;
- use app\api\model\za\ZaActivityRelation;
- /**
- * 订单售后服务
- * Class service
- * @package app\api\controller\user\order
- */
- class Refund extends Controller
- {
- /**
- * 售后单列表
- * @param int $state
- * @return array|\think\response\Json
- * @throws BaseException
- * @throws \think\db\exception\DbException
- */
- public function list(int $state = -1)
- {
- $model = new OrderRefundModel;
- $list = $model->getList($state);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 订单商品详情
- * @param int $orderGoodsId 订单商品ID
- * @return array|\think\response\Json
- * @throws BaseException
- */
- public function goods(int $orderGoodsId)
- {
- $model = new OrderRefundModel;
- $goods = $model->getRefundGoods($orderGoodsId);
- return $this->renderSuccess(compact('goods'));
- }
- /**
- * 申请售后
- * @param $order_goods_id
- * @return array
- * @throws \think\exception\DbException
- * @throws \Exception
- */
- public function apply($order_goods_id)
- {
- // 订单商品详情
- $goods = OrderGoodsModel::get(['order_goods_id'=>$order_goods_id],['refund','orderM']);
- if (isset($goods['refund']) && !empty($goods['refund'])) {
- return $this->renderError('当前商品已申请售后');
- }
-
- unset($goods['image']);
- // unset($goods['order_m']);
- unset($goods['content']);
- $order['delivery_status'] = $goods['order_m']['delivery_status'];
- return $this->renderSuccess(compact('order'));
- }
- //判断是否需要添加运费
- private function isExpressPrice($order,$order_goods_id){
- if($order['express_price']<=0){//没有运费
- return false;
- }
- //以下订单有运费
- $order_goods_ids = OrderGoodsModel::where('order_id',$order['order_id'])->where('order_goods_id','<>',$order_goods_id)->column('order_goods_id');
- if(empty($order_goods_ids)){ //空数组,该订单只有一种商品,得加上运费
- return true;
- }else{
- $count = OrderRefundModel::where(['order_id'=>$order['order_id'],'is_freight'=>1,'order_goods_id'=>['in',$order_goods_ids]])->whereNotIn('status',[5,6,7])->count();//是否有添加了运费的进行中的售后单
- if($count<1) {
- $OrderRefund = OrderRefundModel::with('orderGoods')->where(['order_id' => $order['order_id'], 'order_goods_id' => ['in', $order_goods_ids]])->whereNotIn('status', [5, 6, 7])->select();//未撤销的商品
- if($OrderRefund){
- foreach ($OrderRefund as $refund){
- if($refund['type']['value']==10 && $refund['goods_num']<$refund['order_goods']['total_num']){
- return false;
- }
- }
- if (count($OrderRefund) == count($order_goods_ids)) { //其他商品都在申请中了,最后一款商品需要加上运费
- return true;
- }
- }
- }
- return false;
- }
- }
- //提交售后
- public function applySubmit($type)
- {
- if($type==10){ //退款退货
- //退货退款的逻辑
- return $this->refundMoneyAndGoods($type);
- }
-
- if($type==20){ //不退货退款的逻辑
- return $this->refundMoneyNotGoods($type);
- }
- if($type==30){ //退款
- return $this->refundMoney($type);
- }
- }
- //修改退货退款申请
- public function applyEdit($type){
- if($type==10){ //退款退货
- //退货退款的逻辑
- return $this->editRefundMoneyAndGoods($type);
- }
- if($type==30){
- return $this->editRefundMoney($type);
- }
- }
-
- //已付款未发货退款修改
- public function editRefundMoney($type){
- //退款的逻辑
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_refund_id"=>"require",//售后ID
- "refund_money"=>"require|float|gt:0",//退款金额
- "goods_type"=>"require|in:1,2",//货物状态 货物到货状态(1未收到货 2已收到货)
- "apply_desc"=>"require",//申请原因
- ],[
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- 'goods_type.require'=>'货物状态不能为空',
- 'goods_type.in'=>'货物状态非法',
- 'apply_desc.require'=>'申请原因不能为空',
- ]);
- $user_id = $user->user_id;
-
- $order_refund_id = $params['order_refund_id'];
- $refund_res = OrderRefundModel::where(['order_refund_id'=>$order_refund_id])->find();
- if($refund_res['user_id']!=$user->user_id){
- return $this->renderError('非法售后单');
- }
- $order_goods_id = $refund_res['order_goods_id'];
- if (empty($order_goods_id)) { // 整单退款
- return $this->renderError('整单退款不能修改退款申请');
- }
- $order_good = OrderGoodsModel::find($order_goods_id);
- if(!$order_good){
- return $this->renderError('非法商品');
- }
- // if($order_good['total_num']<$params['goods_num']){
- // return $this->renderError('当前商品数量不能超过'.$order_good['total_num'].'个');
- // }
-
- //判断价格
- $refundMoney = helper::bcsub($order_good['total_pay_price'] + $order_good['rice_card_money'], 0, 2); // 退款金额 = 实付金额 + 现金卡抵扣金额
- if($refundMoney < $params['refund_money']){ //比较价格
- return $this->renderError('退款金额不能超过'.$refundMoney.'元');
- }
- if($refund_res['audit_status']==10){
- return $this->renderError("专员同意不能修改");
- }
- if($refund_res['audit_status_zg']==10){
- return $this->renderError("主管同意不能修改");
- }
- if($refund_res['finance_refund']==10){
- return $this->renderError("财务已退款 不能修改");
- }
- if($refund_res['status']==20){
- return $this->renderError("售后已完成不能修改");
- }
- if($refund_res['status']==30){
- return $this->renderError("用户撤消申请不能修改");
- }
- if($refund_res['status']==40){
- return $this->renderError("用户超时未退货,系统自动关闭售后单");
- }
- $param['refund_money'] = $params['refund_money'];
- $param['pay_money'] = $order_good['total_pay_price'];
- $param['rice_card_money'] = $order_good['rice_card_money'];
- $param['rice_card_id'] = $order_good['rice_card_id'];
- $param['goods_type'] = $params['goods_type'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['status'] = 0;
- $param['audit_status'] = 0;
- $param['audit_status_zg'] =0;
- $param['refuse_desc_zg'] = '';
- $param['refuse_desc'] = '';
- // $param['images'] = $params['images']??'';
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家已申请退款"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[],'买家','提交退款申请');
- $refund_res = OrderRefundModel::where('order_refund_id',$order_refund_id)->update($param);
- $refund['is_sys_refund'] = 1;
- $refund['type'] = $type;
- $refund['refund_money'] = $params['refund_money'];
- $refund['goods_type'] = $params['goods_type'];
- $refund['apply_desc'] = $params['apply_desc'];
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $order_refund_id;
- return $this->renderSuccess(compact('refund'));
- }
- //修改申请
- public function editRefundMoneyAndGoods($type){
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_refund_id"=>"require",//售后ID
- "goods_num"=>"require|gt:0",//商品数量
- "refund_money"=>"require|float|gt:0",//退款金额
- "apply_desc"=>"require",//申请原因
- "apply_detail_desc"=>"max:150", //详细原因
- // "images"=>"array",//用户上传凭证图片(多图)
- ],[
- 'order_refund_id.require'=>'没有售后ID',
- 'goods_num.require'=>'商品数量不能为空',
- 'goods_num.gt'=>'商品数量不能为空',
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- 'apply_desc.require'=>'申请原因不能为空',
- 'apply_detail_desc.max'=>'详细原因不能超过150字',
- // 'images.array'=>'用户上传的凭证格式不对',
- ]);
- $order_refund_id = $params['order_refund_id'];
- $refund_res = OrderRefundModel::where(['order_refund_id'=>$order_refund_id])->find();
- if($refund_res['user_id']!=$user->user_id){
- return $this->renderError('非法售后单');
- }
- if($refund_res['type']!=10){
- return $this->renderError('该售后单不允许修改');
- }
- $order_goods_id = $refund_res['order_goods_id'];
- $order_good = OrderGoodsModel::find($order_goods_id);
- if(!$order_good){
- return $this->renderError('非法商品');
- }
- if($order_good['total_num']<$params['goods_num']){
- return $this->renderError('当前商品数量不能超过'.$order_good['total_num'].'个');
- }
-
- //判断价格
- $refundMoney = helper::bcsub($order_good['total_pay_price'] + $order_good['rice_card_money'], 0, 2); // 退款金额 = 实付金额 + 现金卡抵扣金额
- if($refundMoney < $params['refund_money']){ //比较价格
- return $this->renderError('退款金额不能超过'.$refundMoney.'元');
- }
- if($refund_res['delivery_type']==10){
- if($refund_res['audit_status']==10&&$refund_res['audit_status_zg']==0){
- return $this->renderError("专员同意不能修改");
- }
- if($refund_res['audit_status_zg']==10){
- return $this->renderError("主管同意不能修改");
- }
- }
- if($refund_res['delivery_type']==20){
- if($refund_res['audit_status']==10){
- return $this->renderError("门店同意不能修改");
- }
- }
-
- if($refund_res['finance_refund']==10){
- return $this->renderError("财务已退款 不能修改");
- }
-
- if($refund_res['status']==20){
- return $this->renderError("售后已完成不能修改");
- }
- if($refund_res['status']==30){
- return $this->renderError("用户撤消申请不能修改");
- }
- if($refund_res['status']==40){
- return $this->renderError("用户超时未退货,系统自动关闭售后单");
- }
- //商品订单
- $total_pay_price = $order_good['total_pay_price'];
- $rice_card_money = $order_good['rice_card_money'];
- // 退的数量少于 订单的商品总数 即存在部份退
- if($params['goods_num']<$order_good['total_num']){
- // $one_pay_price = helper::bcsub($total_pay_price/$order_good['total_num'],0,2);
- // $one_rice_card_money = helper::bcsub(($rice_card_money/$order_good['total_num']),0,2);
- // $total_pay_price = helper::bcsub($one_pay_price*$params['goods_num'],0,2);
- // $rice_card_money = helper::bcsub($one_rice_card_money*$params['goods_num'],0,2);
- $price = helper::bcsub((($total_pay_price+$rice_card_money)/
- $order_good['total_num'])*$params['goods_num'],0,2);
- if($price<$params['refund_money']){
- return $this->renderError("退款金额不能超过商品实付价");
- }
- //申请的退款低于实际支付,按比例退
- if($total_pay_price+$rice_card_money>$params['refund_money']){
- $all_pay = $total_pay_price+$rice_card_money;
- $total_pay_price = helper::bcsub(($params['refund_money']/$all_pay)*$total_pay_price,0,2);
- $rice_card_money = helper::bcsub(($params['refund_money']/$all_pay)*$rice_card_money,0,2);
- }
- }else{
- //全部数量都退了,看是不是低于实际支付
- if($total_pay_price+$rice_card_money>$params['refund_money']){
- $all_pay = $total_pay_price+$rice_card_money;
- $total_pay_price = helper::bcsub(($params['refund_money']/$all_pay)*$total_pay_price,0,2);
- $rice_card_money = helper::bcsub(($params['refund_money']/$all_pay)*$rice_card_money,0,2);
- }
- }
- $user_id = $user->user_id;
- $param['type'] = $type;
- $param['refund_money'] = $params['refund_money'];
- $param['pay_money'] = $total_pay_price;
- $param['rice_card_money'] = $rice_card_money;
- $param['rice_card_id'] = $order_good['rice_card_id'];
- $param['goods_num'] = $params['goods_num'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['apply_detail_desc'] = $params['apply_detail_desc']??'';
- // $param['images'] = implode(",",$params['images']??[]);
- $param['images'] = $params['images']??'';
- $param['user_id'] = $user_id;
-
- // $param['provider_id'] = $order['provider_ids'];
- // $param['provider_name'] = $order_good['provider_name']??'';
- // $param['goods_type'] = 2;//默认写收收到货
- // $param['goods_images'] = [$order_good['good_image']];
- $param['status'] = 0; //等待商家审核中
- $param['audit_status'] = 0;
- $param['audit_status_zg'] =0;
- $param['refuse_desc_zg'] = '';
- $param['refuse_desc'] = '';
- OrderRefundModel::where('order_refund_id',
- $order_refund_id)->update($param);
-
- //写入协商历史 不一定要写 先关了先
- if($refund_res['delivery_type']==20){
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["退款类型:退货退款","退款金额:¥".$param['refund_money'],"申请原因:".$param['apply_desc'],"退款说明:".$param['apply_detail_desc']]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,$param['images'],'买家','提交退款申请');
- }
-
- if($refund_res['delivery_type']==10){
- //写入协商历史
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家已申请退款"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[],'买家','提交退款申请');
- }
- $refund['type'] = $type;
- $refund['refund_money'] = $param['refund_money'];
- $refund['goods_type'] = $refund_res->goods_type;
- $refund['goods_num'] = $param['goods_num'];
- $refund['apply_desc'] = $param['apply_desc'];
- // $refund['refund_succ_time'] = Date("Y-m-d H:i:s",$param['refund_succ_time']);
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $order_refund_id;
- return $this->renderSuccess(compact('refund'));
- }
- /**
- * 已付款未发货单个或整单退款
- */
- public function refundMoney($type){
- //退款的逻辑
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_id"=>"require",//订单ID
- "refund_money"=>"require|float|gt:0",//退款金额(包含运费)
- // "goods_type"=>"require|in:1,2",//货物状态 货物到货状态(1未收到货 2已收到货)
- "apply_desc"=>"require",//申请原因
- ],[
- 'order_id.require'=>'没有选择订单',
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- // 'goods_type.require'=>'货物状态不能为空',
- // 'goods_type.in'=>'货物状态非法',
- 'apply_desc.require'=>'申请原因不能为空',
- ]);
- $user_id = $user->user_id;
- $order = OrderModel::get(['order_id'=>$params['order_id'],'user_id'=>$user_id],['goods']);
- if(!$order){
- return $this->renderError('非法订单');
- }
- $params['goods_type'] = $params['goods_type']??1;
- //只有普通订单检查货物状态
- if($order['delivery_type']==10){
- if(!in_array($params['goods_type'],[1,2])){
- return $this->renderError('货物状态非法');
- }
- }
- $params['order_goods_id'] = $params['order_goods_id'] ?? 0;
- if($order['delivery_type']==20){
- if($params['order_goods_id']>0){
- return $this->renderError("门店自提单未核消不允许退单个商品");
- }
- }
- if (empty($params['order_goods_id'])) {
- // 整单退款
- return $this->refundAll($type, $order, $params, $user);
- } else {
- // 单个退款
- return $this->refundSingle($type, $order, $params, $user);
- }
- }
- /**
- * 单个退款
- */
- private function refundSingle($type, $order, $params, $user)
- {
- $orderGoods = OrderGoodsModel::get(['order_goods_id'=>$params['order_goods_id']]);
- // return $order;
- if($order['pay_status']==10){//未付款
- return $this->renderError('未付款不能申请退款');
- }
- if($orderGoods['delivery_status'] == DeliveryStatusEnum::DELIVERED){ //已发货
- return $this->renderError('已发货不能申请退款');
- }
- $refundMoney = helper::bcsub($orderGoods['total_pay_price'] + $orderGoods['rice_card_money'], 0, 2); // 退款金额 = 实付金额 + 现金卡抵扣金额
- if($refundMoney != $params['refund_money']){ //比较价格
- return $this->renderError('退款金额必须等于'.$refundMoney.'元');
- }
- $refund_time = $orderGoods['refund_time'];
- if($refund_time>0&&time()>$refund_time){
- return $this->renderError('当前售后时间已结束');
- }
- $refund = OrderRefundModel::where(['order_goods_id'=>$params['order_goods_id']])->where('status','in',[0,10,20])->find();
- if($refund){
- return $this->renderError('当前商品已申请售后');
- }
- $goods_images = [];
- foreach ($order['goods'] as $arr){ //获取图片url
- $goods_images[] = $arr['good_image'];
- }
- $param['order_id'] = $params['order_id'];
- $param['refund_money'] = $params['refund_money'];
- $param['pay_money'] = $orderGoods['total_pay_price'];
- $param['gold_rice_amount'] = $orderGoods['gold_rice_amount'];
- $param['gold_rice_amount_output'] = $orderGoods['gold_rice_amount_input'];
- $param['rice_card_money'] = $orderGoods['rice_card_money'];
- $param['rice_card_id'] = $orderGoods['rice_card_id'];
- $param['goods_type'] = $params['goods_type'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['type'] = $type;// 30 未发货退款
- $param['refund_number'] = OrderService::createOrderNoPrefix('TKSQ'); //申请单编号
- // $param['out_refund_no'] = OrderService::createOrderNoPrefix('TK');//生成退款编号
- $param['user_id'] = $user['user_id']??0;
- $param['goods_images'] = $goods_images;
- $param['order_goods_id'] = $params['order_goods_id'];
- $param['store_id'] = 10001;
- $param['is_sys_refund'] = 1; //系统退款
- $param['goods_num'] = $orderGoods['total_num'];
- $param['shop_id'] = $order['shop_id'];
- //订单商品是否已导出,未导出就直接退款
- if($orderGoods['is_export']==0){
- $param['finance_refund'] =10;// 10已退款
- $param['out_refund_time'] = time(); //退款时间
- $param['refund_succ_time'] = time(); //退款成功时间
- $param['refund_close_time'] = time(); //退款关闭时间
- $param['status'] = 20;//售后单直接完成
- if ($param['pay_money'] > 0) {
- //直接退款逻辑处理 直接退款
- $RefundService = new RefundService();
- $refund_ret = $RefundService->execute($order,$param['refund_number'], $param['pay_money']);
- if ($refund_ret['status'] == 200) {
- $param['transaction_id'] = $refund_ret['data']['transaction_id']; // 微信退款交易号
- }
- }
- //订单商品修改成全额退款状态
- OrderGoodsModel::updateBase(['has_refund_full' => 1], ['order_goods_id'=>$params['order_goods_id']]);
- //全部退款变更不结算zq11-12
- log_record('is refund::#########');
- //1.3.92后分佣无订单商品了
- //CommissionsDetail::updateDetails($params['order_goods_id']);
- $riceCard = UserRiceCardModel::getValidRiceCardDetail($order['rice_card_id']);
- if ($orderGoods['rice_card_id']) { // 订单商品有使用现金卡
- // 验证余额
- if ($orderGoods['rice_card_money'] + $riceCard['balance'] > $riceCard['face_value']) {
- return $this->renderError("现金卡退还金额异常");
- }
- // 写入现金卡流水明细
- UserRiceCardConsume::add($riceCard, $order['order_no'], $order['pay_price'], $orderGoods['rice_card_money'], 1, '商品退款');
- // // 退还现金卡金额
- UserRiceCard::setIncByField($orderGoods['rice_card_id'], 'balance', (float)$orderGoods['rice_card_money']);
- $riceCard->effect_state = 1; // 改为 生效
- $riceCard->save();
- }
- //售后单成功退了某商品的全部数量,把库存退回
- // if($order['order_source']==)
- FactoryStock::getFactory($order['order_source'])->backGoodsSkuStock($order,$orderGoods['goods_id'],$orderGoods['goods_sku_id'],$orderGoods['total_num']);
- //售后单成功退了某商品的全部数量,把库存退回给活动库存
- FactoryStock::getFactory($order['order_source'])->backActivityGoodsStock($orderGoods,$orderGoods['total_num']);
- }else{
- //非直接退款的订单,先给他冻结
- OrderGoodsModel::where('order_goods_id',$params['order_goods_id'])->update(['frozen_status'=>1]);
- }
-
- $refund_res = OrderRefundModel::create($param);
- //关闭订单状态
- $RefundService = new OrderService();
- $RefundService->closeOrder($param['order_id']);
- //写入金米粒记录
- GoldRice::refundGoldRiceRoad($order,$refund_res);
- //写入协商历史
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家已申请退款"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[],'买家','提交退款申请');
- //退款了就写退款记录
- if(isset($param['status'])&&$param['status']==20){
- $his_type = 2;
- $json_str = json_encode(["退款成功"]);
- $name = '公明腊肠官方体验商城';
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[]);
- }
- $refund['is_sys_refund'] = $refund_res->is_sys_refund;
- $refund['type'] = $type;
- $refund['refund_money'] = $refund_res->refund_money;
- $refund['goods_type'] = $refund_res->goods_type;
- $refund['apply_desc'] = $refund_res->apply_desc;
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $refund_res['order_refund_id'];
- return $this->renderSuccess(compact('refund'));
- }
- /**
- * 整单退款
- */
- private function refundAll($type, $order, $params, $user)
- {
- if($order['pay_status']==10){//未付款
- return $this->renderError('未付款不能申请退款');
- }
- // 普通配送单
- if($order['delivery_type']==10){
- // 存在已导出订单商品/存在已发货订单商品 不允许整单退款
- if (OrderGoodsModel::where('order_id', $params['order_id'])->where('is_export', 1)->count() > 0) {
- return $this->renderError('已发货不能申请退款');
- }
- if (OrderGoodsModel::where('order_id', $params['order_id'])->where('delivery_status', 20)->count() > 0) {
- return $this->renderError('已发货不能申请退款');
- }
- $orderGoods = OrderGoodsModel::where(['order_id' => $params['order_id'], 'is_export' => 0, 'delivery_status' => 10])->select();
- if (empty($orderGoods)) {
- return $this->renderError('该订单不满足整单退款条件');
- }
- }
- //门店自提单
- if($order['delivery_type']==20){
- if($order['hx_status']==20){
- return $this->renderError("已核销的订单不能申请退款");
- }
- $orderGoods = OrderGoodsModel::where(['order_id' => $params['order_id']])->select();
- if (empty($orderGoods)) {
- return $this->renderError('该订单不满足整单退款条件');
- }
- }
-
- // if(!empty($orderGoods['express_no'])){ //已发货
- // return $this->renderError('已发货不能申请退款');
- // }
- $refundMoney = helper::bcsub($order['pay_price'] + $order['rice_card_money'], 0, 2); // 退款金额 = 实付金额 + 现金卡抵扣金额
- if($refundMoney != $params['refund_money']){ //比较价格
- return $this->renderError('退款金额必须等于'.$refundMoney.'元');
- }
- $refund = OrderRefundModel::where(['order_id'=>$params['order_id']])->where('status','in',[0,10,20])->find();
- if($refund){
- if($refund['status']==20){
- return $this->renderError('订单退款完成');
- }
- return $this->renderError('当前订单商品已申请售后');
- }
- $goods_images = [];
- foreach ($order['goods'] as $arr){ //获取图片url
- $goods_images[] = $arr['good_image'];
- }
- $param['order_id'] = $params['order_id'];
- $param['refund_money'] = $params['refund_money'];
- $param['pay_money'] = $order['pay_price'];
- $param['gold_rice_amount'] = $order['gold_rice_amount'];
- $param['gold_rice_amount_output'] = $order['gold_rice_amount_input'];
- $param['rice_card_money'] = $order['rice_card_money'];
- $param['rice_card_id'] = $order['rice_card_id'];
- $param['express_price'] = $order['express_price'];
- $param['goods_type'] = $params['goods_type'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['type'] = $type;// 30 未发货退款
- $param['refund_number'] = OrderService::createOrderNoPrefix('TKSQ'); //申请单编号
- // $param['out_refund_no'] = OrderService::createOrderNoPrefix('TK');//生成退款编号
- $param['user_id'] = $user['user_id']??0;
- $param['goods_images'] = $goods_images;
- $param['order_goods_id'] = $params['order_goods_id'];
- $param['store_id'] = 10001;
- $param['is_sys_refund'] = 1; //系统退款
- $param['goods_num'] = helper::getArrayColumnSum($orderGoods, 'total_num');
- $param['finance_refund'] =10;// 10已退款
- $param['out_refund_time'] = time(); //退款时间
- $param['refund_succ_time'] = time(); //退款成功时间
- $param['refund_close_time'] = time(); //退款关闭时间
- $param['status'] = 20;//售后单直接完成
- $param['delivery_type'] = $order['delivery_type'];
- $param['hx_status'] = $order['hx_status'];
- $param['shop_id'] = $order['shop_id'];
- if($order['delivery_type']==20){
- $param['audit_status'] = 10;//自提单直接门店审核通过
- }
-
- if ($param['pay_money'] > 0) {
- //直接退款逻辑处理 直接退款
- $RefundService = new RefundService();
- $refund_ret = $RefundService->execute($order,$param['refund_number'], $param['pay_money']);
- if ($refund_ret['status'] == 200) {
- $param['transaction_id'] = $refund_ret['data']['transaction_id']; // 微信退款交易号
- }
- }
- //订单商品修改成全额退款状态
- OrderGoodsModel::updateBase(['has_refund_full' => 1], ['order_id'=>$params['order_id']]);
- //全部退款变更不结算
- CommissionsDetail::updateAllDetails($params['order_id']);
-
- $riceCard = UserRiceCardModel::getValidRiceCardDetail($order['rice_card_id']);
- if ($order['rice_card_id']) { // 订单商品有使用现金卡
- // 验证余额
- if ($order['rice_card_money'] + $riceCard['balance'] > $riceCard['face_value']) {
- return $this->renderError("现金卡退还金额异常");
- }
- // 写入现金卡流水明细
- UserRiceCardConsume::add($riceCard, $order['order_no'], $order['pay_price'], $order['rice_card_money'], 1, '商品退款');
- // 退还现金卡金额
- UserRiceCard::setIncByField($order['rice_card_id'], 'balance', (float)$order['rice_card_money']);
- $riceCard->effect_state = 1; // 改为 生效
- $riceCard->save();
- }
- $refund_res = OrderRefundModel::create($param);
- //写入金米粒记录
- GoldRice::refundGoldRiceRoad($order,$refund_res);
- //关闭订单状态
- $RefundService = new OrderService();
- $RefundService->closeOrder($param['order_id']);
- //普通配送单
- if($order['delivery_type']==10){
- //写入协商历史
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家已申请退款"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[],'买家','提交退款申请');
- //退款了就写退款记录
- if(isset($param['status'])&&$param['status']==20){
- $his_type = 2;
- $json_str = json_encode(["退款成功"]);
- $name = '公明腊肠官方体验商城';
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[]);
- }
- }
- //门店自提
- if($order['delivery_type']==20){
- if(isset($param['status'])&&$param['status']==20){
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家申请退款,退款成功"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,[],'买家','提交退款申请');
- }
- }
- $refund['is_sys_refund'] = $refund_res->is_sys_refund;
- $refund['type'] = $type;
- $refund['refund_money'] = $refund_res->refund_money;
- $refund['goods_type'] = $refund_res->goods_type;
- $refund['apply_desc'] = $refund_res->apply_desc;
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $refund_res['order_refund_id'];
- $refund['delivery_type'] = $refund_res['delivery_type'];
- //售后单完成之后,把库存退回,整单退款的
- FactoryStock::getFactory($order['order_source'])->backGoodsStock($order, true);
- //回退多个活动的活动库存
-
- FactoryStock::getFactory($order['order_source'])->backActivityStock($order, true);
- if($order['order_source']==OrderSourceEnum::ZA){
- $zarel = ZaActivityRelation::where('order_id',$order['order_id'])->find();
- if($zarel){
- $zarel->is_pay = 2;
- $zarel->expire_time = Date("Y-m-d H:i:s",time());
- if($zarel->child_order_id>0){
- OrderGoodsModel::updateBase(['has_refund_full' => 1], ['order_id'=>$zarel->child_order_id]);
- $RefundService->closeOrder($zarel->child_order_id);
- }
- $zarel->save();
- }
- }
- return $this->renderSuccess(compact('refund'));
- }
- //已付款已发货 -不退货退款 20
- public function refundMoneyNotGoods($type){
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_id"=>"require",//订单ID
- "order_goods_id"=>"require",//商品ID
- "refund_money"=>"require|float|gt:0",//退款金额
- "goods_type"=>"require|in:1,2",//货物状态 货物到货状态(1未收到货 2已收到货)
- "apply_desc"=>"require",//申请原因
- "apply_detail_desc"=>"max:150",//详细原因
- // "images"=>"array",//用户上传凭证图片(多图)
- ],[
- 'order_id.require'=>'没有选择订单',
- 'order_goods_id.require'=>'没有选择要退货的商品',
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- 'goods_type.require'=>'货物状态不能为空',
- 'goods_type.in'=>'货物状态非法',
- 'apply_desc.require'=>'退款原因不能为空',
- 'apply_detail_desc.max'=>'问题描述不能超过150字',
- // 'images.array'=>'用户上传的凭证格式不对',
- ]);
- $params['type'] = $type;
- $order = OrderModel::get(['user_id'=>$user->user_id,'order_id'=>$params['order_id']]);
- if(!$order){
- return $this->renderError('非法订单');
- }
- if($order['pay_status']==10){//未付款
- return $this->renderError('未付款不能申请不退货退款');
- }
- if($order['delivery_status']==10){ //未发货
- return $this->renderError('未发货不能申请不退货退款');
- }
- $order_good = OrderGoodsModel::find($params['order_goods_id']);
- if(!$order_good){
- return $this->renderError('非法商品');
- }
- $refund = OrderRefundModel::where(['order_goods_id'=>$params['order_goods_id']])->find();
- if($refund){
- if($refund['status']==20){
- return $this->renderError('订单退款完成');
- }
- return $this->renderError('当前订单商品已申请售后');
- }
-
- if($order_good['total_pay_price']<$params['refund_money']){ //比较价格
- return $this->renderError('退款金额不能超过'.$order_good['total_pay_price'].'元');
- }
-
- $param['type'] = $type;
- $param['order_id'] = $params['order_id'];
- $param['order_goods_id'] = $params['order_goods_id'];
- $param['refund_money'] = $params['refund_money'];
- $param['goods_type'] = $params['goods_type'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['apply_detail_desc'] = $params['apply_detail_desc']??'';
- $param['images'] = implode(',',$params['images']);
- $param['user_id'] = $user->user_id;
- $param['status'] = 0; //等待商家审核中
- $param['refund_number'] = OrderService::createOrderNoPrefix('TKSQ'); //申请单编号
- // $param['out_refund_no'] = OrderService::createOrderNoPrefix('TK'); //退款编号
- // $param['provider_id'] = $order['provider_ids'];
- // $param['provider_name'] = $order_good['provider_name']??'';
- // $param['shop_take_time'] = time()+$delay_time; //等待商家处理的最后时间
- // $param['goods_images'] = [$order_good['good_image']??''];
- $refund_res = OrderRefundModel::create($param);
- //写入协商历史
-
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["退款类型:不退货退款","退款金额:¥".$param['refund_money'],"申请原因:".$param['apply_desc'],"退款说明:".$param['apply_detail_desc']]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,$param['images']);
- $refund['type'] = $type;
- $refund['refund_money'] = $refund_res->refund_money;
- $refund['goods_type'] = $refund_res->goods_type;
- $refund['apply_desc'] = $refund_res->apply_desc;
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $refund_res['order_refund_id'];
- return $this->renderSuccess(compact('refund'));
-
- }
- //添加检测赠品订单退货时是否需要退回赠送商品
- public function checkRefund(){
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_id"=>"require",//订单ID
- "order_goods_id"=>"require",//商品ID
- "refund_money"=>"require|float|gt:0",//退款金额
- "goods_num"=>"require|gt:0",//退款金额
- // "images"=>"array",//用户上传凭证图片(多图)
- ],[
- 'order_id.require'=>'没有选择订单',
- 'order_goods_id.require'=>'没有选择要退货的商品',
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- 'goods_num.require'=>'退款数量不能为空',
- 'goods_num.gt'=>'退款数量不能小于0',
- ]);
- // dd($params);
- $orderGoodsDetail = OrderGoodsModel::get(['order_goods_id'=>$params['order_goods_id']]);
- if(!$orderGoodsDetail){
- return $this->renderSuccess(['code'=>0]);
- }
- if($orderGoodsDetail['full_send_activity_id']>0){//如果参与了满就送活动
- $checkRefund = RefundService::checkRefund($params['order_id'],$params['order_goods_id'],$params['refund_money']);
- if($checkRefund){
- return $this->renderSuccess(['code'=>1,'count'=>1]);//需要退回满就送商品
- }
- }
- if($orderGoodsDetail['mj_send_activity_id']>0){//如果参与了满件送活动
- $checkRefund = RefundService::checkMjRefund($params['order_id'],$params['order_goods_id'],$params['goods_num']);
- if($checkRefund){
- return $this->renderSuccess(['code'=>2,'count'=>$checkRefund]);//需要退回满件送商品
- }
- }
- if($orderGoodsDetail['qc_send_activity_id']>0){//如果参与了全场满件送活动
- $checkRefund = RefundService::checkQcMjRefund($params['order_id'],$params['order_goods_id'],$params['goods_num']);
- if($checkRefund){
- return $this->renderSuccess(['code'=>3,'count'=>$checkRefund]);//需要退回满件送商品
- }
- }
- return $this->renderSuccess(['code'=>0]);
- }
- //已付款已发货 -退货退款(二期同一商品暂不做多笔申请)
- public function refundMoneyAndGoods($type){
- $user = UserService::getCurrentLoginUser(true);
- $params = $this->baseValidate([
- "order_id"=>"require",//订单ID
- "order_goods_id"=>"require",//商品ID
- "goods_num"=>"require|gt:0",//商品数量
- "refund_money"=>"require|float|gt:0",//退款金额
- "apply_desc"=>"require",//申请原因
- "apply_detail_desc"=>"max:150",//详细原因
- // "images"=>"array",//用户上传凭证图片(多图)
- ],[
- 'order_id.require'=>'没有选择订单',
- 'order_goods_id.require'=>'没有选择要退货的商品',
- 'goods_num.require'=>'商品数量不能为空',
- 'goods_num.gt'=>'商品数量不能为空',
- 'refund_money.require'=>'退款金额不能为空',
- 'refund_money.float'=>'退款金额非法',
- 'refund_money.gt'=>'退款金额不能小于等于0',
- 'apply_desc.require'=>'申请原因不能为空',
- 'apply_detail_desc.max'=>'详细原因不能超过150字',
- // 'images.array'=>'用户上传的凭证格式不对',
- ]);
- $order = OrderModel::get(['order_id'=>$params['order_id']]);
- $order_good = OrderGoodsModel::find($params['order_goods_id']);
- if(!$order){
- return $this->renderError('非法订单');
- }
- if($order['pay_status']==10){//未付款
- return $this->renderError('未付款不能申请退货退款');
- }
- if($order['delivery_type']==10){
- if($order_good['delivery_status'] == DeliveryStatusEnum::NOT_DELIVERED){ //未发货
- return $this->renderError('未发货不能申请退货退款');
- }
- }
- if($order['delivery_type']==20){
- if($order_good['receipt_status'] != ReceiptStatusEnum::RECEIVED){ //未收货
- return $this->renderError('门店自提未收货不能申请退货退款');
- }
- }
-
- if(!$order_good){
- return $this->renderError('非法商品');
- }
- if($order_good['total_num']<$params['goods_num']){
- return $this->renderError('当前商品数量不能超过'.$order_good['total_num'].'个');
- }
- if($order_good['is_activity_discount']==1){
- if($order_good['total_num']!=$params['goods_num']){
- return $this->renderError('参加折扣活动的商品必须退全部数量');
- }
- }
- $refund_time = $order_good['refund_time'];
- if($refund_time>0&&time()>$refund_time){
- return $this->renderError('当前售后时间已结束');
- }
-
- $count = OrderRefundModel::where(['order_goods_id'=>$params['order_goods_id']])->where('status','in',[0,10,20])->find();
-
- if($count){
- return $this->renderError('当前商品已申请售后');
- }
- //判断价格
- $refundMoney = helper::bcsub($order_good['total_pay_price'] + $order_good['rice_card_money'], 0, 2); // 退款金额 = 实付金额 + 现金卡抵扣金额
- if($refundMoney < $params['refund_money']){ //比较价格
- return $this->renderError('退款金额不能超过'.$refundMoney.'元');
- }
- //商品订单
- $total_pay_price = $order_good['total_pay_price'];
- $rice_card_money = $order_good['rice_card_money'];
- // 退的数量少于 订单的商品总数 即存在部份退
- if($params['goods_num']<$order_good['total_num']){
- // $one_pay_price = helper::bcsub($total_pay_price/$order_good['total_num'],0,2);
- // $one_rice_card_money = helper::bcsub(($rice_card_money/$order_good['total_num']),0,2);
- // $total_pay_price = helper::bcsub($one_pay_price*$params['goods_num'],0,2);
- // $rice_card_money = helper::bcsub($one_rice_card_money*$params['goods_num'],0,2);
- $price = helper::bcsub((($total_pay_price+$rice_card_money)/
- $order_good['total_num'])*$params['goods_num'],0,2);
- if($price<$params['refund_money']){
- return $this->renderError("退款金额不能超过商品实付价");
- }
- // if($total_pay_price+$rice_card_money<$params['refund_money']){
- // return $this->renderError("退款金额不能超过商品实付价");
- // }
- //申请的退款低于实际支付,按比例退
- if($total_pay_price+$rice_card_money>$params['refund_money']){
- $all_pay = $total_pay_price+$rice_card_money;
- $total_pay_price = helper::bcsub(($params['refund_money']/$all_pay)*$total_pay_price,0,2);
- $rice_card_money = helper::bcsub(($params['refund_money']/$all_pay)*$rice_card_money,0,2);
- }
- }else{
- //全部数量都退了,看是不是低于实际支付
- if($total_pay_price+$rice_card_money>$params['refund_money']){
- $all_pay = $total_pay_price+$rice_card_money;
- $total_pay_price = helper::bcsub(($params['refund_money']/$all_pay)*$total_pay_price,0,2);
- $rice_card_money = helper::bcsub(($params['refund_money']/$all_pay)*$rice_card_money,0,2);
- }
- }
-
- $user_id = $user->user_id;
- $param['type'] = $type;
- $param['store_id'] = 10001;
- $param['order_id'] = $params['order_id'];
- $param['order_goods_id'] = $params['order_goods_id'];
- $param['refund_money'] = $params['refund_money'];
- $param['pay_money'] = $total_pay_price;
- $param['gold_rice_amount'] = helper::bcdiv($params['goods_num']*$order_good['gold_rice_amount'],$order_good['total_num'],0);
- $param['gold_rice_amount_output'] = helper::bcdiv($params['goods_num']*$order_good['gold_rice_amount_input'],$order_good['total_num'],0);
- $param['rice_card_money'] = $rice_card_money;
- $param['rice_card_id'] = $order_good['rice_card_id'];
- $param['goods_num'] = $params['goods_num'];
- $param['apply_desc'] = $params['apply_desc'];
- $param['apply_detail_desc'] = $params['apply_detail_desc']??'';
- // $param['images'] = implode(",",$params['images']??[]);
- $param['images'] = $params['images']??'';
- $param['user_id'] = $user_id;
- $param['status'] = 0; //等待商家审核中
- $param['refund_number'] = OrderService::createOrderNoPrefix('TKSQ'); //申请单编号
- // $param['out_refund_no'] = OrderService::createOrderNoPrefix('TK'); //退款编号
- // $param['provider_id'] = $order['provider_ids'];
- // $param['provider_name'] = $order_good['provider_name']??'';
- $param['goods_type'] = 2;//默认写收收到货
- $param['goods_images'] = [$order_good['good_image']];
- $param['delivery_type'] = $order['delivery_type'];
- $param['hx_status'] = $order['hx_status'];
- $param['shop_id'] = $order['shop_id'];
- $refund_res = OrderRefundModel::create($param);
- //写入协商历史
- //非直接退款的订单,先给他冻结
- OrderGoodsModel::where('order_goods_id',$params['order_goods_id'])->update(['frozen_status'=>1]);
- if($param['delivery_type']==10){
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["买家已申请退款"]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,$param['images'],'买家','提交退款申请');
- }
- if($param['delivery_type']==20){
- $his_type = 1;
- $name = $user->nick_name??'';
- $json_str = json_encode(["退款类型:退货退款","退款原因:".$param['apply_desc'],"问题描述:".$param['apply_detail_desc']]);
- (new RefundHis())->add($refund_res['order_refund_id'],$name,$his_type,$json_str,$param['images'],'买家','提交退款申请');
- }
-
- $refund['type'] = $type;
- $refund['refund_money'] = $refund_res->refund_money;
- $refund['goods_type'] = $refund_res->goods_type;
- $refund['goods_num'] = $refund_res->goods_num;
- $refund['apply_desc'] = $refund_res->apply_desc;
- // $refund['refund_succ_time'] = Date("Y-m-d H:i:s",$param['refund_succ_time']);
- $refund['create_time'] = Date("Y-m-d H:i:s",time());
- $refund['order_refund_id'] = $refund_res['order_refund_id'];
- $refund['delivery_type'] = $refund_res->delivery_type;
- return $this->renderSuccess(compact('refund'));
- }
- // /**
- // * 申请售后
- // * @param int $orderGoodsId 订单商品ID
- // * @return array|\think\response\Json
- // * @throws BaseException
- // */
- // public function apply(int $orderGoodsId)
- // {
- // // 新增售后单记录
- // $model = new OrderRefundModel;
- // if ($model->apply($orderGoodsId, $this->postForm())) {
- // return $this->renderSuccess([], '提交成功');
- // }
- // return $this->renderError($model->getError() ?: '提交失败');
- // }
- public function auditstatus(int $orderRefundId){
- $audit_status = OrderRefundModel::where("order_refund_id",
- $orderRefundId)->value("audit_status");
- return $this->renderSuccess(compact('audit_status'));
- }
- /**
- * 售后单详情
- * @param int $orderRefundId 售后单ID
- * @return array|\think\response\Json
- * @throws BaseException
- */
- public function detail(int $orderRefundId)
- {
- $detail = OrderRefundModel::getDetail($orderRefundId, true);
- $hx_refund_code = $detail['hx_refund_code'];
- if(empty($hx_refund_code)){
- $i = 10000000;
- $refund_id = $detail['order_refund_id'];
- $hx_refund_code = "T".($i+$refund_id);
- OrderRefundModel::where("order_refund_id",$detail['order_refund_id'])->update(['hx_refund_code'=>$hx_refund_code]);
- $detail['hx_refund_code'] = $hx_refund_code;
- }
- $detail['hx_refund_url'] = url('/api/order/getHxQrcode',['hxCode'=>$hx_refund_code], true, true)->build();
- $pay_type_text ='微信';
- if($detail['pay_money']>0&&$detail['rice_card_id']>0){
- $pay_type_text = '微信+现金卡';
- }
- if($detail['pay_money']==0&&$detail['rice_card_id']>0){
- $pay_type_text = '现金卡';
- }
- $detail['pay_type_text'] = $pay_type_text;
- return $this->renderSuccess(compact('detail'));
- }
- /**
- * 撤销申请
- * @param int $orderRefundId 售后单ID
- * @return array|\think\response\Json
- * @throws BaseException
- */
- public function revoke(int $orderRefundId)
- {
- // 售后单详情
- $model = OrderRefundModel::getDetail($orderRefundId, false);
- if ($model->revoke()) {
- return $this->renderSuccess([], '操作成功');
- }
- return $this->renderError($model->getError() ?: '提交失败');
- }
- /**
- * 用户发货
- * @param int $orderRefundId 售后单ID
- * @return array|\think\response\Json
- * @throws BaseException
- */
- public function delivery(int $orderRefundId)
- {
- // 售后单详情
- $model = OrderRefundModel::getDetail($orderRefundId, false);
- if ($model->delivery( $this->request->post())) {
- return $this->renderSuccess([], '操作成功');
- }
- return $this->renderError($model->getError() ?: '提交失败');
- }
- /**
- * 查看物流详情
- * @param int $orderRefundId 售后单ID
- * @return array|\think\response\Json
- * @throws BaseException
- * @author: zjwhust
- * @Time: 2021/10/28 14:13
- */
- public function express(int $orderRefundId)
- {
- // 订单信息
- $model = OrderRefundModel::getDetail($orderRefundId, false);
- if (!$model || !$model['is_user_send']) {
- return $this->renderError('没有物流信息');
- }
- $ExpressModel = new ExpressModel;
- $res = $ExpressModel->deliverylist($model['express_no'], $model['send_time']);
- return $this->renderSuccess($res);
- }
- //协商历史
- public function hisList($order_refund_id){
- $list = RefundHis::where(['order_refund_id'=>$order_refund_id])->where('type','>',0)->order(['id'=>'desc'])->select();
- if($list){
- foreach ($list as &$arr){
- $arr['json'] = json_decode($arr['json'],true);
- }
- }
- return $this->renderSuccess(compact('list'));
- }
- }
|