Browse Source

已支付,为发货的商城订单,也能取消订单

lizhen_gitee 9 tháng trước cách đây
mục cha
commit
4a6e5f3887

+ 11 - 3
addons/unishop/controller/Order.php

@@ -360,12 +360,17 @@ class Order extends Base
                 break;
         }
 
-        if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
+        /*if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
             $this->error('此订单已支付,无法取消');
+        }*/
+        if ($order['have_delivered'] != \addons\unishop\model\Order::DELIVERED_NO) {
+            $this->error('此订单已发货,无法取消');
         }
 
-        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
+//        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
+        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_delivered'] == \addons\unishop\model\Order::DELIVERED_NO) {
             $order->status = \addons\unishop\model\Order::STATUS_CANCEL;
+            $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_DELIVERY;
             $order->save();
             $this->success('取消成功', true);
         }
@@ -782,8 +787,11 @@ class Order extends Base
         if (!$order) {
             $this->error(__('Order not exist'));
         }
-        if ($order['have_paid'] == 0) {
+        /*if ($order['have_paid'] == 0) {
             $this->error(__('订单未支付,可直接取消,无需申请售后'));
+        }*/
+        if ($order['have_delivered'] == 0) {
+            $this->error(__('订单未发货,可直接取消,无需申请售后'));//发货的才能走售后,未发货的走取消
         }
         if($order->status == 0){
             $this->error('当前订单不能申请退款');

+ 1 - 1
addons/unishop/model/Order.php

@@ -46,7 +46,7 @@ class Order extends Model
     const STATUS_CANCEL = 0; // 用户取消订单
     const STATUS_REFUND = -1; // 申请售后
 
-    // 申请售后状态 0=无,1=申请中,2=通过(让用户发货),3=通过,4=拒绝
+    // 申请售后状态 0=无,1=申请中,2=通过(让用户发货)或无需退货,3=通过,4=拒绝
     const REFUND_STATUS_NONE = 0;
     const REFUND_STATUS_APPLY = 1;
     const REFUND_STATUS_DELIVERY = 2;

+ 82 - 0
application/admin/controller/unishop/Order.php

@@ -431,6 +431,7 @@ class Order extends Backend
                 $params = [
                     'refund_status' => $refund_status,
                     'updatetime' => time(),
+                    'refund_amount' => $refund_amount,
                 ];
                 if($refund_status == 3) {
                     $params['had_refund'] = time();
@@ -511,6 +512,87 @@ class Order extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 已支付未发货退款
+     */
+    public function cancelrefund($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if ($row['status'] != \app\admin\model\unishop\Order::STATUS_CANCEL || $row['have_paid'] == 0 || $row['have_delivered'] != 0) {
+            $this->error('订单状态错误');
+        }
+        if ($this->request->isPost()) {
+
+            Db::startTrans();
+            try {
+
+                $updatetime = $this->request->post('updatetime');
+                $refund_amount = $this->request->post('refund_amount');
+                $refund_status = $this->request->post('refund_status');
+
+                if ($refund_amount > $row['total_price']) {
+                    $this->error('退款金额不能大于实际支付金额');
+                }
+
+                // 退款
+                $params = [
+                    'refund_status' => $refund_status,
+                    'updatetime' => time(),
+                    'refund_amount' => $refund_amount,
+                ];
+                if($refund_status == 3) {
+                    $params['had_refund'] = time();
+                }
+                // 乐观锁
+                $result = Db::name('unishop_order')->where(['id' => $ids, 'updatetime' => $updatetime])->update($params);
+                if (!$result) {
+                    throw new Exception(__('Data had been update before saved, close windows and do it again'));
+                }
+
+                //修改退款金额
+                /*$rs2 = Db::name('unishop_order_refund')->where('order_id',$ids)->update(['amount'=>$refund_amount]);
+                if ($rs2 === false) {
+                    throw new Exception('操作失败');
+                }*/
+
+                //同意并执行退款
+                if($refund_status == 3 && $refund_amount > 0){
+                    $order = Db::name('unishop_order')->where('id',$ids)->find();
+
+                    if($order['pay_type'] == 2){
+                        $wallet_rs = model('wallet')->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,$remark='商城订单退款','unishop_order',$ids);
+                        if($wallet_rs['status'] === false){
+                            throw new Exception($wallet_rs['msg']);
+                        }
+                    }elseif($order['pay_type'] == 3 || $order['pay_type'] == 4){
+                        $refund_result = $this->old_refund($order,$refund_amount);
+                        if($refund_result !== true){
+                            throw new Exception($refund_result);
+                        }
+                    }
+
+                }
+
+                Db::commit();
+            } catch (ValidateException $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            } catch (PDOException $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+
+            $this->success();
+
+        }
+
+        $this->view->assign('row', $row);
+        return $this->view->fetch();
+    }
+
     // 退款
     public function old_refund($order, $refund_price)
     {

+ 4 - 2
application/admin/lang/zh-cn/unishop/order.php

@@ -48,8 +48,10 @@ return [
     'Refund status'           => '售后状态',
     'Apply'           => '申请中',
     'Pass'           => '同意',
-    'Pass and left User delivery'           => '通过(让用户发货)',
-    'Waiting for shipment'           => '等待发货',
+//    'Pass and left User delivery'           => '通过(让用户发货)',
+    'Pass and left User delivery'           => '通过(让用户发货)或无需退货',
+//    'Waiting for shipment'           => '等待发货',
+    'Waiting for shipment'           => '等待买家发货',
     'Refuse'           => '拒绝',
     'This order is not returned'           => '这个订单没有退货',
     'Withdraw money'           => '退款',

+ 0 - 1
application/admin/view/user/user/updatemoney.html

@@ -1,5 +1,4 @@
 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
-    <input type="hidden" name="id" value="{$row.id}">
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">用户:</label>
         <div class="col-xs-12 col-sm-8">

+ 2 - 0
application/common/library/Auth.php

@@ -449,6 +449,8 @@ class Auth
             $userinfo['realname'] = $realname;
         }
 
+        //待审核好友申请
+        $userinfo['friend_apply_number'] = Db::name('friend_apply')->where('to_user_id',$this->id)->where('status',0)->count();
 
         return $userinfo;
     }

+ 14 - 1
public/assets/js/backend/unishop/order.js

@@ -102,7 +102,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'have_delivered_status', title: __('Have_delivered'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
                         {field: 'have_received_status', title: __('Have_received'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
 //                        {field: 'have_commented_status', title: __('Have_commented'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
-                        {field: 'refund_status', title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Waiting for shipment'),"3":__('Pass'),"4":__('Refuse')},  formatter: Table.api.formatter.status},
+                        {field: 'refund_status', title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Pass and left User delivery'),"3":__('Pass'),"4":__('Refuse')},  formatter: Table.api.formatter.status},
                         {field: 'have_paid', title: __('Pay time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
                         {field: 'have_delivered', title: __('Delivered time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
                         {field: 'have_received', title: __('Received time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
@@ -131,6 +131,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     }
                                 },
                                 {
+                                    name: 'cancelrefund',
+                                    text: '未发货退款',
+                                    classname: 'btn btn-xs btn-info btn-cancelrefund',
+                                    extend: 'data-toggle="tooltip"',
+                                    icon: 'fa fa-handshake-o',
+                                    hidden: function(row){
+                                        if(row.status == 0 && row.have_paid != 0 && row.have_delivered == 0){
+                                            return false;
+                                        }
+                                        return true;
+                                    }
+                                },
+                                {
                                     name: 'delivere',
                                     text: '发货',
                                     classname: 'btn btn-xs btn-info btn-delivere',