123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?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']>900) {
- Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>3));
- }
- $active = Dever::db('active/info')->find($v['active_id']);
- if ($time > $active['act_end']) {
- Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>4));
- }
- }
- }
- 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::load('active/lib/user')->agent($v, 'mid');
- if ($member && $member['mobile']) {
- $user = Dever::db('active/user')->find(array('mobile'=>$member['mobile'], 'clear' => true));
- if (!$user) {
- $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'];
- $insert['clear'] = true;
- $uid = Dever::db('active/user')->insert($insert);
- $ids = Dever::db('active/order')->update(array('where_id' => $v['id'], 'uid' => $uid));
- } else {
- $uid = $user['id'];
- $ids = Dever::db('active/order')->update(array('where_id' => $v['id'], 'uid' => $user['id']));
- }
- if ($v['status'] == 2 && $uid) {
- $code = Dever::db('active/code')->find(array('active_id'=> $v['active_id'],'join_uid'=>$uid,'clear'=>true));
- if (!$code) {
- $w['active_id'] = $v['active_id'];
- $w['join_uid'] = $uid;
- $w['buy_uid'] = $uid;
- $w['order_id'] = $v['id'];
- $w['clear'] = true;
- $w['write_code'] = $this->getCode();
- $code_id = Dever::db('active/code')->insert($w);
- if ($code_id) {
- $where['where_id'] = $v['id'];
- $where['code_num'] = 1;
- $where['no_num'] = 0;
- $where['clear'] = true;
- Dever::db('active/order')->update($where);
- }
- }
- }
- }
- }
- }
- }
- public function bcode_api()
- {
- $order_id = Dever::input('order_id');
- $status = 2;
- $order = Dever::db('active/order')->one(array('id' => $order_id, 'clear' => true));
- if ($order && $status == 2) {
-
- $code = Dever::db('active/code')->find(array('join_uid'=>$order['uid'],'active_id'=>$order['active_id']));
- if (!$code) {
- $active = Dever::db('active/info')->find($order['active_id']);
- $insert['join_uid'] = $order['uid'];
- $insert['active_id'] = $order['active_id'];
- $insert['buy_uid'] = $order['uid'];
- $insert['order_id'] = $order['id'];
- $insert['write_code'] = $this->getCode();
- $insert['act_status'] = $active['act_status'];
- $ids = Dever::db('active/code')->insert($insert);
- if ($ids) {
- $update['code_num'] = 1;
- }
- }
- $update['status'] = 2;
- $update['where_id'] = $order['id'];
-
- Dever::db('active/order')->update($update);
- }
- return 'ok';
- }
- #活动核销码
- public function getCode()
- {
- $where['write_code'] = Dever::rand(6, 0);
- $state = Dever::db('active/code')->one($where);
- if (!$state) {
- return $where['write_code'];
- } else {
- return $this->getCode();
- }
- }
- #更改订单状态
- public function update_order_api()
- {
- $data = Dever::db('active/order')->state();
- foreach ($data as $k => $v) {
- if ($v['num'] == $v['refund_num']) {
- $where['where_id'] = $v['id'];
- $where['status'] = 6;
- }
- if ($v['refund_num'] >0 && $v['refund_num'] != $v['num']) {
- $where['where_id'] = $v['id'];
- $where['status'] = 7;
- }
- if (isset($where) && $where) {
- Dever::db('active/order')->update($where);
- }
- }
- return 'ok';
- }
- }
|