Outerrors.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Outerrors extends Start_Controller{
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_outerrors','outerrors');
  8. $this->load->_model("Model_logic_order","logic_order");
  9. $this->load->_model("Model_check",'check');
  10. $this->load->_model("Model_express","express");
  11. $this->load->_model("Model_warehouse","warehouse");
  12. $this->load->_model('Model_whlabel','whlabel');
  13. $this->load->_model("Model_logic_express","logic_express");
  14. $this->load->_model("Model_ck",'ck');
  15. $this->load->_model("Model_shop","shop");
  16. $this->load->_model('Model_specialstock','specialstock');
  17. $this->load->_model('Model_fullorder','fullorder');
  18. $this->load->_model('Model_fullordersmt','fullordersmt');
  19. $this->load->_model('Model_fullordertt','fullordertt');
  20. $this->load->_model('Model_fullorderamz','fullorderamz');
  21. $this->load->_model('Model_dhl','dhl');
  22. $this->load->_model('Model_dhlhz','dhlhz');
  23. $this->load->_model('Model_typeclass','typeclass');
  24. }
  25. //定义方法的调用规则 获取URI第二段值
  26. public function _remap($arg,$arg_array)
  27. {
  28. if($arg == 'scan')//出库页
  29. {
  30. $this->_scan();
  31. }
  32. else if($arg == 'operate')//出库列表页
  33. {
  34. $this->_operate();
  35. }
  36. else if($arg == 'excel'){
  37. $this->_excel();
  38. }
  39. else
  40. {
  41. $this->_index();
  42. }
  43. }
  44. private function _index()
  45. {
  46. if($this->input->method() === 'post'){
  47. $page = $this->input->post('page',true);
  48. $perpage = $this->input->post('perpage',true);
  49. $number = $this->input->post('number',true);
  50. $timetk = $this->input->post('timetk',true);
  51. $timetj = $this->input->post('timetj',true);
  52. $timetk = strtotime($timetk);
  53. $timetj = strtotime($timetj);
  54. $where = "";
  55. if($number){
  56. $where .= " number = '$number' ";
  57. }
  58. if(empty($where)){
  59. $where = " scan_time > '$timetk' and scan_time < '$timetj' ";
  60. }else{
  61. $where .= " and scan_time > '$timetk' and scan_time < '$timetj' ";
  62. }
  63. //数据排序
  64. $order_str = " id desc";
  65. if(empty($page))
  66. {
  67. $start = 0;
  68. $perpage = 1;
  69. }
  70. else
  71. {
  72. $start = ($page - 1)*$perpage;
  73. }
  74. $list = $this->outerrors->find_all($where,"*",$order_str,$start,$perpage);
  75. $info_list = [];
  76. foreach($list as $k => $v){
  77. $str = "";
  78. if(empty($v['dy_status'])){
  79. $str .= "<p ><b style='font-size:18px !important' data-id='".$v['id']."' data-type='1' onclick='dycz(this)'>店员操作</b></p>";
  80. }
  81. if(!empty($v['dy_status']) && empty($v['ck_status'])){
  82. $str .= "<p><b style='font-size:18px !important;background-color: #FFC125;color: #000;' data-id='".$v['id']."' data-type='2' onclick='dycz(this)'>仓库操作</b></p>";
  83. }
  84. $info_list[] = [
  85. 'id' => $v['id'],
  86. 'scan_time' => date('Y-m-d H:i:s',$v['scan_time']),
  87. 'number' => $v['number'],
  88. 'dy_status'=>empty($v['dy_status'])?'':$v['dy_operate'],
  89. 'ck_status' => empty($v['ck_status'])?'':$v['ck_operate'],
  90. 'remark'=>empty($v['remark'])?'':$v['remark'],
  91. 'opreate'=>$str
  92. ];
  93. }
  94. $total = $this->outerrors->find_count($where);
  95. $pagenum = ceil($total/$perpage);
  96. $over = $total-($start+$perpage);
  97. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  98. echo json_encode($rows);exit;
  99. }
  100. $this->_Template('outerrors',$this->data);
  101. }
  102. private function _operate(){
  103. if($this->input->method() === 'post'){
  104. $id = $this->input->post('id',true);
  105. $type = $this->input->post('operate_type',true);
  106. $remark = $this->input->post('operate_remark',true);
  107. if($type == 1){
  108. $arr = [
  109. 'dy_status'=>1,
  110. 'dy_operate'=>$remark,
  111. 'dy_time'=>time(),
  112. ];
  113. }else if($type == 2){
  114. $arr = [
  115. 'ck_status'=>1,
  116. 'ck_operate'=>$remark,
  117. 'ck_time'=>time(),
  118. ];
  119. }else{
  120. echo json_encode(['code'=>-1,'msg'=>'执行类型异常']);exit;
  121. }
  122. if($this->outerrors->save($arr,$id)){
  123. echo json_encode(['code'=>1,'msg'=>'操作成功']);exit;
  124. }else{
  125. echo json_encode(['code'=>-1,'msg'=>'操作失败']);exit;
  126. }
  127. }
  128. echo json_encode(['code'=>-1,'msg'=>'参数异常']);exit;
  129. }
  130. //excel 下载
  131. private function _excel(){
  132. if($this->input->method() === 'get'){
  133. $excel = $this->input->get('excel',true);
  134. if($excel == 2){
  135. $number = $this->input->get('number',true);
  136. $timetk = $this->input->get('timetk',true);
  137. $timetj = $this->input->get('timetj',true);
  138. $timetk = strtotime($timetk);
  139. $timetj = strtotime($timetj);
  140. $where = "";
  141. if($number){
  142. $where .= " number = '$number' ";
  143. }
  144. if(empty($where)){
  145. $where = " scan_time > '$timetk' and scan_time < '$timetj' ";
  146. }else{
  147. $where .= " and scan_time > '$timetk' and scan_time < '$timetj' ";
  148. }
  149. $list = $this->outerrors->find_all($where,"*");
  150. $info_list = [];
  151. foreach($list as $k => $v){
  152. $info_list[] = [
  153. 'id' => $v['id'],
  154. 'number' => $v['number'],
  155. 'dy_operate'=>$v['dy_operate'],
  156. 'ck_operate' => $v['ck_operate'],
  157. 'remark'=>empty($v['remark'])?'':$v['remark'],
  158. 'scan_time' => date('Y-m-d H:i:s',$v['scan_time']),
  159. 'dy_time'=>empty($v['dy_time'])?'':date('Y-m-d H:i:s',$v['dy_time']),
  160. 'ck_time'=>empty($v['ck_time'])?'':date('Y-m-d H:i:s',$v['ck_time']),
  161. ];
  162. }
  163. $filename = date("Y-m-d")."扫不出库记录.xls";
  164. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  165. <head>
  166. <!--[if gte mso 9]><xml>
  167. <x:ExcelWorkbook>
  168. <x:ExcelWorksheets>
  169. <x:ExcelWorksheet>
  170. <x:Name>EXCEL</x:Name>
  171. <x:WorksheetOptions>
  172. <x:Print>
  173. <x:ValidPrinterInfo />
  174. </x:Print>
  175. </x:WorksheetOptions>
  176. </x:ExcelWorksheet>
  177. </x:ExcelWorksheets>
  178. </x:ExcelWorkbook>
  179. </xml>
  180. <![endif]-->
  181. </head><body>";
  182. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  183. $str .= "<tr><td>订单编码</td><td>店员操作</td><td>仓库操作</td><td>不能出库原因</td><td>扫描时间</td><td>店员操作时间</td><td>仓库操作时间</td></tr>";
  184. foreach ($info_list as $key=>$value)
  185. {
  186. $str .= "<tr>";
  187. $str .= "<td>". $value['number']. "</td>";
  188. $str .= "<td>". $value['dy_operate']. "</td>";
  189. $str .= "<td>". $value['ck_operate']. "</td>";
  190. $str .= "<td>". $value['remark']. "</td>";
  191. $str .= "<td>". $value['scan_time']. "</td>";
  192. $str .= "<td>". $value['dy_time']. "</td>";
  193. $str .= "<td>". $value['ck_time']. "</td>";
  194. $str .= "</tr>";
  195. }
  196. $str .= "</table></body></html>";
  197. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  198. header( "Content-type: application/octet-stream" );
  199. header( "Content-Disposition: attachment; filename=".$filename );
  200. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  201. header( "Pragma: no-cache" );
  202. header( "Expires: 0" );
  203. exit($str);
  204. }
  205. }
  206. }
  207. //扫描未出库的单子
  208. private function _scan(){
  209. if($this->input->method() === 'post'){
  210. $waybill = $this->input->post('waybill',true);
  211. $weight = $this->input->post('weight',true);
  212. if(empty($waybill)){
  213. echo json_encode(['code'=>-1,'msg'=>'快递单号不能为空']);exit;
  214. }
  215. $info = $this->logic_order->getInfo("waybill = '$waybill'");
  216. $outtype = 1;
  217. if(empty($info)){
  218. $info = $this->logic_order->getInfo("oldwaybill like '%/".$waybill."%'");
  219. }
  220. if(empty($info)){
  221. $outtype = 2;
  222. $info = $this->logic_order->getInfo("number = '$waybill'");
  223. }
  224. if(empty($info)){
  225. echo json_encode(['code'=>-1,'msg'=>'未发现和 '.$waybill.' 关联的订单信息']);exit;
  226. }
  227. $r = $this->_outerrorinfo($info,$weight,$outtype);
  228. if($r['success']){
  229. echo json_encode(['code'=>-1,'msg'=>$r['msg']]);exit;
  230. }
  231. $arr = [
  232. 'number'=>$info['number'],
  233. 'waybill'=>$waybill,//扫描单号
  234. 'plat'=>$info['lv_platform'],
  235. 'shop'=>$info['shop'],
  236. 'remark'=>$r['msg'],
  237. 'scan_time'=>time(),
  238. ];
  239. if($this->outerrors->insert($arr)){
  240. echo json_encode(['code'=>1,'msg'=>'扫描成功']);exit;
  241. }else{
  242. echo json_encode(['code'=>-1,'msg'=>'操作失败']);exit;
  243. }
  244. }
  245. $this->_Template('outerrors_scan',$this->data);
  246. }
  247. //出库错误的原因返回
  248. private function _outerrorinfo($info,$weight,$outtype){
  249. $time = time();
  250. if(!isset($weight))//测试没问题后可以删
  251. {
  252. $weight = '';
  253. }
  254. $y = $info;
  255. $fullorder_name = $y['lv_platform'];
  256. if($y['mergeid'] == '1')
  257. {
  258. $y = $this->$fullorder_name->read($y['merge']);
  259. }
  260. // 66 云途(欧洲) 67 云途(欧洲)-带保险 如果是欧洲云途 需要检擦出库时间是否超过15天
  261. if(in_array($y['express'],[66,67,82])){
  262. if((time() - $y['printtime']) >= (14*24*3600)){
  263. return array('msg'=>'运单超时!请联系梦体处理!','success'=>false);
  264. //echo json_encode(array('msg'=>'运单超时!请联系梦体处理!','success'=>false));exit;
  265. }
  266. }
  267. // 78 dpd英国 和 79dpd欧盟
  268. if(in_array($y['express'],[78,79,84])){
  269. $r = $this->check->checkOverdue($y['name'],$y['number'],$y['address']);
  270. if(!$r){
  271. return array('msg'=>'同一个客户3天内发货超过2包,不可出库!请联系店员做申报信息修改!'.$y['name']."-".$y['number']."-".$r*1,'success'=>false);
  272. //echo json_encode(array('msg'=>'同一个客户3天内发货超过2包,不可出库!请联系店员做申报信息修改!'.$y['name']."-".$y['number']."-".$r*1,'success'=>false));exit;
  273. }
  274. }
  275. $express = $this->express->read($y['express']);
  276. if($y['state'] == 216 && $fullorder_name == 'fullordersmt')
  277. {
  278. $y['librarynot'] = '客户已取消!';
  279. }
  280. if($y['print'] != 3 || $y['libraryconfirm'] == 1 || $y['state'] == 214 || $y['state'] == 217 || $y['state'] == 283 || $y['state'] == 206 || $y['state'] == 205 || $y['state'] == 204 || $y['state'] == 210 || $y['state'] == 211 || $y['state'] == 212 || ($y['state'] == 216 && $fullorder_name == 'fullordersmt'))//独立站216先关了
  281. {
  282. return array('msg'=>'禁止出库!'.$y['librarynot'],'success'=>false);
  283. //echo json_encode(array('msg'=>'禁止出库!'.$y['librarynot'],'success'=>false));exit;
  284. }
  285. if($y['library'] > 1)
  286. {
  287. return array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作出库','success'=>false);
  288. // echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit;
  289. }
  290. if($express['out'] != 3)
  291. {
  292. if($express['out'] != $outtype)
  293. {
  294. $smlx = ($express['out']=='1')?'运单':'发货单';
  295. return array('msg'=>'扫描类型错误!此单需要扫描'.$smlx,'success'=>false);
  296. //echo json_encode(array('msg'=>'扫描类型错误!此单需要扫描'.$smlx,'success'=>false));exit;
  297. }
  298. }
  299. if($y['type'] != 7 && $y['waybill'] != '' && $y['printtype'] == '1')
  300. {
  301. $r = $this->logic_express->ydCheckById($y['waybill'],$y['express']);
  302. if(!$r){
  303. return array('msg'=>'出库物流和系统不匹配,请联系梦体解决'.$y['express'],'success'=>false);
  304. //echo json_encode(array('msg'=>'出库物流和系统不匹配,请联系梦体解决'.$y['express'],'success'=>false));exit;
  305. }
  306. }
  307. if(stripos($weight,',') !== false){
  308. $tmp_arr = explode(",",$weight);
  309. $weight = end($tmp_arr);
  310. $numweight = (float)$weight;
  311. $weight = $numweight."kg";
  312. }
  313. $numweight = str_replace('kg','',$weight);
  314. //根据要求 USPS-USA 2 FEDEX-US2 63 USPS-US2 64 这三个快递方式除外的所有快递都需要称重再发货 或者说是【国内发货】的都需要称重
  315. //还有翔文仓库的 不执行
  316. //源代码是
  317. //所有快递必须称重
  318. //所有快递必须称重 翔文除外
  319. //$this->logic_ding->sendToDing("检测订单".$y['number']."称重".$numweight."快递公司".$y['express']."-".$weight."[".$numweight."]");
  320. if(!in_array($y['express'],[2,8,39,43,44,45,47,48,49,55,61,63,64,65,74,81,83,85])){
  321. if($weight == '' || $numweight < '0.1' || !is_numeric($numweight))
  322. {
  323. return array('msg'=>'此单需要称重!','success'=>false);
  324. //echo json_encode(array('msg'=>'此单需要称重!','success'=>false));exit;
  325. }
  326. $yzweight = explode('.',$numweight);
  327. if($yzweight[0] == '')
  328. {
  329. return array('msg'=>'重量错误,请重新称重!','success'=>false);
  330. //echo json_encode(array('msg'=>'重量错误,请重新称重!','success'=>false));exit;
  331. }
  332. if(empty($numweight)){
  333. return array('msg'=>'此单需要称重2!','success'=>false);
  334. //echo json_encode(array('msg'=>'此单需要称重2!','success'=>false));exit;
  335. }
  336. }
  337. $express_info = $this->express->read($y['express']);
  338. if(empty($express_info)){
  339. return array('msg'=>'快递信息异常,请联系技术!','success'=>false);
  340. }
  341. $weight_limit = $express_info['weight_limit']*1;
  342. if($weight_limit > 0 && $y['type'] != 5){
  343. $yzweight = explode('.',$numweight);
  344. if($yzweight[0] == '')
  345. {
  346. return array('msg'=>'重量错误,请重新称重!','success'=>false);
  347. }
  348. if($numweight < ($y['jweight']/1000)){
  349. return array('msg'=>'重量小于净重,请重新称重!','success'=>false);
  350. }
  351. //Fedex(杭州),UPS,DHL官方-美国 需要判断实际重量和净重差 其他快递不需要
  352. if(in_array($y['express'],[3,24,42])){
  353. //规定实际重量不允许超过 净重为1kg
  354. if($numweight -($y['jweight']/1000) > 1 )
  355. {
  356. return array('msg'=>'称重重量和净重相差过大,请找成会处理!','success'=>false);
  357. }
  358. }
  359. if($weight_limit < $numweight){
  360. return array('msg'=>$express['servicename'].'大于'.$weight_limit.'公斤需要拆包!','success'=>false);
  361. }
  362. }
  363. if(((time() - $y['printtime']) > (15*24*3600) || $y['printtime'] < 1590211800) && $y['express'] == '24' && $y['type'] != 6)//杭州店铺除外
  364. {
  365. //echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  366. }
  367. if((time() - $y['printtime']) > (6*24*3600) && $y['express'] == '3' && $y['type'] != 6)//杭州店铺除外
  368. {
  369. //echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  370. return array('msg'=>'此运单过期无法出库,请联系成会处理!','success'=>false);
  371. }
  372. if((time() - $y['printtime']) > (7*24*3600) && $y['express'] == '37' && $y['type'] != 6)//杭州店铺除外
  373. {
  374. //echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  375. }
  376. $this->db->trans_begin();
  377. $warehouse = $this->warehouse->read($y['type']);
  378. $bdck = $warehouse['bdck'];
  379. if($warehouse['zd'] == '1')
  380. {
  381. if($warehouse['bdck'] == '')
  382. {
  383. $this->db->trans_rollback();
  384. return array('msg'=>'仓库设置错误!','success'=>false);
  385. }
  386. $wh = $this->_fout_db($y,$warehouse,$bdck);
  387. if($wh['fh'] == 2)
  388. {
  389. $kcyz = $this->ck->get_kc($y['state'],$warehouse,$y['shop'],$y['number'],$y['whlabel'],$y['fpdata']);
  390. if($kcyz['t'] == '0')
  391. {
  392. if($kcyz['fpdata'] != '')
  393. {
  394. $x['whlabel'] = $kcyz['whlabel'];
  395. $x['fpdata'] = $kcyz['fpdata'];
  396. $y['whlabel'] = $x['whlabel'];
  397. $this->$fullorder_name->save($x,$y['id']);
  398. }
  399. }
  400. $wh = $this->_fout_db($y,$warehouse,$bdck);
  401. if($wh['fh'] == 2)
  402. {
  403. $this->db->trans_rollback();
  404. return array('msg'=>'库存占用量与实际出库量不符!','success'=>false);
  405. }
  406. }
  407. foreach ($wh['sj'] as $v)
  408. {
  409. $this->$bdck->save(array('state'=>1,'cktype'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$v['id']);
  410. }
  411. }
  412. $shop = $this->shop->read($y['shop']);
  413. if($express['printcode'] == "DHLUSA" && $y['waybill'] != '')
  414. {
  415. $type = $this->typeclass->read($shop['type']);
  416. $y['shoptype'] = $type['title'];
  417. $y['weight'] = $weight;
  418. $d = $this->dhl->get_data_9610($y);
  419. if($d != 1)
  420. {
  421. $this->db->trans_rollback();
  422. return array('msg'=>'9610失败,'.$d,'success'=>false);
  423. }
  424. }
  425. if($fullorder_name == 'fullordersmt')
  426. {
  427. $stt = ($y['waybill']!='')?209:$y['state'];
  428. $post = array('library'=>2,'state'=>$stt,'librarytime'=>$time,'weight'=>$weight,'dbapi'=>0);
  429. }
  430. else if(($fullorder_name == 'fullordertt' || $fullorder_name == 'fullorderxw' || $fullorder_name == 'fullorder' || $fullorder_name = 'fullorderamz') && $y['source'] == 1)
  431. {
  432. $post = array('library'=>2,'state'=>216,'librarytime'=>$time,'weight'=>$weight,'dbapi'=>0);
  433. }
  434. else
  435. {
  436. $post = array('library'=>2,'librarytime'=>$time,'weight'=>$weight,'dbapi'=>0);
  437. }
  438. if($outtype == 2 && $y['printnumber'] > 1)
  439. {
  440. $p = json_encode($post);
  441. $this->db->trans_rollback();
  442. return array('msg'=>'该单共打印过'.$y['printnumber'].'次,请注意核对当前发货单是否是最新发货单!','outnumber'=>$y['id'],'post'=>$p,'fullorder_name'=>$fullorder_name,'success'=>false);
  443. }
  444. $this->db->trans_rollback();
  445. return array('msg'=>'此单允许出库 !!!','success'=>true);
  446. //$this->$fullorder_name->save($post,$y['id']);
  447. }
  448. private function _fout_db($y,$warehouse,$bdck)//对比占单是否正确
  449. {
  450. $wh = $this->$bdck->find_all("zd = '".$y['number']."' and warehouse = '".$y['type']."' and (state = '0' or state = '9')");
  451. $cpsl = 0;
  452. $pp = explode('|',trim($y['whlabel'],'|'));
  453. foreach ($pp as $va)
  454. {
  455. $num = explode('-',$va);
  456. if(isset($num[2]))
  457. {
  458. if(stripos($num[2],$warehouse['hz']) !== false)
  459. {
  460. $cpsl += $num[1];
  461. }
  462. }
  463. }
  464. if(count($wh) == $cpsl)
  465. {
  466. return array('fh'=>1,'sj'=>$wh);
  467. }
  468. else
  469. {
  470. return array('fh'=>2);
  471. }
  472. }
  473. }