Apidsyskxcx.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. /**
  4. * 此类是为了解决erp没有队列的问题,为了解决这个问题,先写一下这个类,避免后期写那么多定时任务类 这里只能解决每间隔多少时间执行一会的
  5. */
  6. class Apidsyskxcx extends Start_Controller
  7. {
  8. private $serect_str = "yskxcx";
  9. private $user_agent = 'Xcly251618/Yskxcx (Erp)';
  10. private $api = "Yskxcx25.424";
  11. private $ip = ['127.0.0.1', '47.105.156.18'];
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->_model('Model_fullorder', 'fullorder');
  16. $this->load->_model("Model_logic_ding", "logic_ding");
  17. $this->load->_model("Model_cne", "cne");
  18. $this->load->_model("Model_zzjobs", "zzjobs");
  19. $this->load->_model('Model_notice','notice');
  20. $this->load->_model('Model_shop','shop');
  21. $this->load->_model('Model_express','express');
  22. $this->load->_model('Model_emaildata','emaildata');
  23. }
  24. public function _remap($arg, $arg_array)
  25. {
  26. $ip = $_SERVER['REMOTE_ADDR'];
  27. // if (!in_array($ip, $this->ip)) {
  28. // exit("Unauthorized access");
  29. // }
  30. $user_agent = empty($_SERVER['HTTP_USER_AGENT']) ? "" : $_SERVER['HTTP_USER_AGENT'];
  31. $token = empty($_SERVER['HTTP_X_AUTH_TOKEN']) ? "" : $_SERVER['HTTP_X_AUTH_TOKEN'];
  32. $time = $this->input->get('time', true);
  33. $api = $this->input->get('api', true);
  34. // $this->checkAuth($user_agent, $token, $time, $api);
  35. if ($arg == 'jobs') //调出单
  36. {
  37. $this->_doRenwu();
  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. {
  51. if ($api != $this->api) {
  52. exit("Access denied due to insufficient permissions");
  53. }
  54. $check_str = date("Ymd") . "¥_" . $this->serect_str . "_¥" . $time;
  55. if (empty($user_agent)) {
  56. exit('No direct script access allowed');
  57. }
  58. if ($user_agent != $this->user_agent) {
  59. exit('Illegal request');
  60. }
  61. if (empty($token)) {
  62. exit('No access permission');
  63. }
  64. $sercet_str = md5($check_str);
  65. if ($sercet_str != $token) {
  66. exit("Request permission is illegal");
  67. }
  68. }
  69. private function _index() {}
  70. private function _doRenwu()
  71. {
  72. echo "<pre>";
  73. $list = $this->zzjobs->find_all("status = 0 and quque = 'ysgjcx'", "*",null, 0, 1);
  74. print_r($list);
  75. die;
  76. $ids = array_column($list, 'id');
  77. $this->db->query("update crowd_zzjobs set status = 10 where id in (" . implode(",", $ids) . ")");
  78. foreach ($list as $v) {
  79. $this->doAction($v);
  80. sleep(2);
  81. }
  82. }
  83. private function doAction($v)
  84. {
  85. $param = json_decode($v['payload'], true);
  86. $info = $param['v'];
  87. $notice_id = $param['id'];
  88. $notice_info = $this->notice->read($notice_id);
  89. $fs = $this->cne->get_logistics_yskx(
  90. [
  91. [
  92. 'TrackNumber' => $info['waybill']
  93. ]
  94. ]
  95. );
  96. var_dump($fs);
  97. $wlfs = [];
  98. if (!isset($fs['f'])) {
  99. $this->fullorder->save(array('wlerror' => $fs['content']), $info['id']);
  100. } else {
  101. if ($fs['f'] == '1') {
  102. if ($fs['exstate'] > $info['expressstate'] || isset($fs['webhookregister'])) {
  103. $this->fullorder->save(array('expressstate' => $fs['exstate'], 'excontent' => $fs['data'], 'webhookregister' => 0, 'wlerror' => ''), $info['id']);
  104. }
  105. if ($fs['exstate'] == $notice_info['logisticstatus'] && $info['wlyc'] == '0' && $info['wltype'] != '1' && $info['source'] != '1') //获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  106. {
  107. if ($info['shop'] < '7') // && $v['shouldmoney'] > 100)
  108. {
  109. $wlfs[] = array('v' => $info, 'id' => $notice_id );
  110. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  111. }
  112. }
  113. } else {
  114. $this->fullorder->save(array('wlerror' => $fs['content']), $v['id']);
  115. }
  116. }
  117. $this->zzjobs->save(['status'=>30,'last_time'=>time(),'result'=>json_encode($fs,JSON_UNESCAPED_UNICODE)],$v['id']);
  118. // if(!empty($wlfs)){
  119. // $this->_sdfs($v['v'],$v['id']);
  120. // }
  121. // @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
  122. // if($wlfs)
  123. // {
  124. // foreach ($wlfs as $k=>$v)
  125. // {
  126. // $t1 = microtime(true);
  127. // $this->_sdfs($v['v'],$v['id']);
  128. // $t2 = microtime(true);
  129. // $t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
  130. // sleep($t3);
  131. // }
  132. // }
  133. }
  134. public function _sdfs($fullorder,$id)//手动发送信息
  135. {
  136. $time = time();
  137. $notice = $this->notice->read($id);//无条件同模板匹配
  138. $notice['email'] = $this->emaildata->read($notice['email']);
  139. $shop = $this->shop->read($fullorder['shop']);
  140. $express = $this->express->read($fullorder['express']);
  141. if($notice['type'] == '1')
  142. {
  143. $fslx = 'tab';
  144. $content = '自动发送';
  145. $stripos = '1-';
  146. }
  147. else if ($notice['type'] == '2')
  148. {
  149. $fslx = 'logisticstatus';
  150. $content = $notice['title'];
  151. $stripos = $notice['type'].'-'.$notice[$fslx].'|';
  152. }
  153. $this->logic_ding->sendToDing("云尚轨迹获取快递信息暂时中断");
  154. return ;
  155. if(stripos($fullorder['zdstate'],$stripos) === false && $fullorder['wltype'] == '0')//如果没发送过并且允许发送
  156. {
  157. $go = $this->notice->get_god($fullorder,$shop,$express,$notice);
  158. $this->logic_ding->sendToDing("云尚轨迹获取快递信息".json_encode($go,JSON_UNESCAPED_UNICODE));
  159. if($go == 1)
  160. {
  161. if($notice['type'] == '1')
  162. {
  163. $this->fullorder->save(array('content'=>$fullorder['content'].$content.'-成功;','zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  164. }
  165. else if ($notice['type'] == '2')
  166. {
  167. $this->fullorder->save(array('wlcontent'=>$fullorder['wlcontent'].$content.'-成功;','wlfstime'=>time(),'zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  168. }
  169. return 1;
  170. }
  171. else
  172. {
  173. if($notice['type'] == '1')
  174. {
  175. $this->fullorder->save(array('exstateerror'=>$content.'发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  176. }
  177. else if ($notice['type'] == '2')
  178. {
  179. $this->fullorder->save(array('wlerror'=>$content.'发送失败2:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  180. }
  181. }
  182. }
  183. }
  184. }