dever 3 years ago
parent
commit
74472ac8bd

+ 102 - 32
app/mshop/lib/Buy.php

@@ -117,11 +117,15 @@ class Buy
         $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
         $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
 
+        $info['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => -1));
+
         $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
         if ($view) {
             foreach ($info['goods'] as $k => $v) {
                 $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
                 $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
+
+                $info['goods'][$k]['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
             }
         } else {
             foreach ($info['goods'] as $k => $v) {
@@ -129,6 +133,8 @@ class Buy
                 $info['goods'][$k]['name'] = $goods['name'];
                 $info['goods'][$k]['cover'] = $goods['cover'];
                 $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
+
+                $info['goods'][$k]['tui'] = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
             }
         }
 
@@ -230,7 +236,7 @@ class Buy
     # 再次发起支付
     public function raction($id, $refer = '')
     {
-        $order = Dever::db('goods/buy_order')->find($id);
+        $order = Dever::db('shop/buy_order')->find($id);
 
         if (!$order) {
             Dever::alert('订单信息错误');
@@ -335,6 +341,42 @@ class Buy
         }
     }
 
+    # 同意退款
+    public function tui_yes_api()
+    {
+        $id = Dever::input('id');
+        $process = Dever::input('process', 3);
+        $info = Dever::db('shop/buy_order_tui')->find($id);
+
+        if ($info && $info['process'] == 1) {
+            $update['process'] = $process;
+            $update['where_id'] = $info['id'];
+            $state = Dever::db('shop/buy_order_tui')->update($update);
+
+            if ($state && $process == 2) {
+                $data = $this->getView($info['shop_id'], $info['order_id'], false);
+                if ($data) {
+                    if ($info['order_goods_id'] > 0) {
+                        $state = Dever::db('shop/buy_order_goods')->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
+                        $this->pay_tui($state, $data, $info['cash']);
+
+                        # 检查这个订单下的商品是不是都退了
+                        $total = Dever::db('shop/buy_order_goods')->total(array('order_id' => $info['order_id'], 'shop_id' => $id, 'status' => 1));
+                        if ($total <= 0) {
+                            $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
+                        }
+                    } else {
+                        # 全部退款
+                        $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
+                        $this->pay_tui($state, $data, $info['cash']);
+                    }
+                }
+            }
+        }
+
+        return 'ok';
+    }
+
     # 申请退款
     public function tui_action($shop_id, $order_id, $order_goods_id, $status, $price, $num = false, $desc = '', $pic = '')
     {
@@ -344,7 +386,7 @@ class Buy
         $info = Dever::db('shop/buy_order_tui')->find($data);
 
         $data['status'] = $status;
-        $data['price'] = $price;
+        $data['cash'] = $price;
         if ($num) {
             $data['num'] = $num;
         }
@@ -353,8 +395,10 @@ class Buy
         
         if ($info) {
             $data['where_id'] = $info['id'];
+            $data['process'] = 1;
             return Dever::db('shop/buy_order_tui')->update($data);
         } else {
+            
             return Dever::db('shop/buy_order_tui')->insert($data);
         }
     }
@@ -412,19 +456,6 @@ class Buy
                 }
 
                 $state = $this->tui_action($data['shop_id'], $data['id'], $order_goods_id, $status, $info['price'], $num, $desc, $pic);
-
-                /*
-                if ($state) {
-                    $this->pay_tui($state, $data, $info['price']);
-
-                    # 检查这个订单下的商品是不是都退了
-                    $total = Dever::db('shop/buy_order_goods')->total(array('order_id' => $data['id'], 'shop_id' => $id, 'status' => 1));
-                    if ($total <= 0) {
-                        $status += 3;
-                        $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $info['price'], 'tk_pic' => $pic));
-                    }
-                }
-                */
             } else {
                 Dever::alert('当前订单状态不允许退货退款');
             }
@@ -434,21 +465,25 @@ class Buy
         }
     }
 
-    # 退款通知
+    # 退款到原账户
     public function pay_tui($state, $data, $price)
     {
-        return;
-        if ($state) {
-            $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个工作日内返回原支付账户';
-            Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 1, 1, false, $msg_param);
-
-            # 退款到原支付账户 待处理
+
+    }
+
+    # 查看订单状态
+    public function orderStatus($id)
+    {
+        $config = Dever::db('shop/buy_order')->config;
+
+        $info = Dever::db('shop/buy_order')->one($id);
+        $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'process' => 1));
+        $status = $config['status'][$info['status']];
+
+        if ($tk) {
+            $status = '申请退款中';
         }
+        return $status;
     }
 
     # 展示订单详情
@@ -462,6 +497,12 @@ class Buy
 
         $shop = Dever::db('shop/info')->find($info['shop_id']);
 
+        $tk_status = Dever::db('shop/buy_order_tui')->config['status'];
+        $tk_process = Dever::db('shop/buy_order_tui')->config['process'];
+
+        $status = $config['status'][$info['status']];
+
+        $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => -1));
         
         $html = '[基本信息]:<table class="layui-table"><thead><tr><th style="width:20%">项目</th><th style="width:80%">详情</th></tr> </thead><tbody>';
 
@@ -477,10 +518,27 @@ class Buy
 
         </tr>';
 
-        $html .= '<tr>
-          <td>订单信息</td>
-          <td>'.$this->table(array('订单状态', '金额', '数量'), array(array($config['status'][$info['status']], $info['price'], $info['num']))).'</td>
-        </tr>';
+        $url = Dever::url('lib/buy.tui_yes', 'mshop');
+
+        if ($tk && $tk['process'] == 1) {
+            $status = '申请' . $tk_status[$tk['status']];
+            $process = $tk_process[$tk['process']];
+            $process = '';
+
+            if ($tk['process'] == 1) {
+                $process .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
+            }
+            $html .= '<tr>
+              <td>订单信息</td>
+              <td>'.$this->table(array('金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['num'], $status, $process))).'</td>
+            </tr>';
+        } else {
+            $html .= '<tr>
+              <td>订单信息</td>
+              <td>'.$this->table(array('金额', '数量', '订单状态'), array(array($info['price'], $info['num'], $status))).'</td>
+            </tr>';
+        }
+        
 
         # 增加仓库和工厂信息
 
@@ -488,18 +546,30 @@ class Buy
 
         $html .= '[商品清单]:';
 
-        $head = array('商品名称', '商品属性', '商品价格', '商品数量');
+        $head = array('名称', '属性', '价格', '数量', '状态');
 
         $body = array();
         $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
+        $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
         foreach ($goods as $k => $v) {
             $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
+            $status = $goods_status[$v['status']];
+            $tk = Dever::db('shop/buy_order_tui')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id']));
+            if ($tk && $tk['process'] == 1) {
+                $status = '申请' . $tk_status[$tk['status']];
+                //$status .= '&nbsp;&nbsp;[' . $tk_process[$tk['process']] . ']';
+
+                if ($tk['process'] == 1) {
+                    $status .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
+                }
+            }
             $body[$k] = array
             (
                 $goods_info['name'],
                 $v['price'],
                 $v['price'],
                 $v['num'],
+                $status,
             );
         }
         $html .= $this->table($head, $body);

+ 39 - 0
app/shop/assets/manage/html/buy_order_goods.html

@@ -0,0 +1,39 @@
+</form>
+<form class="layui-form form10" action="" target="f10" method="post">
+<iframe id="f10" name="f10" style="display:none;"></iframe>
+<div class="layui-form-item" id="show">
+    <table class="layui-table">
+      <thead>
+        <tr>
+          <th>昵称</th>
+          <th>加入时间</th>
+          <th>签名</th>
+        </tr> 
+      </thead>
+      <tbody>
+        <tr>
+          <td>贤心</td>
+          <td>2016-11-29</td>
+          <td>人生就像是一场修行</td>
+        </tr>
+        <tr>
+          <td>许闲心</td>
+          <td>2016-11-28</td>
+          <td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
+        </tr>
+      </tbody>
+    </table>
+</div>
+
+<script>
+function audit(id, process, url)
+{
+    var index = layer.confirm('确定进行此项操作吗?', function()
+    {
+        $.post(url, {id:id,process:process}, function(t)
+        {
+            location.reload();
+        })
+    })
+}
+</script>

+ 3 - 1
app/shop/database/buy_order.php

@@ -204,7 +204,7 @@ return array
             'match'     => 'is_numeric',
             'option'    => $status,
             'search'    => 'select',
-            'list'      => true,
+            'list'      => 'Dever::load("mshop/lib/buy.orderStatus", "{id}")',
         ),
 
         'state'     => array
@@ -271,6 +271,8 @@ return array
         'list_button' => array(
             //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin', '{status} == 2'),
             //'delete' => array('删除', '', '{status} == 1'),
+
+            'fast_list' => array('查看详情', '"buy_order_goods&project=shop&order_id={id}&page_type=1"'),
         ),
     ),
 

+ 2 - 0
app/shop/database/buy_order_goods.php

@@ -131,6 +131,8 @@ return array
 
     'manage' => array
     (
+        'insert' => false,
+        'delete' => false,
         'page_list_table' => 'buy_order_goods',
     ),
 

+ 24 - 1
app/shop/database/buy_order_tui.php

@@ -6,13 +6,22 @@ $status = array
     2 => '无货退款',
 );
 
+$process = array
+(
+    1 => '申请退款中',
+    2 => '审核通过',
+    3 => '审核驳回',
+);
+
 return array
 (
     # 表名
     'name' => 'buy_order_tui',
     # 显示给用户看的名称
-    'lang' => '订单退款申请表',
+    'lang' => '采购退款申请',
     'menu' => false,
+    'status' => $status,
+    'process' => $process,
     # 数据结构
     'struct' => array
     (
@@ -113,6 +122,20 @@ return array
             'option'    => $status,
             'search'    => 'select',
             'list'      => true,
+            //'edit'      => true,
+        ),
+
+        'process'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '审核进度',
+            'default'   => '1',
+            'desc'      => '审核进度',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $process,
+            'search'    => 'select',
+            'list'      => true,
             'edit'      => true,
         ),
 

+ 2 - 0
app/shop/database/sell_order_goods.php

@@ -198,6 +198,8 @@ return array
 
     'manage' => array
     (
+        'insert' => false,
+        'delete' => false,
         'page_list_table' => 'sell_order_goods',
     ),
 

+ 3 - 3
app/shop/lib/Sell.php

@@ -225,6 +225,9 @@ class Sell
         }
 
         $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
+        if ($info['address_id']) {
+            $info['address'] = Dever::db('passport/address')->find($info['address_id']);
+        }
         if ($this->view == 2) {
 
             foreach ($info['goods'] as $k => $v) {
@@ -236,9 +239,6 @@ class Sell
 
                 $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
             }
-            if ($info['address_id']) {
-                $info['address'] = Dever::db('passport/address')->find($info['address_id']);
-            }
 
             if ($info['invoice_id']) {
                 $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);

+ 5 - 0
app/shop/template/manage/buy_order_goods.php

@@ -0,0 +1,5 @@
+<?php
+
+$view
+->fetch('#show', 'mshop/lib/buy.show')
+->display();