Crontab.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\api\controller\service;
  3. use app\common\controller\Api;
  4. use think\db\exception\DataNotFoundException;
  5. use think\db\exception\ModelNotFoundException;
  6. use think\exception\DbException;
  7. use think\Log;
  8. class Crontab extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 更新服务者时间
  14. * @return void
  15. */
  16. public function skillTimeUpdate()
  17. {
  18. $starttime = strtotime(date("Y-m-d", time()));
  19. $where['changetime'] = ['<', $starttime];
  20. $skilltime = new \app\api\model\service\SkillTime();
  21. $skilltime->where($where)
  22. ->where('timetype', 'in', [1, 2])
  23. ->dec('timetype', 1)
  24. ->update(['changetime' => time()]);
  25. $skilltime->where($where)
  26. ->where('timetype', 0)
  27. ->inc('starttime', 259200)
  28. ->inc('endtime', 259200)
  29. ->update(['timetype' => 2, 'state' => 0, 'changetime' => time()]);
  30. $this->success('时间已更新');
  31. }
  32. /**
  33. * 结算订单
  34. * @return void
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. */
  39. public function updateOrderSettle()
  40. {
  41. $list = \app\api\model\service\Order::where(['is_settle'=>1,'settletime'=>['<',time()]])->select();
  42. foreach ($list as $value)
  43. {
  44. \app\api\model\service\Rebate::handleRebate($value);
  45. \app\api\model\service\Order::where(['id'=>$value['id']])->update(['is_settle'=>2,'updatetime'=>time()]);
  46. }
  47. $this->success('订单已结算');
  48. }
  49. /**
  50. * 默认好评
  51. * @return void
  52. * @throws DataNotFoundException
  53. * @throws DbException
  54. * @throws ModelNotFoundException
  55. * @throws \think\Exception
  56. */
  57. public function commentOrder()
  58. {
  59. $commentConfig = \app\api\model\service\ProjectConfig::getProjectConfig('comment_day');
  60. $list = \app\api\model\service\Order::where(['status' => 6, 'finishtime' => ['<', time() - 86400 * $commentConfig]])->field('id,user_id')->select();
  61. foreach ($list as $value)
  62. {
  63. \app\api\model\service\Comment::commentAdd(['order_id'=>$value['id'],'user_id'=>$value['user_id'],'score'=>5,'content'=>'此用户未填写评价内容','images'=>'']);
  64. }
  65. $this->success('订单已处理');
  66. }
  67. /**
  68. * 更新优惠券状态
  69. * @return void
  70. * @throws DataNotFoundException
  71. * @throws DbException
  72. * @throws ModelNotFoundException
  73. */
  74. public function updateCoupon()
  75. {
  76. $userCoupon = \app\api\model\service\UserCoupon::where(['state'=>0,'exittime'=>['<',time()]])->field('id')->select();
  77. foreach ($userCoupon as $value)
  78. {
  79. \app\api\model\service\UserCoupon::where('id',$value['id'])->update(['state'=>-1]);
  80. }
  81. $this->success('已处理');
  82. }
  83. /**
  84. * 更新会员状态
  85. * @return void
  86. * @throws DataNotFoundException
  87. * @throws DbException
  88. * @throws ModelNotFoundException
  89. */
  90. public function updateData()
  91. {
  92. $list = \app\api\model\service\UserInfo::where(['is_plus'=>1,'plustime'=>['<',time()]])->field('id')->select();
  93. foreach ($list as $value)
  94. {
  95. \app\api\model\service\UserInfo::where('id',$value['id'])->update(['is_plus'=>0,'plustime'=>time(),'discount'=>100]);
  96. }
  97. $cancelConfig = \app\api\model\service\ProjectConfig::getProjectConfig('cancel_minute');
  98. $list = \app\api\model\service\Order::where(['status' => 0, 'createtime' => ['<', time() - 60 * $cancelConfig]])->field('id,user_id')->select();
  99. foreach ($list as $value)
  100. {
  101. \app\api\model\service\Order::where(['id'=>$value['id']])->update(['status'=>-1,'updatetime'=>time(),'is_pool'=>0]);
  102. }
  103. $this->success('信息已更新');
  104. }
  105. /**
  106. * 统计每日数据
  107. * @return void
  108. */
  109. public function updateTotalData()
  110. {
  111. \app\api\model\service\TotalData::totalData(1);
  112. $this->success('信息已统计');
  113. }
  114. }