Apicjgx.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. /**
  3. * 作为检测车间功效的定时任务
  4. */
  5. class Apicjgx extends Start_Controller {
  6. public function __construct(){
  7. parent::__construct();
  8. $this->load->_model('Model_systemtransfer','systemtransfer');
  9. $this->load->_model("Model_systemtransfer_cr",'systemtransfer_cr');
  10. $this->load->_model("Model_transfer",'transfer');
  11. $this->load->_model("Model_fullorder","fullorder");
  12. $this->load->_model("Model_fullordersmt","fullordersmt");
  13. $this->load->_model("Model_fullordertt","fullordertt");
  14. }
  15. //定义方法的调用规则 获取URI第二段值
  16. public function _remap($arg,$arg_array)
  17. {
  18. if($arg == 'cjgx' ){
  19. //执行车间效率检测
  20. $this->_cjgx();
  21. }else{
  22. $this->_index();
  23. }
  24. }
  25. public function _index(){
  26. echo "程序异常";
  27. }
  28. public function dd($val){
  29. echo "<pre>";
  30. var_dump($val);
  31. die;
  32. }
  33. public function _cjgx(){
  34. $limit_time = time() - 3600*24*30;
  35. $list = $this->systemtransfer->find_all("status < 10 and time >= ".$limit_time);
  36. if(empty($list)){
  37. die(json_encode(array('code'=>0,'msg'=>'没有需要检测的工单'),JSON_UNESCAPED_UNICODE));
  38. }
  39. echo date('Y-m-d H:i:s')."开始执行车间效率检测".PHP_EOL;
  40. foreach ($list as $val){
  41. $this->doSingleData($val);
  42. }
  43. echo date('Y-m-d H:i:s')."执行车间效率检测结束".PHP_EOL;
  44. }
  45. //单独处理每个工单的状态判断
  46. public function doSingleData($info){
  47. $lbrk = array_reverse(explode('|',trim($info['rk'],'|')));
  48. $lbck = array_reverse(explode('|',trim($info['ck'],'|')));
  49. //如果是11 说明是成品库 说明已经入库完毕了 表示已经完毕
  50. if($lbrk[0] == 11){
  51. $this->checkOver($info['id']);
  52. return;
  53. }
  54. //检测出入库都存在时 是否做过标记 在出库的时候已经同步过了
  55. if($lbrk[0] == $lbck[0]){
  56. // if(!in_array($lbrk[0],[11,12,15,16])){
  57. // $this->checkIsOver($info,$lbrk[0]);
  58. // return;
  59. // }
  60. return ;
  61. }
  62. //如果是 成品库 布标打印 发块 滞销款 不做处理 再次判定状态是否是 超时一次 超时两次
  63. if(!in_array($lbrk[0],[11,12,15,16])){
  64. $this->jdgeTimeOut($info,$lbrk[0]);
  65. }
  66. }
  67. //如果检测到最后的入库是
  68. /**
  69. * $id 工单主键id
  70. */
  71. public function checkOver($id){
  72. $this->systemtransfer->save(array('status'=>10),$id);
  73. $this->load->database();
  74. //同步表示 此单已经到成品库 完结了
  75. $this->db->where('fid',$id);
  76. $this->db->update('systemtransfer_cr',array('is_over'=>3));
  77. $this->db->affected_rows();
  78. }
  79. //检测是否已经完结 如果完结 且已经标记 那么不做处理 如果为做标记 那么就坐下处理
  80. /**
  81. * $fid 工单主键id
  82. * $lx 车间id
  83. */
  84. public function checkIsOver($info,$lx){
  85. $fid = $info['id'];
  86. $list = $this->systemtransfer_cr->find_all("fid = ".$fid,"*",'id desc',0,2);
  87. //如果查到的数据小于2 那么就说明此单异常
  88. if(count($list) < 2){
  89. //echo json_encode(array('code'=>0,'msg'=>'程序异常','data'=>['info'=>$info,'list'=>$list]),JSON_UNESCAPED_UNICODE);
  90. return ;
  91. }
  92. //如果查到的数据不等于指定的车间id 说明程序异常了 先不执行
  93. if(($list[0]['lx'] != $lx) || ($list[1]['lx'] != $lx)){
  94. return ;
  95. }
  96. if(($list[0]['is_over'] == 0) || ($list[1]['is_over'] == 0)){
  97. if($list[1]['orver_flag'] == 2){
  98. $this->systemtransfer_cr->save(['is_over'=>1,'orver_flag'=>2],$list[0]['id']);
  99. }else{
  100. $this->systemtransfer_cr->save(['is_over'=>1],$list[0]['id']);
  101. }
  102. $this->systemtransfer_cr->save(['is_over'=>1],$list[1]['id']);
  103. }
  104. return ;
  105. }
  106. //判定是否超时
  107. public function jdgeTimeOut($info,$lx){
  108. $list = $this->systemtransfer_cr->find_all("fid = ".$info['id'],"*",'id desc',0,1);
  109. if(empty($list)){
  110. return ;
  111. }
  112. if($list[0]['lx'] != $lx){
  113. return ;
  114. }
  115. //查询流转部分要求
  116. $depart_info = $this->transfer->find("id = ".$lx);
  117. if(empty($depart_info)){
  118. return ;
  119. }
  120. $now_time = time();
  121. $ru_time = $list[0]['time'];//扫描时间
  122. // $overtime_one = $depart_info['overtime_one'] * 3600;
  123. // $overtime_two = $depart_info['overtime_two'] * 3600;
  124. //如果时间节点一样 就不再执行了
  125. if($depart_info['overtime_one'] == $depart_info['overtime_two']){
  126. return ;
  127. }
  128. $overtime_one = $depart_info['overtime_one'] * 3600 ;
  129. $overtime_two = $depart_info['overtime_two'] * 3600;
  130. //不选超时
  131. if(($now_time - $ru_time) < $overtime_one){
  132. return ;
  133. }
  134. $limit_time = [
  135. 'overtime_one'=> $depart_info['overtime_one'],
  136. 'overtime_two'=>$depart_info['overtime_two'],
  137. ];
  138. $remain_time = $now_time - $ru_time;
  139. $num = $this->weektimes($ru_time , $now_time);
  140. if($num > 0 ){
  141. $remain_time = $remain_time - 24 * 3600 * $num;
  142. }
  143. //前处理有时间1 就是超时提醒
  144. // if($lx == 5){
  145. // //超时一次的
  146. // if(($now_time - $ru_time) >= $overtime_one ){
  147. // if($list['0']['orver_flag'] == 0){
  148. // $this->systemtransfer_cr->save(['orver_flag'=>1,'limit_time_str'=> json_encode($limit_time)],$list['0']['id']);
  149. // }
  150. // }
  151. // }else{
  152. //超时一次的
  153. if(( $remain_time) >= $overtime_one && ( $remain_time) < $overtime_two){
  154. if($list['0']['orver_flag'] == 0){
  155. $type = $this->checkOrderInfo($info['number']);
  156. if($type == 1){//订单取消了或者其他原因 在没出库的情况下就完成了
  157. $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);
  158. }elseif($type == 10){
  159. $this->systemtransfer_cr->save(['orver_flag'=>1,'limit_time_str'=> json_encode($limit_time)],$list[0]['id']);
  160. }
  161. }
  162. }
  163. //超时2次的
  164. if(( $remain_time) >= $overtime_two){
  165. if($list[0]['orver_flag'] <= 1){
  166. //$this->systemtransfer_cr->save(['orver_flag'=>2,'limit_time_str'=> json_encode($limit_time)],$list['0']['id']);
  167. $type = $this->checkOrderInfo($info['number']);
  168. if($type == 1){//订单取消了或者其他原因 在没出库的情况下就完成了
  169. $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);
  170. }elseif($type == 10){
  171. $this->systemtransfer_cr->save(['orver_flag'=>2,'limit_time_str'=> json_encode($limit_time)],$list[0]['id']);
  172. }else{
  173. }
  174. }
  175. }
  176. //}
  177. }
  178. //检测是否含有周日
  179. protected function weektimes($start_time,$endstime)
  180. {
  181. //是否有周六周日
  182. $week_array = [7, 1, 2, 3, 4, 5, 6];
  183. $i = 0;
  184. while ($start_time <= $endstime) {
  185. $now_time = date('Y-m-d', $start_time);
  186. // 可根据自己想要的返回格式进行调整
  187. $alltime[$i]['week'] = $week_array[date("w", strtotime($now_time))];
  188. $start_time = strtotime('+1 day', $start_time);
  189. $i++;
  190. }
  191. $list = [];
  192. foreach ($alltime as $key => $value) {
  193. //周日数组
  194. if ($value['week'] > 6) {
  195. $list[] = $value['week'];
  196. }
  197. }
  198. return count($list);
  199. }
  200. //检验订单的状态
  201. protected function checkOrderInfo($number){
  202. $nu = $this->fullorder->get_number($number);
  203. if(!$nu)
  204. {
  205. $nu = $this->fullordersmt->get_number($number);
  206. if(!$nu)
  207. {
  208. $nu = $this->fullordertt->get_number($number);
  209. }
  210. }
  211. //此单已取消!请联系店员核实
  212. if($nu['state'] == '214' || $nu['state'] == '217')
  213. {
  214. return 1;
  215. }
  216. //因为某些原因订单虽然现实是完成 但是实际上是终止了 所以就按照取消计算吧
  217. // if($nu['state'] == '216' || $nu['state'] == '215')
  218. // {
  219. // return 1;
  220. // }
  221. return 10;
  222. }
  223. }