Zzjobs.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. /**
  4. * 此类是为了解决erp没有队列的问题,为了解决这个问题,先写一下这个类,避免后期写那么多定时任务类 这里只能解决每间隔多少时间执行一会的
  5. */
  6. class Zzjobs extends Start_Controller
  7. {
  8. private $serect_str = "erpjob";
  9. private $user_agent = 'Xcly251618/Job (Erp)';
  10. private $api = "ly202508160727";
  11. private $ip = ['127.0.0.1','47.105.156.18'];
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->_model("Model_zzjobs","zzjobs");
  16. $this->load->_model("Model_logic_tools",'logic_tools');
  17. $this->load->_model("Model_fullordererrors","fullordererrors");
  18. $this->load->_model("Model_logic_order","logic_order");
  19. }
  20. public function _remap($arg, $arg_array)
  21. {
  22. $ip = $_SERVER['REMOTE_ADDR'];
  23. if(!in_array($ip,$this->ip)){
  24. exit("Unauthorized access");
  25. }
  26. $user_agent = empty($_SERVER['HTTP_USER_AGENT'])?"":$_SERVER['HTTP_USER_AGENT'];
  27. $token = empty($_SERVER['HTTP_X_AUTH_TOKEN'])?"":$_SERVER['HTTP_X_AUTH_TOKEN'];
  28. $time = $this->input->get('time',true);
  29. $api = $this->input->get('api',true);
  30. $this->checkAuth($user_agent,$token,$time,$api);
  31. if ($arg == 'jobs') //调出单
  32. {
  33. $this->_jobs();
  34. } else {
  35. $this->_index();
  36. }
  37. }
  38. /**
  39. * 校验是否有权限可以执行
  40. * $user_agent 自定义的请求客户端名称
  41. * $token 自定义的清华客户端的token
  42. * $time 请求的时间
  43. *
  44. */
  45. private function checkAuth($user_agent,$token,$time,$api){
  46. if($api != $this->api){
  47. exit("Access denied due to insufficient permissions");
  48. }
  49. $check_str = date("Ymd")."¥_".$this->serect_str."_¥".$time;
  50. if(empty($user_agent)){
  51. exit('No direct script access allowed');
  52. }
  53. if($user_agent != $this->user_agent){
  54. exit('Illegal request');
  55. }
  56. if(empty($token)){
  57. exit('No access permission');
  58. }
  59. $sercet_str = md5($check_str);
  60. if($sercet_str != $token){
  61. exit("Request permission is illegal");
  62. }
  63. }
  64. private function _index() {}
  65. //一般每一分钟都执行的 每分钟就执行10条
  66. //每五分钟 就执行100条
  67. //其他的就不限制了
  68. private function _jobs() {
  69. $this->db->query("DELETE from crowd_zzjobs where status = 30");
  70. $final_list = $this->zzjobs->find_all("status = 0","*",null,0,100);
  71. if(empty($final_list)){
  72. return ;
  73. }
  74. $do_list_ids = array_column($final_list,'id');
  75. $this->db->query("update crowd_zzjobs set status = 10 where id in (".implode(",",$do_list_ids).")");
  76. foreach($final_list as $v){
  77. $this->tasksAssign($v);
  78. }
  79. }
  80. private function tasksAssign($info){
  81. switch($info['quque']){
  82. case 'outtime_order':
  83. $params = json_decode($info['payload'],true);
  84. $order_info = $this->logic_order->getInfo("number = '".$params['number']."'","*");
  85. if(!empty($order_info)){
  86. $this->fullordererrors->insert([
  87. 'number'=>$order_info['number'],
  88. 'shop'=>$order_info['shop'],
  89. 'plat'=>$order_info['lv_platform'],
  90. 'error_type'=>1,//订单超时15秒
  91. 'error_msg'=>"订单打印超时,请核对订单是否核对",
  92. 'error_time'=>$info['create_time'],
  93. 'create_time'=>time()
  94. ]);
  95. }
  96. $this->zzjobs->save([
  97. 'status'=>30,
  98. 'result'=>$this->logic_tools->ret_json(1,"执行完毕"),
  99. 'last_time'=>time()
  100. ],$info['id']);
  101. break;
  102. default:
  103. $this->zzjobs->save([
  104. 'status'=>20,
  105. 'result'=>$this->logic_tools->ret_json(-1,"没有对应发方法执行任务"),
  106. 'last_time'=>time()
  107. ],$info['id']);
  108. break;
  109. }
  110. }
  111. }