123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020/2/12
- * Time: 17:11
- */
- namespace app\worker\controller;
- use app\common\controller\Orde;
- use app\common\model\Order;
- use think\facade\Db;
- use Workerman\Lib\Timer;
- use app\common\model\User as USers;
- class User
- {
- // 处理过期的订单
- public function index()
- {
- Timer::add(5, function () {
- $this->order_cal();
- }, true);
- }
- // 自动发币
- public function fb()
- {
- Timer::add(20,function (){
- $this->fab();
- },true);
- }
- // 处理过期的订单
- public function order_cal()
- {
- $where[]=["stat_time","<",time()];
- $where[]=["status","=",1];
- $order=Order::where($where)->limit(5)->order("id asc")->select();
- if ($order){
- // $order=$order->toArray();
- foreach ($order as $v){
- Orde::order_fail("系统处理交易失败",$v);
- }
- }
- }
- public function test()
- {
- dump(1212);
- }
- //自动发币
- public function fab()
- {
- $list = Db::name('system')
- ->where(["type"=>"fb"])
- ->field('name,value')
- ->column('value','name');
- if ($list["fbkg"]){// 开启了自动
- // 查询当前未交易数量
- $count=Order::where(["status"=>0])->count();
- if ($count){// 存在交易数量
- // 计算获取多少个交易订单
- $fbsamll=$list["fbsamll"];
- $now=$count/$fbsamll;
- if ($now>1){
- $now=round($now);
- $order=Order::where(["status"=>0])->orderRaw('rand()')->limit($now)->column("id");
- if ($order){
- foreach ($order as $v){
- $mnum=rand(100,999);
- // 随机获取一个后台收款账号
- $user= USers::where(["admin"=>1])->orderRaw('rand()')->limit(1)->value("id");
- $wheres["id"]=$v;
- $update["stat_time"]=time()+(1*3600+$mnum);
- $update["is_admin"]=1;
- $update["status"]=1;
- $update["push_user"]=$user;
- Order::update($update,$wheres);
- }
- }
- }
- }
- }
- }
- }
|