Zzjobs.php 4.8 KB

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