Your Name 2 tahun lalu
induk
melakukan
da4fd6aa78
2 mengubah file dengan 45 tambahan dan 2 penghapusan
  1. 9 2
      learn/active/database/order.php
  2. 36 0
      learn/active/lib/Manage.php

+ 9 - 2
learn/active/database/order.php

@@ -9,8 +9,11 @@ $pay_type = array
 $status = array
 (
     1 => '待支付',
-    2 => '已完成',
-    3 => '已关闭',
+    2 => '已支付',
+    3 => '已关闭',#超时未支付
+    4 => '已完成',
+    5 => '已完成(有退款)',
+    6 => '已完成已退款',#(全部退款)
 );
 $active = function()
 {
@@ -165,6 +168,10 @@ return array
         'edit' => false,
         'insert' => false,
         'excel'	=> $excel,
+        'list_button' => array
+        (
+        	'oper'  => array('全额退款', '"active/lib/manage.refund?id={id}"', '{status} == 2'),
+        ),
     ),
 
     'request' => array

+ 36 - 0
learn/active/lib/Manage.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Active\Lib;
+
+use Dever;
+Class Manage {
+	#全额退款
+	public function refund($id){
+		$data = Dever::db('active/order')->find($id);
+		$param = array
+        (
+            'project_id' => 6,
+            'channel_id' => 1,
+            'system_source' => 1,
+            'order_id' => $data['order_num'],
+            'refund_cash' => $data['price'],
+            'refund_order_id' => $data['order_num'],
+        );
+        if($data['status'] != 2){
+        	Dever::alert('此状态下不可退款');
+        }
+
+        if ($data['price'] > 0) {
+            $result = Dever::load('pay/api.refund', $param);
+
+            if (!$result) {
+                # 退款失败,抛出错误
+                //throw new \Exception('退款失败');
+                Dever::alert('退款失败,请联系管理员');
+            }else{
+            	Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>6));
+            }
+        }
+  		return 'reload';
+	}
+}