Controller.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  4. use Illuminate\Foundation\Bus\DispatchesJobs;
  5. use Illuminate\Foundation\Validation\ValidatesRequests;
  6. use Illuminate\Routing\Controller as BaseController;
  7. //
  8. use App\Common\Library\Easemob;
  9. use Illuminate\Support\Facades\DB;
  10. use App\Jobs\EasemobJob;
  11. class Controller extends BaseController
  12. {
  13. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  14. public function test(){
  15. /*$easemob = new Easemob();
  16. $rs = $easemob->push_text(1009,'标题','内容');
  17. dd($rs);*/
  18. (new EasemobJob(1))->handle();
  19. }
  20. public function plantask(){
  21. $list = DB::table('mt_message')->where('dispatch_status',0)->orderBy('id','asc')->get()->toArray();
  22. //dd($list);
  23. //
  24. if(!empty($list)){
  25. foreach($list as $key => $val){
  26. $msg_id = $val->id;
  27. dispatch((new EasemobJob($msg_id))->delay(0));//加入队列
  28. }
  29. }
  30. //更新
  31. $ids = array_column($list,'id');
  32. $update = [
  33. 'dispatch_status' => 1,
  34. ];
  35. DB::table('mt_message')->whereIn('id',$ids)->update($update);
  36. }
  37. }