Plan.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\UsersModel;
  4. use app\common\lib\WxPay;
  5. use think\Controller;
  6. use think\Db;
  7. /**
  8. * 宝塔计划任务类
  9. * @ApiInternal
  10. * Class Plan
  11. * @package app\api\controller
  12. */
  13. class Plan extends Controller
  14. {
  15. // 每月清空VIP开通限制 /api/plan/clearVipData
  16. public function clearVipData()
  17. {
  18. $ids = UsersModel::field('user_id')->select();
  19. $ip = $this->request->ip();
  20. foreach ($ids as $v) {
  21. UsersModel::where('user_id', $v['user_id'])->update(['vip_use_num' => 0, 'vip_discount_quota' => 0]);
  22. }
  23. $info = array(
  24. 'desc' => '每月清空VIP开通限制',
  25. 'status' => '成功',
  26. 'ip' => $ip,
  27. 'time' => date('Y-m-d H:i:s', time())
  28. );
  29. Db::name('plan_log')->insert($info);
  30. }
  31. // 清空今日已用的基础排队次数 /api/plan/clearTodayQueueUseNum
  32. public function clearTodayQueueUseNum()
  33. {
  34. $ids = UsersModel::field('user_id')->select();
  35. $ip = $this->request->ip();
  36. foreach ($ids as $v) {
  37. UsersModel::where('user_id', $v['user_id'])->update(['queue_num_today' => 0]);
  38. }
  39. $info = array(
  40. 'desc' => '每天清空已用基础排队次数',
  41. 'status' => '成功',
  42. 'ip' => $ip,
  43. 'time' => date('Y-m-d H:i:s', time())
  44. );
  45. Db::name('plan_log')->insert($info);
  46. }
  47. // 用户白豆每日千分之一递减至红豆
  48. public function whiteToRed()
  49. {
  50. $users = UsersModel::where('user_whitebean', '>', '1')->select();
  51. $bean = Db::name('setbean')->find();
  52. foreach ($users as &$v) {
  53. // 求出每个用户要递减白豆和递加红豆的数量
  54. $bean = $v['user_whitebean'] * $bean['num'];
  55. // 红豆递加
  56. Db::name('users')->where('user_id', $v['user_id'])->setInc('user_redbean', $bean);
  57. // 白豆递减
  58. Db::name('users')->where('user_id', $v['user_id'])->setDec('user_whitebean', $bean);
  59. }
  60. // 获取当前访问IP
  61. $ip = $this->request->ip();
  62. $info = array(
  63. 'desc' => '白豆红豆递减递加',
  64. 'status' => '成功',
  65. 'ip' => $ip,
  66. 'time' => date('Y-m-d H:i:s', time())
  67. );
  68. // 生成记录
  69. Db::name('plan_log')->insert($info);
  70. }
  71. }