quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
 
namespace app\supplier\controller\setting;
 
use app\supplier\controller\Controller;
use app\supplier\model\settings\Stall as StallModel;
use app\common\enum\settings\StallTypeEnum;
use app\common\model\settings\Printer as PrinterModel;
 
/**
 * 打印档口控制器
 */
class Stall extends Controller
{
    /**
     * 档口列表
     */
    public function index()
    {
        $model = new StallModel;
        if (StallModel::checkDefault($this->getSupplierId())) {
            $list = $model->getList($this->postData(), $this->getSupplierId());
        }
        return $this->renderSuccess('', compact('list'));
    }
 
 
    /**
     * 档口类型
     */
    public function type()
    {
        $model = new StallModel;
        $stallType = $model::getStallTypeList();
        return $this->renderSuccess('', compact('stallType'));
    }
 
 
    /**
     * 添加打印机
     */
    public function add($stall_type)
    {
        if($this->request->isGet()){
            $type_info = StallTypeEnum::data()[$stall_type];
            // 档口名称
            $stallTypeName = $type_info['name'];
            // 打印机列表
            $printerList = PrinterModel::getAll($this->getSupplierId(), $type_info['printer_type']);
            return $this->renderSuccess('', compact('printerList', 'stallTypeName'));
        }
        // 新增记录
        $model = new StallModel;
        $data = $this->postData();
        $data['shop_supplier_id'] = $this->getSupplierId();
        if ($model->add($data)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     * 打印机详情
     */
    public function detail($stall_id)
    {
        $detail = StallModel::detail($stall_id);
        return $this->renderSuccess('', compact('detail'));
 
    }
 
    public function edit($stall_id)
    {
        if($this->request->isGet()){
            $detail = StallModel::detail($stall_id);
            $type_info = StallTypeEnum::data()[$detail['stall_type']];
            // 档口名称
            $stallTypeName = $type_info['name'];
            // 打印机列表
            $printerList = PrinterModel::getAll($this->getSupplierId(), $type_info['printer_type']);
            return $this->renderSuccess('', compact('printerList', 'stallTypeName', 'detail'));
        }
        $model = StallModel::detail($stall_id);
        // 更新记录
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 删除记录
     */
    public function delete($stall_id)
    {
        $model = StallModel::detail($stall_id);
        if ($model->setDelete()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?:'删除失败');
    }
 
    public function getAllList()
    {
        $list = (new StallModel)->getAll($this->getSupplierId(), true);
        return $this->renderSuccess('', compact('list'));
    }
 
}