quanwei
2025-10-31 f226d5fe6327e31bb471a96b7370cf94689c6608
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
<?php
 
namespace app\agent\model\plus\coupon;
 
use app\common\model\plus\coupon\Coupon as CouponModel;
 
/**
 * 优惠券模型
 */
class Coupon extends CouponModel
{
    /**
     * 获取优惠券列表getList
     */
    public function getList($data)
    {
        $model = $this;
        if (isset($data['shop_supplier_id'])) {
            $model = $model->where('coupon.shop_supplier_id', '=', $data['shop_supplier_id']);
        }
        return $model->alias('coupon')->field(['coupon.*,supplier.name as supplier_name'])
            ->join('supplier', 'coupon.shop_supplier_id = supplier.shop_supplier_id', 'left')
            ->where('coupon.is_delete', '=', 0)
            ->order(['coupon.sort' => 'asc', 'coupon.create_time' => 'desc'])
            ->paginate($data);
    }
 
    /**
     * 添加新记录
     */
    public function add($data)
    {
        $data['agent_id'] = self::$agent_id;
        $data['shop_supplier_id'] = 0;
        if ($data['expire_type'] == '20') {
            $data['start_time'] = strtotime($data['active_time'][0]);
            $data['end_time'] = strtotime($data['active_time'][1]);
        }
        return self::create($data);
    }
 
    /**
     * 更新记录
     */
    public function edit($data)
    {
        if ($data['expire_type'] == '20') {
            $data['start_time'] = strtotime($data['active_time'][0]);
            $data['end_time'] = strtotime($data['active_time'][1]);
        }
        $where['coupon_id'] = $data['coupon_id'];
        unset($data['coupon_id']);
        return self::update($data, $where);
    }
 
    /**
     * 删除记录 (软删除)
     */
    public function setDelete($where)
    {
        return self::update(['is_delete' => 1], $where);
    }
 
    /**
     * 查询指定优惠券
     * @param $value
     */
    public function getCoupon($value)
    {
        return $this->where('coupon_id', 'in', $value)->select();
    }
 
    /**
     * 查询指定优惠券
     * @param $value
     */
    public function getCoupons($value)
    {
        $data = $this->where('coupon_id', 'in', $value)->select();
        $name = '';
        if (!empty($data)) {
            foreach ($data as $val) {
                $name .= $val['name'] . ',';
            }
        }
 
        return $name;
    }
}