Timedtask.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Apply;
  5. /**
  6. * 定时脚本
  7. */
  8. class Timedtask extends Api
  9. {
  10. protected $noNeedLogin = '*';
  11. protected $noNeedRight = '*';
  12. /**
  13. * 申请wx过期自动退还狗粮
  14. * @return void
  15. */
  16. public function refund()
  17. {
  18. $expirationTime = config('site.expirationTime');
  19. $data = Apply::all(['status' => 0]);
  20. foreach ($data as $k => $v) {
  21. if((strtotime($v['createtime'])+$expirationTime*60*60)<time()){
  22. \app\common\model\User::money($v['grain'],$v['uid'],'过期自动退还狗粮');
  23. $v->save(['status'=>3,'refund_grain'=>$v['grain']]);
  24. }
  25. }
  26. }
  27. /**
  28. * 会员每月免费喜欢额度
  29. */
  30. public function freescore(){
  31. $freescore = config('site.freescore');
  32. $user = \app\common\model\User::all(['status'=>'normal']);
  33. foreach ($user as $k=>$v){
  34. $freescore_time = strtotime($v['freescore_time'])+(24*60*60)*30;
  35. if($freescore_time<time()){
  36. \app\common\model\User::score($freescore,$v['id'],'会员每月免费喜欢额度');
  37. $v->save(['freescore_time'=>date("Y-m-d H:i:s")]);
  38. }
  39. }
  40. }
  41. }