0
0

WasteTask.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\cron;
  3. use app\common\util\AppMsg;
  4. use think\Db;
  5. use yunwuxin\cron\Task;
  6. class WasteTask extends Task
  7. {
  8. public function configure()
  9. {
  10. $this->everyMinute(); //每分钟执行一次
  11. }
  12. /**
  13. * 执行任务
  14. * @return mixed
  15. */
  16. protected function execute()
  17. {
  18. try{
  19. $this->waste();
  20. }catch (\Exception $e){
  21. trace($e->getMessage());
  22. }
  23. }
  24. //医废未转运提醒 每分钟执行一次
  25. public function waste(){
  26. set_time_limit(0);
  27. ini_set("memory_limit","1024M");
  28. $orgids = Db::name('config_org')
  29. ->alias('co')
  30. ->join('config c','c.id = co.config_id')
  31. ->where('c.name','org_waste_status')
  32. ->where('co.value',1)
  33. ->column('co.org_id');
  34. if(!$orgids){
  35. return false;
  36. }
  37. $orgids2 = Db::name('config_org')
  38. ->alias('co')
  39. ->join('config c','c.id = co.config_id')
  40. ->where('c.name','org_waste_time')
  41. ->where('co.value',date('H:i'))
  42. ->column('co.org_id');
  43. if(!$orgids2){
  44. return false;
  45. }
  46. $orgids = array_unique(array_intersect($orgids,$orgids2));
  47. if(!$orgids){
  48. return false;
  49. }
  50. $users = [];
  51. foreach ($orgids as $v){
  52. //检查是否有未转运订单
  53. $ret = Db::name('waste_record')
  54. ->where('org_id',$v)
  55. ->where('status','in',[0,1])
  56. ->find();
  57. if(!$ret){
  58. continue;
  59. }
  60. // 检查是否设置通知人员
  61. $uids = model('Config')->getConfig('org_waste_user',$v);
  62. if($uids){
  63. $users = array_merge($users,explode(',',$uids));
  64. }
  65. }
  66. if($users){ //推送
  67. $length = 1000;
  68. $count = ceil(count($users)/$length);
  69. for ($i=0;$i<$count;$i++){
  70. $uids = array();
  71. $min = $i*$length;
  72. $max = $min + $length;
  73. if($max > count($users)){
  74. $max = count($users);
  75. }
  76. for($j=$min;$j<$max;$j++){
  77. $uids[] = $users[$j];
  78. }
  79. send_jpush($uids,AppMsg::PUSH_WASTE_UNFINISH);
  80. }
  81. }
  82. }
  83. }