quanwei
2025-12-25 a47b138c7455dee981af9b4fac431a16c0eee675
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
130
131
132
133
134
135
<?php
 
namespace app\supplier\model\store;
 
use app\common\model\store\Store as StoreModel;
use Lvht\GeoHash;
 
/**
 * 门店模型
 */
class Store extends StoreModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'app_id',
        'update_time',
    ];
    /**
     * 获取列表数据
     */
    public function getList($data = null, $shop_supplier_id, $status = '')
    {
        $model = $this;
        !empty($status) && $model = $model->where('status', '=', (int)$status);
        $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
        return $model->with(['logo'])->where('is_delete', '=', '0')
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->paginate($data);
    }
 
    /**
     * 获取所有门店列表
     */
    public static function getAllList($shop_supplier_id)
    {
        return (new self)->where('is_delete', '=', '0')
            ->where('shop_supplier_id','=',$shop_supplier_id)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
    }
 
    /**
     * 新增记录
     */
    public function add($data)
    {
        $data = $this->createData($data);
        return self::create($data);
    }
 
    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return $this->save($this->createData($data));
    }
 
    /**
     * 软删除
     */
    public function setDelete($where)
    {
        return self::update(['is_delete' => 1], $where);
    }
 
    /**
     * 创建数据
     */
    private function createData($data)
    {
        $data['app_id'] = self::$app_id;
        // 格式化坐标信息
        $coordinate = explode(',', $data['coordinate']);
        $data['latitude'] = $coordinate[0];
        $data['longitude'] = $coordinate[1];
 
        // 生成geohash
        $Geohash = new Geohash;
        $data['geohash'] = $Geohash->encode($data['longitude'], $data['latitude']);
        return $data;
    }
    /**
     * 提现打款成功:累积提现佣金
     */
    public static function totalMoney($store_id, $money)
    {
        $model = self::detail($store_id);
        return $model->save([
            'freeze_money' => $model['freeze_money'] - $money,
            'cash_money' => $model['cash_money'] + $money,
        ]);
    }
    /**
     * 提现驳回:解冻门店资金
     */
    public static function backFreezeMoney($store_id, $money)
    {
        $model = self::detail($store_id);
        return $model->save([
            'money' => $model['money'] + $money,
            'freeze_money' => $model['freeze_money'] - $money,
        ]);
    }
 
    /**
     * 根据门店id集获取门店列表
     */
    public function getListByIds($storeIds, $shop_supplier_id)
    {
        // 获取商品列表数据
        return $this->with(['logo'])
            ->where('shop_supplier_id', '=', $shop_supplier_id)
            ->where('is_delete', '=', '0')
            ->where('status', '=', '1')
            ->where('store_id', 'in', $storeIds)
            ->select();
    }
 
    /**
     * 获取支持核销门店列表数据
     */
    public function getCheckList($shop_supplier_id)
    {
        return $this->with(['logo'])->where('is_delete', '=', '0')
            ->where('shop_supplier_id', '=', $shop_supplier_id)
            ->where('is_check', '=', 1)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
    }
 
}