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
<?php
 
namespace app\operations\model\user;
 
use app\common\model\user\CardRecord as CardRecordModel;
 
/**
 * 会员卡记录模型
 */
class CardRecord extends CardRecordModel
{
    /**
     * 获取列表记录
     */
    public function getList($data)
    {
        $model = $this;
        if ($data['search']) {
            $model = $model->where('card_name|nickName', 'like', '%' . $data['search'] . '%');
        }
        if ($data['status'] >= 0) {
            if ($data['status'] == 0) {
                $model = $model->where('expire_time', '<', time());
            } else {
                $model = $model->where('expire_time', '>=', time());
            }
 
        }
        $list = $model->alias('r')
            ->where('pay_status', '=', 20)
            ->where('r.is_delete', '=', 0)
            ->with(['card', 'user'])
            ->join('user u', 'u.user_id=r.user_id')
            ->join('user_card c', 'c.card_id=r.card_id')
            ->field('r.*')
            ->order(['r.create_time' => 'desc'])
            ->paginate($data);
        return $list;
    }
 
    /**
     * 延期
     */
    public function delay($data)
    {
        $isExist = self::checkExistByUserId($this['user_id'], $data['order_id']);
        if ($isExist) {
            $this->error = "该会员已存在会员卡,请勿延期";
            return false;
        }
        $update['expire_time'] = strtotime($data['expire_time']);
        if ($update['expire_time'] < $this['expire_time']) {
            $this->error = "延期日期不能小于当前有效期";
            return false;
        }
        return $this->save($update);
    }
 
    /**
     * 获取微信购买卡的金额
     */
    public function getTotalPayByDate($day,$user_ids=[],$in='true')
    {
        $start = strtotime($day);
        $end = strtotime($day) + 86399;
        $model = $this;
        if(!empty($user_ids)){
            if($in){
                $model = $model->where('user_id', 'in', $user_ids);
            }else{
                $model = $model->where('user_id', 'not in', $user_ids);
            }
        }
        $money = $model->where('create_time', 'between', "$start,$end")
            ->where('pay_status', '=', 20)
            ->where('pay_type', '=', 20)
            ->sum("money");
 
        return $money;
    }
 
}