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
93
94
95
96
97
<?php
 
namespace app\operations\controller\store;
 
use app\operations\controller\Controller;
use app\operations\model\store\Clerk as ClerkModel;
use app\operations\model\store\Store as StoreModel;
use app\operations\model\supplier\Supplier as SupplierModel;
 
/**
 * 店员控制器
 */
class Clerk extends Controller
{
 
    /**
     * 店员列表
     */
    public function index($store_id = 0, $search = '')
    {
        //获取该角色管理的区域 by yj 2023.12.20
        $shop_supplier_ids = SupplierModel::getSupplierIdsByUser($this->store['user']);
        // 店员列表
        $model = new ClerkModel;
        $data = $this->postData();
        $postData = [];
        if(!empty($shop_supplier_ids)){
            $data["shop_supplier_ids"] = $shop_supplier_ids;
            $postData["shop_supplier_ids"] = $shop_supplier_ids;
        }
        $list = $model->getList(-1, $store_id, $search, $data);
        // 门店列表
        $store_list = (new StoreModel)->getList($postData);
 
        return $this->renderSuccess('', compact('list', 'store_list'));
    }
 
    /**
     * 添加店员
     */
    public function add()
    {
        $model = new ClerkModel;
        //传过来的信息
        $data = $this->postData();
 
        $list = $model->getAll()->toArray();
        $list_user_id = array_column($list, 'user_id');
        if (in_array($data['user_id'], $list_user_id)) {
            return $this->renderError('', '该用户已经是店员,无需重复添加');
        }
        // 新增记录
        if ($model->add($data)) {
            return $this->renderSuccess('', '添加成功');
        }
        return $this->renderError('', $model->getError() ?: '添加失败');
    }
 
    public function detail($clerk_id)
    {
        $detail = ClerkModel::detail($clerk_id);
        // 门店列表
        $store_list = StoreModel::getAllList();
        return $this->renderSuccess('', compact('detail', 'store_list'));
    }
 
    /**
     * 编辑店员
     */
    public function edit($clerk_id)
    {
        if($this->request->isGet()){
            return $this->detail($clerk_id);
        }
        $model = ClerkModel::detail($clerk_id);
        //编辑店员的数据
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('', '更新成功');
        }
        return $this->renderError('', $model->getError() ?: '更新失败');
 
    }
 
    /**
     * 删除店员
     */
    public function delete($clerk_id)
    {
        // 店员详情
        $model = ClerkModel::detail($clerk_id);
        if (!$model->setDelete()) {
            return $this->renderError('', '删除失败');
        }
        return $this->renderSuccess('', $model->getError() ?: '删除成功');
    }
 
}