123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- <?php
- namespace Shop\Lib;
- use Dever;
- class Refund
- {
- # 设置订单的类型
- public function set($type)
- {
- $this->type = $type;
- if ($type == 'dh') {
- $this->order_table = 'agent/dh_order';
- $this->goods_table = 'agent/dh_order_goods';
- $this->refund_table = 'agent/dh_order_refund';
- $this->lib = 'agent/lib/dhorder';
- } elseif ($type == 'card') {
- $this->order_table = 'card/order';
- $this->goods_table = 'card/order_card';
- $this->refund_table = 'shop/order_refund';
- $this->lib = 'card/lib/buy';
- } else {
- $this->order_table = 'shop/' . $type . '_order';
- $this->goods_table = 'shop/' . $type . '_order_goods';
- $this->refund_table = 'shop/' . $type . '_order_refund';
- if ($type == 'buy') {
- $this->lib = 'mshop/lib/' . $type;
- } else {
- $this->lib = 'shop/lib/' . $type;
- }
- }
- return $this;
- }
- # 获取退款记录
- public function getList($type, $id, $order_id)
- {
- $order = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
- $where['order_id'] = $order_id;
- $data = Dever::db($this->refund_table)->select_page($where);
- if ($data) {
- $goods_status = Dever::db($this->goods_table)->config['status'];
- $refund_status = Dever::db($this->refund_table)->config['status'];
- $refund_process = Dever::db($this->refund_table)->config['process'];
- foreach ($data as $k => $v) {
- if ($v['cash'] <= 0 && $v['re_cash'] > 0) {
- $data[$k]['cash'] = $v['cash'] = $v['re_cash'];
- }
- $data[$k]['cdate'] = date('Y-m-d H:i', $v['cdate']);
- if ($v['order_goods_id'] != -1 && $v['order_goods_id']) {
- $data[$k]['goods'] = Dever::db($this->goods_table)->getDataByIds(array('ids' => $v['order_goods_id']));
- } else {
- $data[$k]['goods'] = Dever::db($this->goods_table)->getDataByIds(array('order_id' => $v['order_id']));
- }
-
- $data[$k]['status_name'] = $refund_status[$v['status']];
- $data[$k]['process_name'] = $refund_process[$v['process']];
- if ($data[$k]['goods']) {
- foreach ($data[$k]['goods'] as $k1 => $v1) {
- $data[$k]['goods'][$k1]['info'] = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
- $data[$k]['goods'][$k1]['status_name'] = $goods_status[$v1['status']];
- }
- }
- }
- }
- return $data;
- }
- # 更新退款记录
- public function up($order_id, $order_goods_id, $status, $price, $p_price, $num = false, $desc = '', $pic = '', $process = 1, $order = array(), $re_cash = 0)
- {
- $data['order_id'] = $order_id;
- if (!$order_goods_id) {
- $where['order_id'] = $order_id;
- $goods = Dever::db($this->goods_table)->getIds($where);
- if ($goods) {
- $order_goods_id = implode(',', array_keys($goods));
- }
- $data['type'] = 1;
- } else {
- $data['type'] = 2;
- }
- $data['order_goods_id'] = $order_goods_id;
- $info = Dever::db($this->refund_table)->find($data);
- $data['status'] = $status;
- $data['cash'] = $price;
- if ($p_price) {
- $data['p_cash'] = $p_price;
- }
- $data['re_cash'] = $re_cash;
-
- if ($num) {
- $data['num'] = $num;
- }
- $data['desc'] = $desc;
- $data['pic'] = $pic;
- $data['process'] = $process;
- if ($order && isset($order['parent_type']) && $order['parent_type'] > 1) {
- $data['parent_type'] = $order['parent_type'];
- $data['parent_order_id'] = $order['parent_order_id'];
- }
- if ($info) {
- $data['where_id'] = $info['id'];
- $state = Dever::db($this->refund_table)->update($data);
- if ($state) {
- $data['id'] = $info['id'];
- return $data;
- }
- } else {
- $state = Dever::db($this->refund_table)->insert($data);
- if ($state) {
- $data['id'] = $state;
- return $data;
- }
- }
- return false;
- }
- # 申请退款
- public function apply($type, $id, $order_id, $order_goods_id, $status = 1, $num = 0, $desc = '', $pic = '', $process = 2, $buy_status = false)
- {
- if ($status != 1 && $status != 2 && $status != 3) {
- Dever::alert('当前订单状态不允许退货退款');
- }
- $data = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
- if (isset($data['withdraw']) && $data['withdraw'] == 2) {
- Dever::alert('当前订单状态不允许退货退款');
- }
- $auth = false;
- if ($this->type == 'sell' && $type == 1) {
- if ($data['status'] == 2) {
- $auth = true;
- }
- } else {
- $config = array(2,3,4,5,6);
- if (in_array($data['status'], $config)) {
- $auth = true;
- }
- }
- if ($auth) {
- $re_cash = 0;
- if ($order_goods_id) {
- $info = Dever::db($this->goods_table)->find(array('id' => $order_goods_id, 'order_id' => $data['id']));
- if ($info) {
- Dever::db($this->goods_table)->update(array('where_id' => $info['id'], 'status' => 2));
- if (!$num) {
- $num = $info['num'];
- }
- $info['total_price'] = $info['price'] * $num;
- if (isset($info['discount_cash']) && $info['discount_cash']) {
- $info['total_price'] = $info['total_price'] - $info['discount_cash'];
- }
- if (isset($info['coupon_cash']) && $info['coupon_cash']) {
- $info['total_price'] = $info['total_price'] - $info['coupon_cash'];
- }
- if (isset($data['card_code_cash']) && $data['card_code_cash']) {
- $kou = $data['card_code_cash'] + $data['wallet_cash'];
-
- if ($kou > 0) {
- if ($info['total_price'] >= $kou) {
- $info['total_price'] = $info['total_price'] - $kou;
- } else {
- $re_cash = $info['total_price'];
- $info['total_price'] = 0;
- }
- }
- }
- if (isset($data['record_cash']) && $data['record_cash']) {
- if ($info['total_price'] >= $data['record_cash']) {
- $info['total_price'] = $info['total_price'] - $data['record_cash'];
- } else {
- $re_cash = $info['total_price'];
- $info['total_price'] = 0;
- }
- }
- $cash = $info['total_price'];
- if (isset($info['p_price'])) {
- $p_cash = $info['p_price'] * $num;
- } else {
- $p_cash = 0;
- }
- } else {
- Dever::alert('您没有权限操作1');
- }
- } else {
- Dever::db($this->goods_table)->updates(array('option_order_id' => $data['id'], 'option_status' => 1, 'set_status' => 2));
- if (!$num) {
- $num = $data['num'];
- }
- if (!$data['refund_cash']) {
- $data['refund_cash'] = 0;
- }
- if ($data['price'] <= 0 && isset($data['p_price'])) {
- $data['price'] = $data['p_price'];
- }
- $cash = $data['price'] - $data['refund_cash'];
- $num = $data['num'] - $data['refund_num'];
- if (isset($data['p_price']) && isset($data['refund_p_cash'])) {
- $p_cash = $data['p_price'] - $data['refund_p_cash'];
- } else {
- $p_cash = 0;
- }
- if (isset($data['ps_cash']) && $data['ps_cash'] > 0 && $data['status'] >= 3) {
- # 已发货不退配送费
- $cash -= $data['ps_cash'];
- }
- #新加
- if(isset($data['record_cash']) && $data['record_cash']>0){
- $re_cash = $data['record_cash'];
- }
- }
- $cash = round($cash, 2);
- if ($cash >= 0) {
- $log = $this->up($data['id'], $order_goods_id, $status, $cash, $p_cash, $num, $desc, $pic, $process, $data, $re_cash);
- if (!$log) {
- Dever::alert('退款失败');
- }
- if ($this->type == 'buy') {
- # 如果是采购单,这里要把库存先减掉
- if ($data['status'] == 5 || $data['status'] == 6) {
- $oper_data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $log['order_goods_id']));
- Dever::load('shop/lib/goods')->oper($data, 2, 1, $oper_data);
- }
- if ($data['source_id'] && $data['source_id'] > 0) {
- $data['num'] = $num;
- Dever::load('cash/lib/order')->up($data, 2, 1, $log);
- } else {
- $data['num'] = $num;
- Dever::load('cash/lib/order')->up($data, 1, 3);
- }
- # 发消息给供应商
- if ($data['source_id'] && Dever::project('message')) {
- $msg = '您的订单'.$data['order_num'].',有新的商品问题。';
- $msg_param['type'] = 1;
- $msg_param['id'] = $data['id'];
- $msg_param = Dever::json_encode($msg_param);
- $pid = $data['source_type'] + 1;
- Dever::load('message/lib/data')->push(-1, $data['source_id'], '退货与报损通知', $msg, 2, $pid, false, $msg_param);
- }
- }
- if (!$data['refund_cash']) {
- $data['refund_cash'] = 0;
- }
- if (isset($data['refund_p_cash']) && !$data['refund_p_cash']) {
- $data['refund_p_cash'] = 0;
- }
- $update = array();
- $update['where_id'] = $data['id'];
- $update['refund_cash'] = $data['refund_cash'] + $cash + $re_cash;
- $update['refund_num'] = $data['refund_num'] + $num;
- if (isset($data['refund_p_cash'])) {
- $update['refund_p_cash'] = $data['refund_p_cash'] + $p_cash;
- }
- $update['refund_status'] = 2;
-
- Dever::db($this->order_table)->update($update);
- if ($id && $process == 2) {
- $this->action($log, $process, $data, true, $buy_status);
- }
- } else {
- Dever::alert('您没有可以退款的金额');
- }
- } else {
- Dever::alert('您没有权限操作2');
- }
- return 'reload';
- }
- # 确认退款
- public function action($info, $process, $order = false, $cash = true, $buy_status = false)
- {
- if (!is_array($info)) {
- $info = Dever::db($this->refund_table)->find($info);
- }
- if (!$info) {
- Dever::alert('您没有权限操作3');
- }
- if (!$order) {
- $order = Dever::db($this->order_table)->find($info['order_id']);
- }
- if (!$order) {
- Dever::alert('您没有权限操作4');
- }
- if (isset($order['withdraw']) && $order['withdraw'] == 2) {
- Dever::alert('当前订单状态不允许退货退款');
- }
- $state = Dever::db($this->refund_table)->update(array('where_id' => $info['id'], 'process' => $process));
- if (!$state) {
- Dever::alert('操作失败');
- }
- $update = $data = array();
- if ($process == 3) {
- if ($info['num'] && $info['num'] > 0) {
- //$update['num'] = $order['num'] + $info['num'];
- }
- $update['refund_num'] = $order['refund_num'] - $info['num'];
- $update['refund_cash'] = $order['refund_cash'] - $info['cash'];
- if (isset($order['refund_p_cash'])) {
- $update['refund_p_cash'] = $order['refund_p_cash'] - $info['p_cash'];
- }
- $update['where_id'] = $order['id'];
- if ($update['refund_cash'] <= 0) {
- $update['refund_status'] = 1;
- } else {
- $update['refund_status'] = 3;
- }
- # 检测是否还有别的退款申请
- $refund_data = Dever::db($this->refund_table)->find(array('order_id' => $order['id'], 'process' => 1));
- if ($refund_data) {
- $update['refund_status'] = 2;
- }
-
- $state = Dever::db($this->order_table)->update($update);
- if ($info['type'] == 2) {
- Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 1));
- } else {
- Dever::db($this->goods_table)->updates(array('option_order_id' => $order['id'], 'option_status' => 2, 'set_status' => 1));
- }
- if ($cash && $this->type == 'buy' && $order['source_id'] && $order['source_id'] > 0) {
- $order['num'] = $info['num'];
- Dever::load('cash/lib/order')->up($order, 2, 3, $info);
- }
- } else {
- if ($info['type'] == 2) {
- if ($info['order_goods_id']) {
- $data = Dever::db($this->goods_table)->getDataByIds(array('ids' => $info['order_goods_id'], 'order_id' => $info['order_id'], 'clear' => true));
- }
- $state = Dever::db($this->goods_table)->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
- if ($state) {
- $this->notice($state, $order, $info);
- # 检查这个订单下的商品是不是都退了
- $total = Dever::db($this->goods_table)->getTotal(array('order_id' => $order['id'], 'status' => '1,2'));
- if ($total <= 0) {
- $update['operdate'] = time();
- $update['status'] = 8;
- $update['refund_status'] = 4;
- } elseif ($order['status'] == 5) {
- $update['status'] = 6;
- $update['refund_status'] = 3;
- } else {
- $update['refund_status'] = 3;
- }
- if ($update['refund_status'] == 3) {
- $refund_data = Dever::db($this->refund_table)->find(array('order_id' => $order['id'], 'process' => 1));
- if ($refund_data) {
- $update['refund_status'] = 2;
- }
- }
- if ($update) {
- $update['where_id'] = $order['id'];
- $state = Dever::db($this->order_table)->update($update);
- }
- if ($buy_status != -1) {
- if (isset($order['parent_type']) && $order['parent_type'] > 1 && isset($order['parent_order_id']) && $order['parent_order_id']) {
- # 把关联订单也退掉
- $goods_info = Dever::db($this->goods_table)->find($info['order_goods_id']);
- if ($goods_info) {
- if ($order['parent_type'] == 2) {
- $sell_order_goods = Dever::db('shop/sell_order_goods')->find(array('order_id' => $order['parent_order_id'], 'goods_id' => $goods_info['goods_id'], 'sku_id' => $goods_info['sku_id']));
- } elseif ($order['parent_type'] == 3) {
- $dh_order_goods = Dever::db('agent/dh_order_goods')->find(array('order_id' => $order['parent_order_id'], 'goods_id' => $goods_info['goods_id'], 'sku_id' => $goods_info['sku_id']));
- }
-
- }
- } elseif (isset($order['shop_type']) && $order['shop_type'] == 2) {
- # 把关联订单也退掉
- $buy_order = Dever::db('shop/buy_order')->select(array('parent_type' => 2, 'parent_order_id' => $info['order_id']));
- if ($buy_order) {
- $goods_info = Dever::db($this->goods_table)->find($info['order_goods_id']);
- foreach ($buy_order as $k => $v) {
- $temp = Dever::db('shop/buy_order_goods')->find(array('order_id' => $v['id'], 'goods_id' => $goods_info['goods_id'], 'sku_id' => $goods_info['sku_id']));
- if ($temp) {
- $temp['type'] = $v['type'];
- $temp['type_id'] = $v['type_id'];
- $buy_order_goods = $temp;
- }
- }
- }
- } elseif (isset($order['mid']) && $order['mid']) {
- # 把关联订单也退掉
- $buy_order = Dever::db('shop/buy_order')->select(array('parent_type' => 3, 'parent_order_id' => $info['order_id']));
- if ($buy_order) {
- $goods_info = Dever::db($this->goods_table)->find($info['order_goods_id']);
- foreach ($buy_order as $k => $v) {
- $temp = Dever::db('shop/buy_order_goods')->find(array('order_id' => $v['id'], 'goods_id' => $goods_info['goods_id'], 'sku_id' => $goods_info['sku_id']));
- if ($temp) {
- $temp['type'] = $v['type'];
- $temp['type_id'] = $v['type_id'];
- $buy_order_goods = $temp;
- }
- }
- }
- }
- }
- }
- } else {
- $update['where_id'] = $order['id'];
- $update['operdate'] = time();
- if (isset($order['ps_cash']) && $order['ps_cash'] > 0 && $order['status'] < 3) {
- # 配送费退掉
- //$update['ps_cash'] = 0;
- }
- $update['status'] = 8;
- $update['refund_status'] = 4;
- $state = Dever::db($this->order_table)->update($update);
- if ($state) {
- $data = Dever::db($this->goods_table)->getDataByIds(array('order_id' => $order['id'], 'status' => 2, 'clear' => true));
- Dever::db($this->goods_table)->updates(array('option_order_id' => $order['id'], 'option_status' => 2, 'set_status' => 3));
- $this->notice($state, $order, $info);
- if (isset($order['user_coupon_id']) && $order['user_coupon_id']) {
- # 还原优惠券
- Dever::db('shop/user_coupon')->update(array('where_id' => $order['user_coupon_id'], 'status' => 1));
- }
- }
- }
- $re_cash = $info['re_cash'];
- if (isset($order['card_code_id']) && $order['card_code_id'] && $order['card_code_cash'] > 0) {
- # 还原礼品卡
- if ($re_cash > 0) {
- $card_cash = $re_cash;
- } else {
- $card_cash = $order['card_code_cash'];
- }
-
- if ($re_cash > 0) {
- $card_code_cash = $order['card_code_cash'] - $re_cash;
- $order['card_code_cash'] = $re_cash;
- Dever::db($this->order_table)->update(array('where_id' => $order['id'], 'card_code_cash' => $card_code_cash, 'clear' => true));
- }
- Dever::db('card/code')->decUseCash(array('where_id' => $order['card_code_id'], 'set_use_cash' => $order['card_code_cash']));
- # 生成结算单
- $code = Dever::db('card/code')->find($order['card_code_id']);
- if ($code) {
- $card_info = Dever::db('card/info')->find($code['card_id']);
- if ($card_info) {
- if ($card_info['price'] == $card_info['value']) {
- $price = $card_cash;
- } else {
- $zhe = round($card_info['price']/$card_info['value'], 2);
- $price = round($card_cash*$zhe, 2);
- }
- $rorder = $order;
- $rinfo = $info;
- $rorder['type'] = 1;
- $rorder['type_id'] = $rorder['shop_id'];
- $rorder['source_type'] = 4;
- $rorder['source_id'] = -1;
- $rorder['num'] = $info['num'];
- $rinfo['cash'] = $rorder['price'] = $price;
- $rinfo['p_cash'] = $rorder['p_price'] = $card_cash;
- if (isset($update['status'])) {
- $rorder['status'] = $update['status'];
- }
- Dever::load('cash/lib/order')->up($rorder, 2, 2, $rinfo, 2);
- }
- }
- } elseif (isset($order['wallet_cash']) && $order['wallet_cash'] && $order['wallet_cash'] > 0) {
- # 还原钱包
- if ($re_cash > 0) {
- $wallet_cash = $re_cash;
- } else {
- $wallet_cash = $order['wallet_cash'];
- }
-
- if ($re_cash > 0) {
- $wallet_cash = $order['wallet_cash'] - $re_cash;
- $order['wallet_cash'] = $re_cash;
- Dever::db($this->order_table)->update(array('where_id' => $order['id'], 'wallet_cash' => $wallet_cash, 'clear' => true));
- }
- Dever::load('shop/lib/money')->up($order['uid'], 4, $wallet_cash, $order['id'], '商品退款', 2);
- $rorder = $order;
- $rinfo = $info;
- $rorder['type'] = 1;
- $rorder['type_id'] = $rorder['shop_id'];
- $rorder['source_type'] = 4;
- $rorder['source_id'] = -1;
- $rorder['num'] = $info['num'];
- $rinfo['cash'] = $rorder['price'] = $wallet_cash;
- $rinfo['p_cash'] = $rorder['p_price'] = $order['wallet_cash'];
- if (isset($update['status'])) {
- $rorder['status'] = $update['status'];
- }
- Dever::load('cash/lib/order')->up($rorder, 2, 2, $rinfo, 3);
- }elseif (isset($order['record_cash']) && $order['record_cash'] && $order['record_cash'] > 0) {
- # 还原资金账户
- if ($re_cash > 0) {
- $record_cash = $re_cash;
- } else {
- $record_cash = $order['record_cash'];
- }
-
- if ($re_cash > 0) {
- $record_cash = $order['record_cash'] - $re_cash;
- $order['record_cash'] = $re_cash;
- Dever::db($this->order_table)->update(array('where_id' => $order['id'], 'record_cash' => $record_cash, 'clear' => true));
- }
- $record = Dever::db('shop/record')->find(array('type_id'=>$info['order_id'],'shop_id'=>$order['type_id']));
- $shop = Dever::db('shop/info')->find(array('id'=>$order['type_id']));
- if($shop && $record){
- if(!$shop['price']){
- $shop['price'] = 0;
- }
- $price = $shop['price'] + $info['re_cash'];
- $explan = '订单退货返还';
- Dever::load('shop/lib/record')->pingtai($shop['id'],$shop['sid'],3,$info['order_id'],$info['re_cash'],$price,$explan);
- }
- $rorder = $order;
- $rinfo = $info;
- $rorder['type'] = 1;
- $rorder['type_id'] = $rorder['type_id'];
- $rorder['source_type'] = 4;
- $rorder['source_id'] = -1;
- $rorder['num'] = $info['num'];
- $rinfo['cash'] = $rorder['price'] = $record_cash;
- $rinfo['p_cash'] = $rorder['p_price'] = $order['record_cash'];
- if (isset($update['status'])) {
- $rorder['status'] = $update['status'];
- }
- Dever::load('cash/lib/order')->up($rorder, 2, 2, $rinfo, 3);
- }
- if ($cash && isset($order['source_id']) && $order['source_id'] && $order['source_id'] > 0) {
- $order['num'] = $info['num'];
- if (isset($update['status'])) {
- $order['status'] = $update['status'];
- }
-
- Dever::load('cash/lib/order')->up($order, 2, 2, $info);
- }
- }
- if ($this->type == 'sell' && $process == 2) {
- # 如果是销售单,退款后要减少销量
- Dever::load('shop/lib/goods')->oper($order, 2, 2, $data);
- } elseif ($this->type == 'buy' && $process == 3 && ($order['status'] == 5 || $order['status'] == 6)) {
- # 如果是采购单,退款后要恢复库存
- Dever::load('shop/lib/goods')->oper($order, 1, 1, $data);
- } elseif ($this->type == 'buy' && $process == 2 && $order['source_type'] == 2) {
- # 如果是采购单,退款后要恢复库存
- Dever::load('store/lib/goods')->oper($order['source_id'], 2, 2, $data);
- } elseif ($this->type == 'dh' && $process == 2) {
- # 如果是兑换单,要恢复
- Dever::load('agent/lib/dhorder')->updateSell($order, 2);
- }
- if (isset($sell_order_goods) && $sell_order_goods) {
- Dever::load('shop/lib/refund')->set('sell')->apply(2, $sell_order_goods['shop_id'], $sell_order_goods['order_id'], $sell_order_goods['id'], 2, 0, '退货退款', '', 2, -1);
- } elseif (isset($buy_order_goods) && $buy_order_goods) {
- Dever::load('shop/lib/refund')->set('buy')->apply($buy_order_goods['type'], $buy_order_goods['type_id'], $buy_order_goods['order_id'], $buy_order_goods['id'], $buy_status, 0, $info['desc'], '', 2, -1);
- } elseif (isset($dh_order_goods) && $dh_order_goods) {
- Dever::load('shop/lib/refund')->set('dh')->apply(2, $dh_order_goods['mid'], $dh_order_goods['order_id'], $dh_order_goods['id'], 2, 0, '退货退款', '', 2, -1);
- }
- return 'reload';
- }
- # 获取部分退款的详情
- public function getInfo($type, $id, $order_id, $order_goods_id)
- {
- $data = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
- $info = Dever::db($this->goods_table)->find(array('id' => $order_goods_id, 'order_id' => $data['id'], 'status' => 1));
- if ($info) {
- if ($type > 10) {
- $info['price'] = $info['p_price'];
- }
- $total = ($info['price'] * $info['num']);
- if (isset($info['discount_cash']) && $info['discount_cash']) {
- $total = $total - $info['discount_cash'];
- }
- if (isset($info['coupon_cash']) && $info['coupon_cash']) {
- $info['tui_price'] = $total - $info['coupon_cash'];
- } else {
- $info['tui_price'] = $total;
- }
- $info['tui_one_price'] = $info['price'];
- $info['goods'] = Dever::db('goods/info')->one($info['goods_id']);
- }
- return $info;
- }
- # 退款通知
- public function notice($state, $data, $info)
- {
- if (!$state) {
- return;
- }
- if (isset($data['dh_type'])) {
- return;
- }
- if (isset($data['type']) && $data['type'] > 1) {
- return;
- }
- if (isset($data['pay_type']) && $data['pay_type'] > 1) {
- return;
- }
- if (isset($data['parent_type']) && $data['parent_type'] > 1) {
- return;
- }
- if ($info['cash'] <= 0) {
- return;
- }
- $refund_cash = $info['cash'];
- $refund_order_id = $info['id'];
- # 退款到原支付账户 待处理
- if (strstr($data['order_num'], '_')) {
- $temp = explode('_', $data['order_num']);
- $data['order_num'] = $temp[0];
- }
- $param = array
- (
- 'project_id' => 1,
- 'channel_id' => 1,
- 'system_source' => 5,
- 'order_id' => $data['order_num'],
- 'refund_cash' => $refund_cash,
- 'refund_order_id' => $refund_order_id
- );
- if ($refund_cash > 0) {
- $result = Dever::load('pay/api.refund', $param);
- if (!$result) {
- # 退款失败,抛出错误
- //throw new \Exception('退款失败');
- Dever::alert('退款失败,请联系管理员');
- }
- }
-
- if (isset($data['uid']) && $data['uid'] > 0) {
- $shop = Dever::db('shop/info')->one($data['shop_id']);
- $msg_param['type'] = 1;//消息类型1是订单消息
- $msg_param['id'] = $data['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- $msg = '您有一笔订单已退款,退款将在3个工作日内返回原支付账户';
- if (Dever::project('message')) {
- Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 2, 1, false, $msg_param);
- }
- if (Dever::project('wechat_applet')) {
- $config = Dever::db($this->order_table)->config;
- $user = Dever::db('passport/wechat')->one(array('uid' => $data['uid'], 'system_id' => 1, 'system_source' => 5));
- if ($user && $user['openid']) {
- $send = array
- (
- 'character_string1' => array
- (
- 'value' => $data['order_num'],
- ),
- 'amount3' => array
- (
- 'value' => $refund_cash . '元',
- ),
- 'thing7' => array
- (
- 'value' => '您的退款已到账,请查看~',
- ),
- );
- $send = Dever::json_encode($send);
- Dever::load('wechat_applet/subscribe')->sendOne('order_refund', 1, $user['openid'], 'pages/app/order/order?id=' . $data['id'], $send, Dever::config('base')->wechat_applet);
- }
- }
- }
- }
- }
|