User.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/2/12
  6. * Time: 17:11
  7. */
  8. namespace app\worker\controller;
  9. use app\common\controller\Orde;
  10. use app\common\model\Order;
  11. use think\facade\Db;
  12. use Workerman\Lib\Timer;
  13. use app\common\model\User as USers;
  14. class User
  15. {
  16. // 处理过期的订单
  17. public function index()
  18. {
  19. Timer::add(5, function () {
  20. $this->order_cal();
  21. }, true);
  22. }
  23. // 自动发币
  24. public function fb()
  25. {
  26. Timer::add(20,function (){
  27. $this->fab();
  28. },true);
  29. }
  30. // 处理过期的订单
  31. public function order_cal()
  32. {
  33. $where[]=["stat_time","<",time()];
  34. $where[]=["status","=",1];
  35. $order=Order::where($where)->limit(5)->order("id asc")->select();
  36. if ($order){
  37. // $order=$order->toArray();
  38. foreach ($order as $v){
  39. Orde::order_fail("系统处理交易失败",$v);
  40. }
  41. }
  42. }
  43. public function test()
  44. {
  45. dump(1212);
  46. }
  47. //自动发币
  48. public function fab()
  49. {
  50. $list = Db::name('system')
  51. ->where(["type"=>"fb"])
  52. ->field('name,value')
  53. ->column('value','name');
  54. if ($list["fbkg"]){// 开启了自动
  55. // 查询当前未交易数量
  56. $count=Order::where(["status"=>0])->count();
  57. if ($count){// 存在交易数量
  58. // 计算获取多少个交易订单
  59. $fbsamll=$list["fbsamll"];
  60. $now=$count/$fbsamll;
  61. if ($now>1){
  62. $now=round($now);
  63. $order=Order::where(["status"=>0])->orderRaw('rand()')->limit($now)->column("id");
  64. if ($order){
  65. foreach ($order as $v){
  66. $mnum=rand(100,999);
  67. // 随机获取一个后台收款账号
  68. $user= USers::where(["admin"=>1])->orderRaw('rand()')->limit(1)->value("id");
  69. $wheres["id"]=$v;
  70. $update["stat_time"]=time()+(1*3600+$mnum);
  71. $update["is_admin"]=1;
  72. $update["status"]=1;
  73. $update["push_user"]=$user;
  74. Order::update($update,$wheres);
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }