quanwei
2025-12-10 898043fc97d2ab8b793fd317a049b874ed207c6d
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
 
namespace app\supplier\model\supplier;
 
use app\common\model\supplier\Supplier as SupplierModel;
/**
 * 后台管理员登录模型
 */
class Supplier extends SupplierModel
{
    /**
     *检查登录
     */
    public function checkLogin($params)
    {
        $where['user_name'] = $params['username'];
        $where['password'] = $params['password'];
        $where['is_delete'] = 0;
 
        if (!$supplier = $this->where($where)->with(['app'])->find()) {
            return false;
        }
        if (empty($supplier['app'])) {
            $this->error = '登录失败, 未找到应用信息';
            return false;
        }
        if ($supplier['app']['is_recycle']) {
            $this->error = '登录失败, 当前应用已删除';
            return false;
        }
        // 保存登录状态
        $this->loginState($supplier);
        return true;
    }
 
 
    /*
    * 修改密码
    */
    public function editPass($data, $user)
    {
        $user_info = User::detail($user['shop_user_id']);
        if ($data['password'] != $data['confirmPass']) {
            $this->error = '密码错误';
            return false;
        }
        if ($user_info['password'] != salt_hash($data['oldpass'])) {
            $this->error = '两次密码不相同';
            return false;
        }
        $date['password'] = salt_hash($data['password']);
        $user_info->save($date);
        return true;
    }
 
    /**
     * 保存登录状态
     */
    public function loginState($supplier)
    {
        $app = $supplier['app'];
        // 保存登录状态
        $session = array(
            'supplier' => [
                'shop_supplier_id' => $supplier['shop_supplier_id'],
                'user_name' => $supplier['user_name']
            ],
            'app' => $app->toArray(),
            'is_login' => true,
        );
        session('jjjshop_supplier', $session);
    }
 
    /**
     * 修改
     */
    public function edit($data){
        $isexist = $this->where('name','=',$data['name'])->where('shop_supplier_id','<>',$data['shop_supplier_id'])->find();
        if($isexist){
            $this->error = '店铺名称已存在';
            return false;
        }
        return $this->save([
            'link_name' => $data['link_name'],
            'link_phone' => $data['link_phone'],
            'address' => $data['address'],
            'description' => $data['description'],
            'logo_id' => $data['logo_id'],
            'business_id' => $data['business_id'],
            'app_id' => self::$app_id,
            'name' => $data['name'],
            'is_full' => 1,
            'notice' => $data['notice']
        ]);
    }
 
    /**
     * 资金冻结
     */
    public function freezeMoney($money)
    {
        return $this->save([
            'money' => $this['money'] - $money,
            'freeze_money' => $this['freeze_money'] + $money,
        ]);
    }
 
    /**
     * 获取列表数据
     */
    public function getList($params)
    {
        $model = $this;
        if (isset($params['search']) && $params['search']) {
            $model = $model->where('name', 'like', '%' . $params['search'] . '%');
        }
        if(isset($params['shop_supplier_ids'])&&$params['shop_supplier_ids']){
            $model = $model->where('shop_supplier_id', 'in', $params['shop_supplier_ids']);
        }
        if(isset($params['is_takeout']) && $params['is_takeout'] > -1){
            $model = $model->where('is_takeout', '=', $params['is_takeout']);
        }
        // 查询列表数据
        return $model->with(['logo', 'superUser', 'business', 'qyQrcode'])
            ->where('is_delete', '=', '0')
            ->order(['create_time' => 'desc'])
            ->paginate($params);
    }
}