quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
 
namespace app\operations\controller\order;
 
use app\operations\controller\Controller;
use app\operations\model\order\Order as OrderModel;
use app\operations\model\order\OrderRefund as OrderRefundModel;
use app\operations\model\settings\ReturnAddress as ReturnAddressModel;
use app\operations\model\supplier\Supplier as SupplierModel;
 
/**
 * 售后管理
 */
class Refund extends Controller
{
    /**
     * 售后列表
     */
    public function index()
    {
        //获取该角色管理的区域 by yj 2023.12.20
        $shop_supplier_ids = SupplierModel::getSupplierIdsByUser($this->store['user']);
        $model = new OrderRefundModel;
        $params = $this->postData();
        if(!empty($shop_supplier_ids)){
            $params["shop_supplier_ids"] = $shop_supplier_ids;
        }
        //列表数据
        $list = $model->getList($params);
        //重要数字
        $num_arr = $model->groupCount($params);
        $arr = [];
        foreach ($num_arr as $key => $val) {
            $k = $val['status']['value'];
            $arr[$k] = $val;
        }
 
        return $this->renderSuccess('', compact('list', 'arr'));
    }
 
    /**
     * 售后单详情
     */
    public function detail($order_refund_id)
    {
        // 售后单详情
        $detail = OrderRefundModel::detail($order_refund_id);
        if (isset($detail['send_time']) && $detail['send_time'] > 0) {
            $detail['send_time'] = date('Y-m-d H:i:s', $detail['send_time']);
        }
        // 订单详情
        $order = OrderModel::detail($detail['order_id']);
        $detail['orderproduct']['max_refund_money'] = $detail['orderproduct']['total_pay_price'];
        if ($order['order_source'] == 70) {
            $detail['orderproduct']['total_pay_price'] = round($detail['orderproduct']['total_pay_price'] + $order['advance']['pay_price'], 2);
            if ($order['advance']['money_return'] == 1) {
                $detail['orderproduct']['max_refund_money'] = round($detail['orderproduct']['max_refund_money'] + $order['advance']['pay_price'], 2);
            }
        }
        // 退货地址
        $address = (new ReturnAddressModel)->getAll($detail['shop_supplier_id']);
        return $this->renderSuccess('', compact('detail', 'order', 'address'));
    }
 
    /**
     * 商家审核
     */
    public function audit($order_refund_id)
    {
        $model = OrderRefundModel::detail($order_refund_id);
        if ($model->audit($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 确认收货并退款
     */
    public function receipt($order_refund_id)
    {
        if (!$this->request->isPost()) {
            return false;
        }
        $model = OrderRefundModel::detail($order_refund_id);
        if ($model->receipt($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
}