rabin 6 months ago
parent
commit
4872814823

+ 1 - 0
src/place/api/Data.php

@@ -89,6 +89,7 @@ class Data extends Main
                 $parent = Dever::db('member', 'place')->find($parent_uid);
                 if ($parent && $parent['agent_id'] && $parent['agent_id'] > 0) {
                     Dever::load('relation', 'invite')->set($parent_uid, $id);
+                    Dever::db('member', 'place')->update($id, array('parent_uid' => $parent_uid));
                 }
             }
         }

+ 69 - 0
src/place/api/Resource.php

@@ -100,4 +100,73 @@ class Resource extends Main
         $this->service->upOrderAddress();
         return 'ok';
     }
+
+    # 确认收货
+    public function upOrderFinish()
+    {
+        $this->service->upOrderFinish();
+        return 'ok';
+    }
+
+    # 申请退款
+    public function applyRefund()
+    {
+        $info = $this->service->getOrderView();
+        if ($info && $info['type'] == 1 && $info['status'] > 1 && $info['status'] < 7 && !$info['refund_cur']) {
+            $data['type'] = Dever::db('order_refund', $this->service->app)->value('type');
+            $data['desc_type'] = Dever::db('order_refund', $this->service->app)->value('desc_type');
+            $data['cash'] = $info['cash'];
+            $data['detail'] = $info['detail'];
+            return $data;
+        } else {
+            Dever::error('无法申请退款');
+        }
+    }
+
+    # 确认申请退款
+    public function applyRefundAct_commit(){}
+    public function applyRefundAct()
+    {
+        $info = $this->service->getOrderView();
+        if ($info && $info['type'] == 1 && $info['status'] > 1 && $info['status'] < 7 && !$info['refund_cur']) {
+            $type = Dever::input('apply_type', 'is_numeric', '申请类型');
+            $desc_type = Dever::input('desc_type', 'is_numeric', '申请原因');
+            $cash = Dever::input('cash', 'is_numeric', '退款金额');
+            $desc = Dever::input('desc', 'is_string', '申请说明');
+            $detail = Dever::input('detail', 'isset', '退款明细');
+            if (is_string($detail)) {
+                $detail = Dever::json_decode($detail);
+            }
+            $log['type'] = 1;
+            $log['uid'] = Place::$uid;
+            Dever::load('refund', $this->service->app)->up($detail, $info, $type, $desc_type, $cash, $desc, $log);
+            return 'ok';
+        } else {
+            Dever::error('无法申请退款');
+        }
+    }
+
+    # 退款单发货 获取信息
+    public function express()
+    {
+        $info = $this->service->getOrderView();
+        if ($info && $info['type'] == 1 && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
+            $data['express'] = Dever::db('express', 'sector')->select([]);
+            return $data;
+        }
+        Dever::error('无发货权限');
+    }
+
+    # 退款单发货
+    public function expressAct()
+    {
+        $info = $this->service->getOrderView();
+        if ($info && $info['type'] == 1 && $info['refund'] && $info['refund']['type'] == 1 && $info['refund']['status'] == 2) {
+            $express_id = Dever::input('express_id', 'is_string', '快递公司');
+            $number = Dever::input('number', 'is_string', '快递单号');
+            Dever::load('refund', $this->service->app)->express($info, $info['refund'], $express_id, $number);
+            return 'ok';
+        }
+        Dever::error('无发货权限');
+    }
 }

+ 13 - 0
src/place/api/Test.php

@@ -15,4 +15,17 @@ class Test extends Main
         Dever::load('order', $app)->success($order_num, $status);
         return 'ok';
     }
+
+    public function yue_commit(){}
+    public function yue()
+    {
+        $state = Dever::db('member', 'place')->update(Place::$uid, array('cash' => -10));
+        $info = Dever::db('member', 'place')->find(Place::$uid);
+        $info['yue'] = $info['cash'];
+        if ($info['yue'] < 0) {
+            Dever::error('余额不足');
+        }
+
+        print_r($state);die;
+    }
 }

+ 1 - 0
src/place/lib/Address.php

@@ -71,6 +71,7 @@ class Address
                 $data['province_name'] = $info['name'];
             }
         }
+        $data['full'] = $data['name'] . ',' . $data['phone'] . ',' . $data['area_string'] . ',' . $data['address'];
         return $data;
     }
 

+ 16 - 1
src/place/lib/Resource.php

@@ -99,6 +99,7 @@ class Resource
             $data['order_id'] = Dever::db('order', $this->app)->insert($order);
             $data['order_num'] = $order['order_num'];
             if (isset($info['detail'])) {
+                Dever::load('log', $this->app)->up(1, $order['uid'], $data['order_id'], '下单成功');
                 $detail['order_id'] = $data['order_id'];
                 foreach ($info['detail'] as $k => $v) {
                     $detail['info_id'] = $v['id'];
@@ -162,7 +163,7 @@ class Resource
         return $order;
     }
 
-    # 获取订单详情
+    # 更新地址
     public function upOrderAddress()
     {
         $where['uid'] = Place::$uid;
@@ -182,6 +183,20 @@ class Resource
         return $order;
     }
 
+    # 确认收货
+    public function upOrderFinish()
+    {
+        $where['uid'] = Place::$uid;
+        $where['id'] = Dever::input('id', 'is_numeric', '订单');
+        $order = Dever::db('order', $this->app)->find($where);
+        if ($order && ($order['status'] == 3 || $order['status'] == 4)) {
+            Dever::load('order', $this->app)->finish(1, $order);
+        } else {
+            Dever::error('无法确认收货');
+        }
+        return $order;
+    }
+
     private function getOrderInfo($order, $view = false)
     {
         if ($order) {

+ 25 - 0
src/place/manage/core.php

@@ -54,6 +54,31 @@ return array
             'sort'      => '1',
         ),
 
+        'member_vip' => array
+        (
+            'parent'    => 'member_manage',
+            'name'      => '会员列表',
+            'icon'      => 'vip-line',
+            'sort'      => '2',
+        ),
+
+        'member_agent' => array
+        (
+            'parent'    => 'member_manage',
+            'name'      => '代理列表',
+            'icon'      => 'vip-crown-2-line',
+            'sort'      => '3',
+        ),
+
+        'member_agent_child' => array
+        (
+            'parent'    => 'member_manage',
+            'name'      => '代理下级列表',
+            'icon'      => 'vip-crown-2-line',
+            'sort'      => '4',
+            'show'      => 3,
+        ),
+
         # 配置
         'set_manage' => array
         (

+ 1 - 1
src/place/manage/info.php

@@ -14,7 +14,7 @@ $id = $data[0]['children'][0]['id'];
 $uid = $data[0]['children'][0]['uid'];
 $user = Dever::db('user', 'sector')->find($uid);
 if ($user['channel'] == 1) {
-    $config['update']['tab']['渠道设置'] = 'channel,place/client_price,place/client';
+    $config['update']['tab']['供货设置'] = 'channel,place/client_price,place/client';
     $config['update']['field']['channel'] = array
     (
         'type' => 'radio',

+ 2 - 2
src/place/manage/member.php

@@ -26,11 +26,11 @@ return array
         ),
         'data_button' => array
         (
-            '编辑' => 'edit',
+            '编辑' => 'fastedit',
         ),
         'search'    => array
         (
-            'name',
+            'name' => 'like',
             'mobile',
             'vip_id',
             'agent_id',

+ 56 - 0
src/place/manage/member_agent.php

@@ -0,0 +1,56 @@
+<?php
+return array
+(
+    'source' => 'place/member',
+    'list' => array
+    (
+        'where' => array('agent_id' => array('>=', 1)),
+        'field'      => array
+        (
+            'id',
+            'name',
+            'mobile',
+            'agent_id',
+            'cash',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            //'新增' => array('add'),
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+            '下级' => array('route', array
+            (
+                'path' => 'member_manage/member_agent_child',
+                'param' => array
+                (
+                    'set' => array('parent_uid' => 'id', 'menu' => 'member_manage/member_agent', 'parent' => 'member_manage/member_agent'),
+                ),
+            )),
+        ),
+        'search'    => array
+        (
+            'name' => 'like',
+            'mobile',
+            'agent_id',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name',
+            'agent_id',
+        ),
+    ),
+);

+ 43 - 0
src/place/manage/member_agent_child.php

@@ -0,0 +1,43 @@
+<?php
+$parent_uid = Dever::input('set')['parent_uid'];
+return array
+(
+    'source' => 'place/member',
+    'list' => array
+    (
+        'where' => array('parent_uid' => $parent_uid),
+        'field'      => array
+        (
+            'id',
+            'name',
+            'mobile',
+            'vip_id',
+            'agent_id',
+            'cash',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            //'新增' => array('add'),
+        ),
+        'data_button' => array
+        (
+            //'编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name' => 'like',
+            'mobile',
+            'vip_id',
+            'agent_id',
+            'status',
+        ),
+    ),
+);

+ 48 - 0
src/place/manage/member_vip.php

@@ -0,0 +1,48 @@
+<?php
+return array
+(
+    'source' => 'place/member',
+    'list' => array
+    (
+        'where' => array('vip_id' => array('>=', 1)),
+        'field'      => array
+        (
+            'id',
+            'name',
+            'mobile',
+            'vip_id',
+            'cash',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            'cdate',
+        ),
+        'button' => array
+        (
+            //'新增' => array('add'),
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'search'    => array
+        (
+            'name' => 'like',
+            'mobile',
+            'vip_id',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name',
+            'vip_id',
+        ),
+    ),
+);

+ 1 - 1
src/place/table/info.php

@@ -99,7 +99,7 @@ return array
 
         'channel' => array
         (
-            'name'      => '渠道',
+            'name'      => '供货能力',
             'type'      => 'tinyint(1)',
             'default'   => 2,
             'value'     => array

+ 6 - 0
src/place/table/member.php

@@ -46,6 +46,12 @@ return array
             'value'     => 'sector/user',
             'default'   => -1,
         ),
+        'parent_uid' => array
+        (
+            'name'      => '上级',
+            'type'      => 'int(11)',
+            'default'   => -1,
+        ),
         'score_cash' => array
         (
             'name'      => '积分余额',

+ 13 - 2
src/resource/goods/lib/Address.php

@@ -7,12 +7,16 @@ class Address
     {
         $order = Dever::db('order', 'goods')->find($data['id']);
         if ($order) {
-            $this->up($order['id'], $order['uid'], $order['address_id'], $data['address_name'], $data['address_phone'], $data['address_area'], $data['address_address']);
+            $auth = new \Manage\Lib\Auth();
+            $uid = $auth->uid;
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            $this->up($order['id'], $order['uid'], $order['address_id'], $data['address_name'], $data['address_phone'], $data['address_area'], $data['address_address'], $log);
         }
         return 'end';
     }
 
-    public function up($order_id, $uid, $address_id, $name, $phone, $area, $address)
+    public function up($order_id, $uid, $address_id, $name, $phone, $area, $address, $log = false)
     {
         $update['uid'] = $uid;
         $update['name'] = $name;
@@ -29,5 +33,12 @@ class Address
             $id = Dever::db('address', 'place')->insert($update);
             Dever::db('order', 'goods')->update($order_id, array('address_id' => $id));
         }
+        $type = 1;
+        if ($log) {
+            $type = $log['type'];
+            $uid = $log['uid'];
+        }
+        $address = Dever::load('address', 'place')->handleInfo($update);
+        Dever::load('log', 'goods')->up($type, $uid, $order_id, '更改收货地址:' . $address['full']);
     }
 }

+ 85 - 2
src/resource/goods/lib/Express.php

@@ -7,12 +7,16 @@ class Express
     {
         $order = Dever::db('order', 'goods')->find($data['order_id']);
         if ($order && $order['status'] <= 3) {
-            $this->up($data['id'], $order['id'], $data['express_id'], $data['number']);
+            $auth = new \Manage\Lib\Auth();
+            $uid = $auth->uid;
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            $this->up($data['id'], $order['id'], $data['express_id'], $data['number'], $log);
         }
         return 'end';
     }
 
-    public function up($id, $order_id, $express_id, $number)
+    public function up($id, $order_id, $express_id, $number, $log = false)
     {
         $update['order_id'] = $order_id;
         $update['express_id'] = $express_id;
@@ -26,5 +30,84 @@ class Express
             Dever::db('order_express', 'goods')->insert($update);
             Dever::db('order', 'goods')->update($order_id, array('status' => 3, 'ddate' => time()));
         }
+        if ($log) {
+            $type = $log['type'];
+            $uid = $log['uid'];
+            $express_info = Dever::db('express', 'sector')->find($update['express_id']);
+            $msg = '已发货:' . $express_info['name'] . ',' . $update['number'];
+            Dever::load('log', 'goods')->up($type, $uid, $order_id, $msg);
+        }
+    }
+
+    # 获取快递物流信息
+    public function getInfo($order, $address_id, $type = 1)
+    {
+        if ($type == 1) {
+            $info = Dever::db('order_express', 'goods')->find(array('order_id' => $order['id']));
+        } else {
+            $info = Dever::db('order_refund_express', 'goods')->find(array('order_refund_id' => $order['id']));
+        }
+
+        if ($info) {
+            $express_info = Dever::db('express', 'sector')->find($info['express_id']);
+            $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
+            $info['name'] = $express_info['name'];
+            $log = Dever::db('express_log', 'sector')->find(array('number' => $info['number']));
+            if ($log) {
+                if ($log['status'] == 1) {
+                    $info['log'] = Dever::json_decode($log['content']);
+                } else {
+                    if (time() - $log['udate'] > 3600) {
+                        list($info['log'], $order['status']) = $this->get($order, $info['express_id'], $info['number'], $log['mobile'], $log['id'], $type);
+                    } else {
+                        $info['log'] = Dever::json_decode($log['content']);
+                    }
+                }
+            } else {
+                $address = Dever::db('address', 'place')->find($address_id);
+                list($info['log'], $order['status']) = $this->get($order, $info['express_id'], $info['number'], $address['phone'], false, $type);
+            }
+            $order['express'] = $info;
+        }
+        return $order;
+    }
+
+    public function get($order, $express_id, $number, $mobile, $id = false, $type = 1)
+    {
+        $param['number'] = $number;
+        $param['mobile'] = substr($mobile, -4);
+        //$data = Dever::load('account', 'api')->run('aliyun_market', 'express', $param);
+        $data['data']['list'] = array();
+        $data['data']['state'] = 2;
+        if ($data && isset($data['data']['list'])) {
+            if ($data['data']['state'] == 3) {
+                $param['status'] = 1;
+                if ($type == 1) {
+                    if ($order['status'] <= 3) {
+                        $info = $data['data']['list'][0];
+                        Dever::load('log', 'goods')->up(1, $order['uid'], $order['id'], $info['status']);
+                        $order['status'] = 4;
+                        Dever::db('order', 'goods')->update($order['id'], array('status' => $order['status'], 'qdate' => strtotime($info['time'])));
+                    }
+                } else {
+                    if ($order['status'] <= 3) {
+                        $order_info = Dever::db('order', 'goods')->find($order['order_id']);
+                        Dever::load('refund', 'goods')->finish($order_info, $order);
+                    }
+                }
+                
+            } else {
+                $param['status'] = 2;
+            }
+            $param['content'] = Dever::json_encode($data['data']['list']);
+            $param['express_id'] = $express_id;
+            $param['udate'] = time();
+            if ($id) {
+                Dever::db('express_log', 'sector')->update($id, $param);
+            } else {
+                Dever::db('express_log', 'sector')->insert($param);
+            }
+            return array($data['data']['list'], $order['status']);
+        }
     }
 }

+ 7 - 3
src/resource/goods/lib/Log.php

@@ -27,15 +27,19 @@ class Log
     # 获取日志信息
     public function getInfo($info)
     {
-        if ($type == 1) {
+        if ($info['type'] == 1) {
             $user = Dever::db('member', 'place')->find($info['type_id']);
-        } elseif ($type == 2) {
+        } elseif ($info['type'] == 2) {
             $user = Dever::db('user', 'sector')->find($info['type_id']);
-        } elseif ($type == 3) {
+        } elseif ($info['type'] == 3) {
             $user = Dever::db('supplier', 'place')->find($info['type_id']);
+        } else {
+            $user['name'] = $user['mobile'] = '-';
         }
+        $info['type'] = Dever::db('order_log', 'goods')->value('type', $info);
         $info['name'] = $user['name'];
         $info['mobile'] = $user['mobile'];
+        $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
         return $info;
     }
 }

+ 243 - 38
src/resource/goods/lib/Order.php

@@ -47,6 +47,10 @@ class Order
         $info['address'] = Dever::load('address', 'place')->getInfo($info['address_id'], $info['uid']);
         # 运费
         $info['yun'] = Dever::load('price', 'place')->getText(0, 3);
+        if (in_array($info['status'], array(3,4,5))) {
+            $info = Dever::load('express', 'goods')->getInfo($info, $info['address_id']);
+            $info['status_name'] = Dever::db('order', 'goods')->value('status', $info['status']);
+        }
         $info['status_list'] = array
         (
             1 => array
@@ -98,6 +102,88 @@ class Order
         } elseif ($info['status'] > 6) {
             $info['status_msg'] = '订单已取消';
         }
+        
+        $info['refund'] = false;
+        $info['refund_list'] = Dever::db('order_refund', 'goods')->select(array('order_id' => $info['id']));
+        if ($info['refund_list']) {
+            foreach ($info['refund_list'] as $k => $v) {
+                if ($v['status'] < 4) {
+                    $info['refund'] = $v;
+                }
+            }
+        }
+        if ($info['refund']) {
+            if ($info['refund']['status'] > 2) {
+                $info['refund'] = Dever::load('express', 'goods')->getInfo($info['refund'], $info['address_id'], 2);
+            }
+            $info['refund']['cdate_str'] = date('Y-m-d H:i:s', $info['refund']['cdate']);
+            if (isset($info['refund']['sdate']) && $info['refund']['sdate']) {
+                $info['refund']['sdate_str'] = date('Y-m-d H:i:s', $info['refund']['sdate']);
+            }
+            if (isset($info['refund']['ddate']) && $info['refund']['ddate']) {
+                $info['refund']['ddate_str'] = date('Y-m-d H:i:s', $info['refund']['ddate']);
+            }
+            if (isset($info['refund']['fdate']) && $info['refund']['fdate']) {
+                $info['refund']['fdate_str'] = date('Y-m-d H:i:s', $info['refund']['fdate']);
+            }
+            if ($info['refund']['type'] == 1) {
+                $info['refund_status_list'] = array
+                (
+                    1 => array
+                    (
+                        'selected' => false,
+                        'name' => '退货退款',
+                        'time' => $info['refund']['cdate_str'],
+                    ),
+                    2 => array
+                    (
+                        'selected' => false,
+                        'name' => '已审核',
+                        'time' => $info['refund']['sdate_str'] ?? '',
+                    ),
+                    3 => array
+                    (
+                        'selected' => false,
+                        'name' => '买家已发货',
+                        'time' => $info['refund']['ddate_str'] ?? '',
+                    ),
+                    4 => array
+                    (
+                        'selected' => false,
+                        'name' => '已完成',
+                        'time' => $info['refund']['fdate_str'] ?? '',
+                    ),
+                );
+            }
+            if ($info['refund']['type'] == 2) {
+                $info['refund_status_list'] = array
+                (
+                    1 => array
+                    (
+                        'selected' => false,
+                        'name' => '仅退款',
+                        'time' => $info['cdate_str'],
+                    ),
+                    2 => array
+                    (
+                        'selected' => false,
+                        'name' => '已审核',
+                        'time' => $info['sdate_str'] ?? '',
+                    ),
+                    4 => array
+                    (
+                        'selected' => false,
+                        'name' => '已完成',
+                        'time' => $info['fdate_str'] ?? '',
+                    ),
+                );
+            }
+            foreach ($info['refund_status_list'] as $k => $v) {
+                if ($info['refund']['status'] >= $k) {
+                    $info['refund_status_list'][$k]['selected'] = true;
+                }
+            }
+        }
     }
 
     # 取消订单
@@ -118,11 +204,15 @@ class Order
     {
         if ($status == 1) {
             $update['status'] = 2;
+            $msg = '支付成功';
+            
         } else {
             $update['status'] = 7;
+            $msg = '支付失败';
         }
         $update['pdate'] = time();
         $state = Dever::db('order', 'goods')->update($order['id'], $update);
+        Dever::load('log', 'goods')->up(1, $order['uid'], $data['order_id'], $msg);
         if ($state && $update['status'] == 7) {
             # 恢复库存
             $this->resell($order['id']);
@@ -130,6 +220,27 @@ class Order
         return $state;
     }
 
+    # 确认收货
+    public function finish_commit(){}
+    public function finish($type = 1, $order)
+    {
+        if ($order['status'] >= 3 && $order['status'] <= 6) {
+            if ($type == 1) {
+                $uid = $order['uid'];
+            } else {
+                $uid = '';
+            }
+            # 检查有没有退款
+            $refund = Dever::db('order_refund', 'goods')->find(array('order_id' => $order['id'], 'refund_status' => 1));
+            $status = 5;
+            if ($refund) {
+                $status = 6;
+            }
+            Dever::db('order', 'goods')->update($order['id'], array('status' => $status, 'fdate' => time()));
+            Dever::load('log', 'goods')->up($type, $uid, $order['id'], '确认收货,订单完成');
+        }
+    }
+
     # 恢复库存
     public function resell($id)
     {
@@ -174,16 +285,16 @@ class Order
             if ($k == 1) {
                 $v['name'] .= ' 下单人:' . $user['name'] . '('.$user['mobile'].')' . ' 付款:' . $page->info['cash'] . '元 '. $desc;
             } elseif ($k == 2) {
-                $v['name'] .= ' 收货地址:' . $address['name'] . ',' . $address['phone'] . ',' . $address['area_string'] . ',' . $address['address'];
+                $v['name'] .= ' 收货地址:' . $address['full'];
             } elseif ($k == 3) {
-                $express = Dever::db('order_express', 'goods')->find(array('order_id' => $page->info['id']));
-                if ($express) {
-                    $express_info = Dever::db('express', 'sector')->find($express['express_id']);
-                    $v['name'] .= ' 已发货:' . $express_info['name'] . ',' . $express['number'];
+                if (isset($page->info['express'])) {
+                    $v['name'] .= ' 已发货:' . $page->info['express']['name'] . ',' . $page->info['express']['number'];
                 }
-                
-            }
-            if ($k == 5 && $page->info['status'] > 6) {
+            } elseif ($k == 4) {
+                if (isset($page->info['express']['log'])) {
+                    $v['name'] .= ' ' . $page->info['express']['log'][0]['status'];
+                }
+            } elseif ($k == 5 && $page->info['status'] > 6) {
                 $v['name'] .= ' 订单'.$status.'';
             }
             if ($v['selected']) {
@@ -194,15 +305,6 @@ class Order
             }
             $timeline[] = $v;
         }
-        $content = array
-        (
-            array
-            (
-                'name' => '订单进度',
-                'type' => 'timeline',
-                'content' => $timeline,
-            ),
-        );
 
         $button = array();
 
@@ -249,8 +351,76 @@ class Order
                 ),
             );
         }
+        if (!$page->info['refund'] && $page->info['status'] >= 2 && $page->info['status'] < 7) {
+            $button[] = array
+            (
+                'name' => '退款',
+                'type' => 'fastadd',
+                'path' => 'sector_place_order/goods_order_refund',
+                'row' => array
+                (
+                    'id' => $page->info['id'],
+                ),
+                'param' => array
+                (
+                    'order_id' => $page->info['id'],
+                ),
+            );
+        }
+        $desc = '';
+        if ($page->info['refund']) {
+            $desc = '[退款中]';
+            $refund = array();
+            foreach ($page->info['refund_status_list'] as $k => $v) {
+                $v['name'] = '['.$v['name'].']';
+                if ($k == 1) {
+                    $v['name'] .= ' 申请原因:' . Dever::db('order_refund', 'goods')->value('desc_type', $page->info['refund']['desc_type']) . ' 申请说明:' . $page->info['refund']['desc'];
+                } elseif ($k == 2) {
+                    $v['name'] .= ' 审核备注:' . $page->info['refund']['audit_desc'];
+                } elseif ($k == 3) {
+                    if (isset($page->info['refund']['express'])) {
+                        $v['name'] .= ' 已发货:' . $page->info['refund']['express']['name'] . ',' . $page->info['refund']['express']['number'];
+                    }
+                }
+                if ($v['selected']) {
+                    $v['hollow'] = true;
+                    $v['color'] = 'red';
+                    $v['type'] = 'primary';
+                    $v['size'] = 'large';
+                }
+                $refund[] = $v;
+            }
+            $content[] = array
+            (
+                'name' => '退款进度',
+                'type' => 'timeline',
+                'content' => $refund,
+            );
+            $button = array();
+            if ($page->info['refund']['status'] == 1) {
+                $button[] = array
+                (
+                    'name' => '退款审核',
+                    'type' => 'fastedit',
+                    'path' => 'sector_place_order/goods_order_refund_audit',
+                    'row' => array
+                    (
+                        'id' => $page->info['refund']['id'],
+                    ),
+                    'param' => array
+                    (
+                        'order_id' => $page->info['id'],
+                    ),
+                );
+            }
+        }
 
-        
+        $content[] = array
+        (
+            'name' => '订单进度' . $desc,
+            'type' => 'timeline',
+            'content' => $timeline,
+        );
 
         $info[] = array
         (
@@ -270,30 +440,25 @@ class Order
         );
 
         $detail = Dever::db('order_detail', 'goods')->select(array('order_id' => $page->info['id']));
-        foreach ($detail as &$v) {
-            
+        if ($detail) {
+            foreach ($detail as &$v) {
+                $v['status'] = '正常';
+            }
         }
 
-        $detail_button = array();
-        if ($page->info['status'] >= 2 && $page->info['status'] <= 6) {
-            $detail_button[] = array
-            (
-                'name' => '退款',
-                'type' => 'fastedit',
-                'load' => 'platform/role',
-            );
-        }
+        $log = Dever::load('log', 'goods')->getList($page->info['id']);
+        
         $tab = array
         (
-            'active' => 'tab2',
+            'active' => 't1',
             'content' => array
             (
-                'tab2' => array
+                't1' => array
                 (
                     'name' => '商品清单',
                     'type' => 'table',
                     'border' => true,
-                    'height' => '200',
+                    #'height' => '200',
                     'head' => array
                     (
                         array
@@ -320,18 +485,58 @@ class Order
                             'name' => '数量',
                             'fixed' => 'fixed',
                         ),
+                        array
+                        (
+                            'key' => 'status',
+                            'name' => '状态',
+                            'fixed' => 'fixed',
+                        ),
                     ),
-                    'button' => $detail_button,
+                    'button' => array(),
                     'body' => $detail,
                 ),
 
-                'table1' => array
+                't2' => array
                 (
-                    # 这里跟desc一样
                     'name' => '操作记录',
-                    'type' => 'text',
-                    'content' => '内容',
-                    'style' => 'primary',
+                    'type' => 'table',
+                    'border' => true,
+                    #'height' => '200',
+                    'head' => array
+                    (
+                        array
+                        (
+                            'key' => 'type',
+                            'name' => '身份',
+                            'fixed' => 'fixed',
+                        ),
+                        array
+                        (
+                            'key' => 'name',
+                            'name' => '名称',
+                            'fixed' => 'fixed',
+                        ),
+                        array
+                        (
+                            'key' => 'mobile',
+                            'name' => '联系电话',
+                            'fixed' => 'fixed',
+                        ),
+                        array
+                        (
+                            'key' => 'desc',
+                            'name' => '详情',
+                            'fixed' => 'fixed',
+                        ),
+                        array
+                        (
+                            'key' => 'cdate_str',
+                            'name' => '时间',
+                            'fixed' => 'fixed',
+                        ),
+                    ),
+                    'button' => array(),
+                    'body' => $log,
                 ),
             )
         );

+ 184 - 0
src/resource/goods/lib/Refund.php

@@ -0,0 +1,184 @@
+<?php namespace Goods\Lib;
+use Dever;
+use Place;
+class Refund
+{
+    # 后台提交
+    public function update($db, $data)
+    {
+        $detail = Dever::input('goods/order_refund_detail');
+        $order = Dever::db('order', 'goods')->find($data['order_id']);
+        if ($order && $order['type'] == 1 && $order['status'] <= 4) {
+            $auth = new \Manage\Lib\Auth();
+            $uid = $auth->uid;
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            $this->up($detail, $order, $data['type'], $data['desc_type'], $data['cash'], $data['desc'], $log);
+        }
+        return 'end';
+    }
+
+    # 后台审核
+    public function audit($db, $data)
+    {
+        $refund = Dever::db('order_refund', 'goods')->find($data['id']);
+        if ($refund['status'] == 1) {
+            if ($data['audit'] == 1) {
+                $refund['status'] = $update['status'] = 2;
+                $update['sdate'] = time();
+            } else {
+                $update['status'] = 5;
+                $update['sdate'] = time();
+                $update['fdate'] = time();
+            }
+            $update['audit_desc'] = $data['audit_desc'];
+            Dever::db('order_refund', 'goods')->update($data['id'], $update);
+            $auth = new \Manage\Lib\Auth();
+            $msg = '退款:' . $update['audit_desc'];
+            Dever::load('log', 'goods')->up(2, $auth->uid, $refund['order_id'], $msg);
+            if ($refund['type'] == 2 && $refund['status'] == 2) {
+                # 仅退款
+                $order = Dever::db('order', 'goods')->find($refund['order_id']);
+                $this->finish($order, $refund);
+            }
+        }
+        return 'end';
+    }
+
+    # 买家发货
+    public function express($order, $refund, $express_id, $number)
+    {
+        $refund = Dever::db('order_refund', 'goods')->find($refund['id']);
+        if ($refund['status'] == 2) {
+            $update['status'] = 3;
+            $update['ddate'] = time();
+            $where = array('order_refund_id' => $refund['id']);
+            $info = Dever::db('order_refund_express', 'goods')->find($where);
+            if (!$info) {
+                $where['order_id'] = $order['id'];
+                $where['express_id'] = $express_id;
+                $where['number'] = $number;
+                Dever::db('order_refund_express', 'goods')->insert($where);
+                Dever::load('log', 'goods')->up(1, $order['uid'], $order['id'], '退款:买家已发货');
+            }
+            Dever::db('order_refund', 'goods')->update($refund['id'], $update);
+        }
+    }
+
+    # 完成退款 如果是支付订单,原路退回
+    public function finish($order, $refund)
+    {
+        $refund = Dever::db('order_refund', 'goods')->find($refund['id']);
+        if ($refund['status'] == 2 || $refund['status'] == 3) {
+            $update['status'] = 4;
+            $update['fdate'] = time();
+            $update['refund_status'] = 1;
+            Dever::db('order_refund', 'goods')->update($refund['id'], $update);
+            Dever::load('log', 'goods')->up(1, $order['uid'], $order['id'], '退款:已完成退款');
+
+            # 检测订单是否全都退了
+            $refund = Dever::db('order_refund', 'goods')->select(array('order_id' => $order['id']));
+            $cash = 0;
+            foreach ($refund as $k => $v) {
+                $cash += $v['cash'];
+            }
+
+            if ($cash >= $order['cash']) {
+                $refund = Dever::db('order', 'goods')->update($order['id'], array('status' => 8, 'fdate' => time(), 'refund_status' => 2));
+
+                Dever::load('log', 'goods')->up(1, $order['uid'], $order['id'], '订单已退款');
+                # 恢复库存
+                Dever::load('order', 'goods')->resell($order['id']);
+            }
+
+            # 判断是否支付订单,如果是,走退款流程
+            if ($order['type'] == 1) {
+
+            }
+        }
+    }
+
+    public function up($detail, $order, $type, $desc_type, $cash, $desc, $log = false)
+    {
+        if ($detail) {
+            foreach ($detail as $k => $v) {
+                $info = Dever::db('order_detail', 'goods')->find($v['detail_id']);
+                $refund = Dever::db('order_refund_detail', 'goods')->find(array('detail_id' => $v['detail_id'], 'refund_status' => 1), array('col' => 'sum(num) as num'));
+                if ($refund && $refund['num']) {
+                    $info['num'] -= $refund['num'];
+                }
+                if ($v['num'] > $info['num']) {
+                    Dever::error('退款数量不能大于下单商品数量');
+                }
+            }
+        }
+        $where = array('order_id' => $order['id'], 'refund_status' => 1);
+        $refund = Dever::db('order_refund', 'goods')->find($where, array('col' => 'sum(cash) as cash'));
+        if ($refund && $refund['cash']) {
+            $order['cash'] -= $refund['cash'];
+        }
+        if ($cash > $order['cash']) {
+            Dever::error('退款金额不能大于订单金额');
+        }
+        $update = $where;
+        $update['refund_status'] = 2;
+        $update['status'] = array('<', '5');
+        $refund = Dever::db('order_refund', 'goods')->find($update);
+        $update['type'] = $type;
+        $update['desc_type'] = $desc_type;
+        $update['cash'] = $cash;
+        $update['desc'] = $desc;
+        $update['status'] = 1;
+        if ($refund) {
+            Dever::error('您有退款进行中,请先处理');
+        } else {
+            $id = Dever::db('order_refund', 'goods')->insert($update);
+            if ($id) {
+                Dever::db('order', 'goods')->update($order['id'], array('refund_status' => 1));
+                if ($detail) {
+                    foreach ($detail as $k => $v) {
+                        $v['order_refund_id'] = $id;
+                        Dever::db('order_refund_detail', 'goods')->insert($v);
+                    }
+                }
+                if ($log) {
+                    $type = $log['type'];
+                    $uid = $log['uid'];
+                    $msg = '退款:提交退款申请单';
+                    Dever::load('log', 'goods')->up($type, $uid, $order['id'], $msg);
+                }
+            }
+        }
+    }
+
+    # 获取信息
+    public function getList($order_id)
+    {
+        $log = Dever::db('order_log', 'goods')->select(array('order_id' => $order_id));
+        if ($log) {
+            foreach ($log as &$v) {
+                $v = $this->getInfo($v);
+            }
+        }
+        return $log;
+    }
+
+    # 获取信息
+    public function getInfo($info)
+    {
+        if ($info['type'] == 1) {
+            $user = Dever::db('member', 'place')->find($info['type_id']);
+        } elseif ($info['type'] == 2) {
+            $user = Dever::db('user', 'sector')->find($info['type_id']);
+        } elseif ($info['type'] == 3) {
+            $user = Dever::db('supplier', 'place')->find($info['type_id']);
+        } else {
+            $user['name'] = $user['mobile'] = '-';
+        }
+        $info['type'] = Dever::db('order_log', 'goods')->value('type', $info);
+        $info['name'] = $user['name'];
+        $info['mobile'] = $user['mobile'];
+        $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
+        return $info;
+    }
+}

+ 18 - 0
src/resource/goods/manage/core.php

@@ -69,5 +69,23 @@ return array
             'sort'      => '10',
             'show'      => 3,
         ),
+
+        'goods_order_refund' => array
+        (
+            'parent'    => 'sector_place_order',
+            'name'      => '订单退款',
+            'icon'      => 'product-hunt-line',
+            'sort'      => '10',
+            'show'      => 3,
+        ),
+
+        'goods_order_refund_audit' => array
+        (
+            'parent'    => 'sector_place_order',
+            'name'      => '订单退款审核',
+            'icon'      => 'product-hunt-line',
+            'sort'      => '10',
+            'show'      => 3,
+        ),
     ),
 );

+ 2 - 0
src/resource/goods/manage/goods_order.php

@@ -16,6 +16,7 @@ $config = array
             'cash',
             'num',
             'status',
+            'refund_status',
             'cdate',
         ),
         'button' => array
@@ -51,6 +52,7 @@ $config = array
                 'range_separator' => '至',
             ),
             'status',
+            'refund_status',
         ),
     ),
     # 详情页配置

+ 1 - 1
src/resource/goods/manage/goods_order_express.php

@@ -1,5 +1,5 @@
 <?php
-$id = Dever::input('id');
+$id = Dever::input('field')['order_id'];
 $config = array
 (
     'source' => 'goods/order_express',

+ 44 - 0
src/resource/goods/manage/goods_order_refund.php

@@ -0,0 +1,44 @@
+<?php
+$id = Dever::input('field')['order_id'];
+$config = array
+(
+    'source' => 'goods/order_refund',
+    'update' => array
+    (
+        'start' => 'goods/refund.update',
+        'field'    => array
+        (
+            'order_id' => array
+            (
+                'value' => $id,
+                'type' => 'hidden',
+            ),
+            'type' => array
+            (
+                'rules' => true,
+                'type' => 'radio',
+            ),
+            'cash' => array
+            (
+                'rules' => true,
+            ),
+            'goods/order_refund_detail' => array
+            (
+                'name' => '退款明细',
+                'where'  => array('order_refund_id' => 'id'),
+            ),
+            'desc_type' => array
+            (
+                'rules' => true,
+            ),
+            'desc' => array
+            (
+                'rules' => true,
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+            ),
+        ),
+    ),
+);
+
+return $config;

+ 33 - 0
src/resource/goods/manage/goods_order_refund_audit.php

@@ -0,0 +1,33 @@
+<?php
+$config = array
+(
+    'source' => 'goods/order_refund',
+    'update' => array
+    (
+        'start' => 'goods/refund.audit',
+        'field'    => array
+        (
+            'audit' => array
+            (
+                'name' => '退款审核',
+                'rules' => true,
+                'type' => 'radio',
+                'option' => array
+                (
+                    1 => '审核通过',
+                    2 => '审核驳回',
+                ),
+                'default' => 1,
+            ),
+            'audit_desc' => array
+            (
+                'name' => '审核备注',
+                //'rules' => true,
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 2),
+            ),
+        ),
+    ),
+);
+
+return $config;

+ 23 - 0
src/resource/goods/manage/order_refund_detail.php

@@ -0,0 +1,23 @@
+<?php
+$id = Dever::input('field')['order_id'];
+$detail = Dever::db('order_detail', 'goods')->select(array('order_id' => $id, 'status' => 1), array('col' => 'concat(name,"-",sku_name) as name, id'));
+return array
+(
+    'source' => 'goods/order_refund_detail',
+    'update' => array
+    (
+        'field'    => array
+        (
+            'detail_id' => array
+            (
+                'type' => 'select',
+                'clearable' => true,
+                'option' => $detail,
+            ),
+            'num' => array
+            (
+                
+            ),
+        ),
+    ),
+);

+ 24 - 0
src/resource/goods/table/order.php

@@ -53,6 +53,30 @@ return array
             'name'      => '订单备注',
         ),
 
+        'type'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '订单类型',
+            'default'   => '1',
+            'value'         => array
+            (
+                1 => '源代宝订单',
+                2 => '第三方订单',
+            ),
+        ),
+
+        'refund_status'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '退款申请状态',
+            'default'   => '2',
+            'value'         => array
+            (
+                1 => '退款申请中',
+                2 => '无退款申请',
+            ),
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint(1)',

+ 13 - 0
src/resource/goods/table/order_detail.php

@@ -52,5 +52,18 @@ return array
             'type'      => 'decimal(11,2)',
             'name'      => '明细数量',
         ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '明细状态',
+            'default'   => '1',
+            'value'         => array
+            (
+                1 => '正常',
+                2 => '部分退款',
+                3 => '已全部退款',
+            ),
+        ),
     ),
 );

+ 2 - 1
src/resource/goods/table/order_log.php

@@ -18,6 +18,7 @@ return array
             'default'   => 1,
             'value'     => array
             (
+                -1 => '系统',
                 1 => '买家',
                 2 => '卖家',
                 3 => '渠道',
@@ -32,7 +33,7 @@ return array
 
         'desc'      => array
         (
-            'type'      => 'varchar(100)',
+            'type'      => 'varchar(1000)',
             'name'      => '操作明细',
         ),
     ),

+ 82 - 13
src/resource/goods/table/order_refund.php

@@ -5,34 +5,103 @@ return array
     'partition' => 'Dever::call("manage/common.system")',
     'struct' => array
     (
-        'info_id' => array
+        'order_id'       => array
         (
-            'name'      => '商品ID',
             'type'      => 'int(11)',
+            'name'      => '订单ID',
         ),
 
-        'order_id'       => array
+        'cash'      => array
         (
-            'type'      => 'int(11)',
-            'name'      => '订单ID',
+            'type'      => 'decimal(11,2)',
+            'name'      => '退款金额',
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar(200)',
+            'name'      => '申请说明',
+        ),
+
+        'audit_desc'      => array
+        (
+            'type'      => 'varchar(200)',
+            'name'      => '审核备注',
+        ),
+
+        'type' => array
+        (
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '退货退款',
+                2 => '仅退款',
+            ),
+        ),
+
+        'desc_type' => array
+        (
+            'name'      => '申请原因',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '不想要了',
+                2 => '不喜欢、效果不好',
+                3 => '货物与描述不符',
+                4 => '收到商品少件',
+                5 => '商品破损或污渍',
+                6 => '发错货',
+                7 => '假冒品牌',
+                8 => '其他原因',
+            ),
+        ),
+
+        'refund_status' => array
+        (
+            'name'      => '退款状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '退款有效',
+                2 => '退款无效',
+            ),
+        ),
+
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '申请中',
+                2 => '已审核',
+                3 => '已退货',
+                4 => '已退款',
+                5 => '已驳回',
+            ),
         ),
 
-        'detail_id'       => array
+        'sdate'       => array
         (
             'type'      => 'int(11)',
-            'name'      => '明细ID',
+            'name'      => '审核时间',
         ),
 
-        'cash'      => array
+        'ddate'       => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '退款金额',
+            'type'      => 'int(11)',
+            'name'      => '发货时间',
         ),
 
-        'num'      => array
+        'fdate'       => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '退款数量',
+            'type'      => 'int(11)',
+            'name'      => '完成时间',
         ),
     ),
 );

+ 38 - 0
src/resource/goods/table/order_refund_detail.php

@@ -0,0 +1,38 @@
+<?php
+return array
+(
+    'name' => '商品退款单明细表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'order_refund_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '订单ID',
+        ),
+
+        'detail_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '商品',
+        ),
+
+        'num'      => array
+        (
+            'type'      => 'decimal(11,2)',
+            'name'      => '退款数量',
+        ),
+
+        'refund_status' => array
+        (
+            'name'      => '退款状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '退款有效',
+                2 => '退款无效',
+            ),
+        ),
+    ),
+);

+ 33 - 0
src/resource/goods/table/order_refund_express.php

@@ -0,0 +1,33 @@
+<?php
+return array
+(
+    'name' => '商品订单退货物流配送表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'order_refund_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '退款ID',
+        ),
+
+        'order_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '订单ID',
+        ),
+
+        'express_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '快递公司',
+            'value'     => 'sector/express',
+        ),
+
+        'number'      => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '快递单号',
+        ),
+    ),
+);

+ 45 - 0
src/sector/table/express_log.php

@@ -0,0 +1,45 @@
+<?php
+return array
+(
+    'name' => '快递物流记录表',
+    'store' => 'log',
+    'struct' => array
+    (
+        'express_id' => array
+        (
+            'name'      => '快递ID',
+            'type'      => 'int(11)',
+        ),
+        'mobile' => array
+        (
+            'name'      => '手机号',
+            'type'      => 'varchar(15)',
+        ),
+        'number' => array
+        (
+            'name'      => '快递单号',
+            'type'      => 'varchar(150)',
+        ),
+        'content' => array
+        (
+            'name'      => '快递内容',
+            'type'      => 'text(255)',
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => array
+            (
+                1 => '已签收',
+                2 => '未签收',
+            ),
+        ),
+        'udate' => array
+        (
+            'name'      => '更新时间',
+            'type'      => 'int(11)',
+        ),
+    ),
+);