Timing.php
3.4 KB
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
<?php
namespace app\api\controller;
use app\api\model\OrderDetail;
use app\api\model\TeamGroup;
use app\api\model\Ticket;
use app\api\model\UserTicket;
use app\api\model\User;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;
/**
* 定时任务接口
* @ApiInternal
*/
class Timing extends Api
{
/**
* @ApiTitle (自动收货)
* @ApiSummary (自动收货 每天执行)
* @ApiMethod (POST)
* @ApiRoute (/api/Timing/automaticReceiving)
* @ApiReturn({
})
*/
public function automaticReceiving(){
$model = new OrderDetail();
$model->where(['status'=>3,'receivingtime'=>['<',time()]])->update(['status'=>4]);
}
/**
* @ApiTitle (修改用户会员状态)
* @ApiSummary (修改用户会员状态 每天执行)
* @ApiMethod (POST)
* @ApiRoute (/api/Timing/user)
* @ApiReturn({
})
*/
public function user(){
$userModel = new User();
$userModel->where(['type'=>2,'deadline'=>['<',time()]])->update(['type'=>1,'deadline'=>'']);
}
/**
* @ApiTitle (修改优惠券过期状态)
* @ApiSummary (修改优惠券过期状态 每天执行)
* @ApiMethod (POST)
* @ApiRoute (/api/Timing/ticket)
* @ApiReturn({
})
*/
public function ticket(){
$userTicketModel = new UserTicket();
$userTicketModel->where(['status'=>1,'pasttime'=>['<',time()]])->update(['status'=>'3']);
}
/**
* @ApiTitle (发放优惠券(会员用户))
* @ApiSummary (发放优惠券(会员用户)每月第一天执行)
* @ApiMethod (POST)
* @ApiRoute (/api/Timing/grantVipTicket)
* @ApiReturn({
})
*/
public function grantVipTicket(){
$ticketModel = new Ticket();
$userTicketModel = new UserTicket();
$userModel = new User();
$ticket = $ticketModel->where(['setting_month'=>1])->field('createtime,updatetime',true)->select();
$userIds = $userModel->where('type',2)->column('id');
$data = [];
foreach ($ticket as $k => $ticketInfo){
foreach ($userIds as $kk => $userId){
$date = explode('-',date('Y-m-d',strtotime('+ '.$ticketInfo['days'].'day')));
$time = mktime(23,59,00,$date[1],$date[2],$date[0]);
$data[] = [
'user_id' => $userId,
'ticket_id' => $ticketInfo['id'],
'ch_name' => $ticketInfo['ch_name'],
'en_name' => $ticketInfo['en_name'],
'price' => $ticketInfo['price'],
'type' => 2, //获取途径:1=后台发放,2=其他
'status' => 1, //状态:1=未使用,2=已使用,3=已过期
'pasttime' => $time //过期时间
];
}
}
$userTicketModel->saveAll($data);
}
/**
* @ApiTitle (修改拼团过期状态)
* @ApiSummary (修改拼团过期状态 每分钟执行)
* @ApiMethod (POST)
* @ApiRoute (/api/Timing/teamGroup)
* @ApiReturn({
})
*/
public function teamGroup(){
$teamGroupModel = new TeamGroup();
$ids = $teamGroupModel->where(['status'=>1,'grouptime'=>['<',time()]])->column('id');
if (!$ids) return false;
$teamGroupModel->pastDue($ids);
}
}