123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace Active\Lib;
- Use Dever;
- Class Cron{
- #活动订单定时关闭
- public function job_api()
- {
- $data = Dever::db('active/order')->state(array('status'=>1));
- $time = time();
- if ($data) {
- foreach ($data as $k => $v) {
- if ($v['cdate'] && $time-$v['cdate']>300) {
- Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>3));
- }
- }
- }
- return 'ok';
- }
- #活动状态
- public function status_api()
- {
- $data = Dever::db('active/info')->state();
- $time = time();
- if ($data) {
- $where = array();
- foreach ($data as $k =>$v) {
- if ($v['sign_start']) {
- $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end'],$v['sign_start'],$v['sign_end']);
- } else {
- $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end']);
- }
- $where['where_id'] = $v['id'];
- $where['act_status'] = $ids['act_status'];
- Dever::db('active/info')->update($where);
- }
- }
- return 'ok';
- }
- public function code_api()
- {
- $data = Dever::db('active/code')->state();
- if ($data) {
- foreach ($data as $k => $v) {
- if ($v['active_id']) {
- $active = Dever::db('active/info')->find($v['active_id']);
- if ($active['sign_start']) {
- $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end'],$active['sign_start'],$active['sign_end']);
- } else {
- $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end']);
- }
- $where['where_id'] = $v['id'];
- $where['act_status'] = $ids['act_status'];
- Dever::db('active/code')->update($where);
- }
- }
- return 'ok';
- }
- }
- public function start($cdate, $act_start, $act_end, $sign_start = false, $sign_end = false)
- {
- $time = time();
- if ($sign_start) {
- if ($time < $sign_start){
- $where['act_status'] = 1;
- } elseif ($sign_end) {
- if ($time >= $sign_start && $time < $sign_end) {
- $where['act_status'] = 2;
- } elseif ($time > $sign_end && $time < $act_start) {
- $where['act_status'] = 3;
- } elseif ($time > $act_start && $time < $act_end) {
- $where['act_status'] = 4;
- } elseif ($time > $act_end) {
- $where['act_status'] = 5;
- }
- }
- } else {
- if($time < $cdate) {
- $where['act_status'] = 1;
- } elseif ($time > $cdate && $time < $act_start) {
- $where['act_status'] = 2;
- } elseif ($time > $act_start && $time < $act_end) {
- $where['act_status'] = 4;
- } elseif ($time > $act_end) {
- $where['act_status'] = 5;
- }
- }
- return $where;
- }
- #更新user表
- public function user_api()
- {
- $data = Dever::db('active/order')->state();
- foreach ($data as $k => $v) {
- if ($v['mid'] && $v['mid'] > 0) {
- $member = Dever::db('agent/member')->find($v['mid']);
- if ($member && $member['mobile']) {
- $user = Dever::db('active/user')->find(array('mobile'=>$member['mobile']));
- if (!$user) {
- $insert['mid'] = $v['mid'];
- $insert['name'] = $member['name'];
- $insert['mobile'] = $member['mobile'];
- $insert['idcard'] = $member['idcard'];
- $insert['pass'] = $member['password'];
- $insert['old_pwd'] = $member['old_pwd'];
- $insert['old_salt'] = $member['old_salt'];
- Dever::db('active/user')->insert($insert);
- }
- }
- }
- }
- }
- #更新订单表
- public function setUSer_api()
- {
- $data = Dever::db('active/order')->state();
- foreach ($data as $k => $v) {
- $user = Dever::db('active/user')->find(array('mid'=>$v['mid']));
- if ($user) {
- $where['where_id'] = $v['id'];
- $where['uid'] = $user['id'];
- Dever::db('active/order')->update($where);
- }
- }
- }
- }
|