Cron.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Active\Lib;
  3. Use Dever;
  4. Class Cron{
  5. #活动订单定时关闭
  6. public function job_api()
  7. {
  8. $data = Dever::db('active/order')->state(array('status'=>1));
  9. $time = time();
  10. if ($data) {
  11. foreach ($data as $k => $v) {
  12. if ($v['cdate'] && $time-$v['cdate']>300) {
  13. Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>3));
  14. }
  15. }
  16. }
  17. return 'ok';
  18. }
  19. #活动状态
  20. public function status_api()
  21. {
  22. $data = Dever::db('active/info')->state();
  23. $time = time();
  24. if ($data) {
  25. $where = array();
  26. foreach ($data as $k =>$v) {
  27. if ($v['sign_start']) {
  28. $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end'],$v['sign_start'],$v['sign_end']);
  29. } else {
  30. $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end']);
  31. }
  32. $where['where_id'] = $v['id'];
  33. $where['act_status'] = $ids['act_status'];
  34. Dever::db('active/info')->update($where);
  35. }
  36. }
  37. return 'ok';
  38. }
  39. public function code_api()
  40. {
  41. $data = Dever::db('active/code')->state();
  42. if ($data) {
  43. foreach ($data as $k => $v) {
  44. if ($v['active_id']) {
  45. $active = Dever::db('active/info')->find($v['active_id']);
  46. if ($active['sign_start']) {
  47. $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end'],$active['sign_start'],$active['sign_end']);
  48. } else {
  49. $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end']);
  50. }
  51. $where['where_id'] = $v['id'];
  52. $where['act_status'] = $ids['act_status'];
  53. Dever::db('active/code')->update($where);
  54. }
  55. }
  56. return 'ok';
  57. }
  58. }
  59. public function start($cdate, $act_start, $act_end, $sign_start = false, $sign_end = false)
  60. {
  61. $time = time();
  62. if ($sign_start) {
  63. if ($time < $sign_start){
  64. $where['act_status'] = 1;
  65. } elseif ($sign_end) {
  66. if ($time >= $sign_start && $time < $sign_end) {
  67. $where['act_status'] = 2;
  68. } elseif ($time > $sign_end && $time < $act_start) {
  69. $where['act_status'] = 3;
  70. } elseif ($time > $act_start && $time < $act_end) {
  71. $where['act_status'] = 4;
  72. } elseif ($time > $act_end) {
  73. $where['act_status'] = 5;
  74. }
  75. }
  76. } else {
  77. if($time < $cdate) {
  78. $where['act_status'] = 1;
  79. } elseif ($time > $cdate && $time < $act_start) {
  80. $where['act_status'] = 2;
  81. } elseif ($time > $act_start && $time < $act_end) {
  82. $where['act_status'] = 4;
  83. } elseif ($time > $act_end) {
  84. $where['act_status'] = 5;
  85. }
  86. }
  87. return $where;
  88. }
  89. #更新user表
  90. public function user_api()
  91. {
  92. $data = Dever::db('active/order')->state();
  93. foreach ($data as $k => $v) {
  94. if ($v['mid'] && $v['mid'] > 0) {
  95. $member = Dever::db('agent/member')->find($v['mid']);
  96. if ($member && $member['mobile']) {
  97. $user = Dever::db('active/user')->find(array('mobile'=>$member['mobile']));
  98. if (!$user) {
  99. $insert['mid'] = $v['mid'];
  100. $insert['name'] = $member['name'];
  101. $insert['mobile'] = $member['mobile'];
  102. $insert['idcard'] = $member['idcard'];
  103. $insert['pass'] = $member['password'];
  104. $insert['old_pwd'] = $member['old_pwd'];
  105. $insert['old_salt'] = $member['old_salt'];
  106. Dever::db('active/user')->insert($insert);
  107. }
  108. }
  109. }
  110. }
  111. }
  112. #更新订单表
  113. public function setUSer_api()
  114. {
  115. $data = Dever::db('active/order')->state();
  116. foreach ($data as $k => $v) {
  117. $user = Dever::db('active/user')->find(array('mid'=>$v['mid']));
  118. if ($user) {
  119. $where['where_id'] = $v['id'];
  120. $where['uid'] = $user['id'];
  121. Dever::db('active/order')->update($where);
  122. }
  123. }
  124. }
  125. }