Model_ck.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Model_ck extends Lin_Model
  3. {
  4. function __construct(){
  5. parent::__construct();
  6. $this->load_table('setting');
  7. $this->load->_model("Model_logic_ding","logic_ding");
  8. }
  9. public function get_kcyz($state,$warehouse,$shop,$number,$whlabel,$fpdata)//库存验证
  10. {
  11. $save = array();$x=0;
  12. $pp = explode('|',trim($number,'|'));
  13. if($warehouse['zd'] == 1 && $warehouse['bdck'] != '')
  14. {
  15. $n = 'get_'.$warehouse['bdck'];
  16. $y = $this->$n($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=1);
  17. return $y;
  18. }
  19. }
  20. public function get_kc($state,$warehouse,$shop,$number,$whlabel,$fpdata)//库存操作开始
  21. {
  22. if(!preg_match('/[0-9]/',$whlabel))
  23. {
  24. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit;
  25. }
  26. $wl = $this->specialstock->find_all("zd = '$number'");
  27. if($wl)
  28. {
  29. foreach ($wl as $v)
  30. {
  31. $this->specialstock->save(array('zd'=>''),$v['id']);//专属
  32. }
  33. }
  34. //非待发货和客户待收货状态以及仓库不占单
  35. if(($state != '207' && $state != '209') || $warehouse['zd'] == 0)//待发货状态
  36. {
  37. $wlw = $this->whlabel->find_all("zd = '$number'");
  38. if($wlw)
  39. {
  40. foreach ($wlw as $v)
  41. {
  42. $this->whlabel->save(array('zd'=>''),$v['id']);//专属
  43. }
  44. }
  45. }
  46. $fhw = '|';$j = 0;
  47. $fd = explode(';',trim($fpdata,';'));
  48. $wcfpd = '';
  49. $pp = explode('|',trim($whlabel,'|'));
  50. if($warehouse['bdck'] == 'specialstock' && ($state == '207' || $state == '209'))//特殊仓含特殊产品的不处理whlabel和fpdata 但需要状态符合
  51. {
  52. foreach ($pp as $v)
  53. {
  54. if(stripos($v,$warehouse['hz']) === false)
  55. {
  56. $num = explode('-',$v);
  57. $fhw .= $num[0].'-'.$num[1].'-0|';
  58. $cffpt = explode('|',trim($fd[$j],'|'));
  59. $cffpt[9] = 0;
  60. $wcfpd .= implode("|",$cffpt).';';
  61. }
  62. else
  63. {
  64. $fhw .= $v.'|';
  65. $wcfpd .= $fd[$j].';';
  66. }
  67. $j++;
  68. }
  69. }
  70. else
  71. {
  72. foreach ($pp as $v)
  73. {
  74. $num = explode('-',$v);
  75. if(isset($num[2]) && $num[2] == 'DNOTO')//选择不占单的
  76. {
  77. $fhw .= $v.'|';
  78. $wcfpd .= $fd[$j].';';
  79. }
  80. else
  81. {
  82. if(!isset($fd[$j])){
  83. $this->logic_ding->sendToDing("Modelck错误排查:".json_encode($fd,JSON_UNESCAPED_UNICODE)."||".json_encode($pp,JSON_UNESCAPED_UNICODE));
  84. }
  85. $fhw .= $num[0].'-'.$num[1].'-0|';
  86. $cffpt = explode('|',trim($fd[$j],'|'));
  87. $cffpt[9] = 0;
  88. $wcfpd .= implode("|",$cffpt).';';
  89. }
  90. $j++;
  91. }
  92. }
  93. $whlabel = $fhw;
  94. $fpdata = $wcfpd;
  95. if($warehouse['zd'] == 1 && $warehouse['bdck'] != '')
  96. {
  97. $n = 'get_'.$warehouse['bdck'];
  98. $z = $this->$n($state,$warehouse,$shop,$number,$whlabel,$fpdata);
  99. return $z;exit;
  100. }
  101. else
  102. {
  103. return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit;
  104. }
  105. }
  106. public function get_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=0)
  107. {
  108. //smt:edit-bcbz-readonly-customersmt_medit,dlz:edit-readonly-customer_medit
  109. if(!$whlabel || $whlabel == '|')
  110. {
  111. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit;
  112. }
  113. //先预先判断开始,否则清除数据后造成库存错误
  114. if($state == '207' || $state == '209')//待发货状态
  115. {
  116. $pp = explode('|',trim($whlabel,'|'));
  117. $cxsl = array();//产品数组化提供下面查询
  118. foreach ($pp as $key=>$va)
  119. {
  120. $w = explode('-',$va);
  121. if(!isset($w[2]))
  122. {
  123. $w[2] = 0;
  124. }
  125. $cxsl[$key] = $w;
  126. }
  127. $x = 0;$save = array();
  128. foreach ($pp as $key=>$va)
  129. {
  130. $num = explode('-',$va);
  131. if(!isset($num[2]) || isset($num[2]) && $num[2] != "DNOTO")
  132. {
  133. foreach ($cxsl as $k=>$v)
  134. {
  135. if($v[0] == $num[0] && $num[2] != "DNOTO" && $key != $k)
  136. {
  137. $num[1] += $v[1];//如果有相同产品并且未禁止占单,那么合并占单数量
  138. }
  139. }
  140. }
  141. $wh = $this->whlabel->find_count("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')");//通用
  142. $shopwh = $this->whlabel->find_count("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '$number' or zd = '') and shop like '%,".$shop.",%'");//专属
  143. $x++;
  144. if($wh+$shopwh < $num[1] || (isset($num[2]) && $num[2] == "DNOTO" && $warehouse['zdms'] == 2))
  145. {
  146. //$this->logic_ding->sendToDing("库存验证数据【".$number."】".json_encode($num)."库存数量:".($wh+$shopwh)."仓库的占单模式".$warehouse['zdms']);
  147. $save[] = $x-1;continue;//提前先加X不然出错,所以要减1
  148. }
  149. }
  150. //$this->logic_ding->sendToDing("库存验证数据2【".$number."】".json_encode($num)."库存数量:".($wh+$shopwh)."仓库的占单模式".$warehouse['zdms']."$".json_encode($save));
  151. if(isset($save[0]) && $warehouse['zdms'] == 2)
  152. {
  153. return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存不够扣减或不允许占单",'error'=>$save,'hq'=>"state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')",'success'=>false)));exit;
  154. }
  155. if($yz == 0)
  156. {
  157. $z = $this->get_whlabel_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata);
  158. return $z;
  159. }
  160. }
  161. else//订单状态不符合
  162. {
  163. return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit;
  164. }
  165. }
  166. public function get_whlabel_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata)
  167. {
  168. $fhw = '|';
  169. $fpdata = explode(';',trim($fpdata,';'));
  170. $wcfpd = '';
  171. $wlw = $this->whlabel->find_all("zd = '".$number."'");
  172. if($state == '207' || $state == '209')
  173. {
  174. $x = 0;
  175. $pp = explode('|',trim($whlabel,'|'));
  176. $wzdid = '';$szdid = '';$wfcid = array();
  177. foreach ($pp as $va)
  178. {
  179. $fhid = '';$DNOTO = 0;
  180. $num = explode('-',$va);
  181. if(isset($num[2]) && $num[2] == "DNOTO")
  182. {
  183. $DNOTO = 1;
  184. }
  185. $whlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '".$number."' or zd = '') and (shop IS NULL or shop = '')");//通用
  186. $shopwhlabel = $this->whlabel->find_all("state = '0' and number = '$num[0]' and warehouse = '".$warehouse['id']."' and (zd = '".$number."' or zd = '') and shop like '%,".$shop.",%'");//专属
  187. if(count($shopwhlabel) > 0 && $DNOTO < 1)//如果有专属库存
  188. {
  189. if(count($shopwhlabel) >= $num[1])
  190. {
  191. for($i=0;$i<$num[1];$i++)
  192. {
  193. $fhid .= $shopwhlabel[$i]['id'].$warehouse['hz'].'~';
  194. //$this->whlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//专属 ~符号这里改验货也需要改
  195. $wzdid .= 'id != '.$shopwhlabel[$i]['id'].' and ';
  196. $wfcid[] = $shopwhlabel[$i]['id'];
  197. }
  198. }
  199. else
  200. {
  201. for($i=0;$i<count($shopwhlabel);$i++)
  202. {
  203. $fhid .= $shopwhlabel[$i]['id'].$warehouse['hz'].'~';
  204. //$this->whlabel->save(array('zd'=>$number),$shopwhlabel[$i]['id']);//扣减专属
  205. $wzdid .= 'id != '.$shopwhlabel[$i]['id'].' and ';
  206. $wfcid[] = $shopwhlabel[$i]['id'];
  207. }
  208. for($i=0;$i<$num[1]-count($shopwhlabel);$i++)
  209. {
  210. if(isset($whlabel[$i]))
  211. {
  212. $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~';
  213. //$this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//扣减通用
  214. $wzdid .= 'id != '.$whlabel[$i]['id'].' and ';
  215. $wfcid[] = $whlabel[$i]['id'];
  216. }
  217. }
  218. }
  219. $fhw .= $num[0].'-'.$num[1].'-'.rtrim($fhid,'~')."|";
  220. $cffpt = explode('|',trim($fpdata[$x],'|'));
  221. $cffpt[9] = rtrim($fhid,'~');
  222. $wcfpd .= implode("|",$cffpt).';';
  223. }
  224. else if(count($whlabel) >= $num[1] && $DNOTO < 1)
  225. {
  226. for($i=0;$i<$num[1];$i++)
  227. {
  228. $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~';
  229. //$this->whlabel->save(array('zd'=>$number),$whlabel[$i]['id']);//通用
  230. $wzdid .= 'id != '.$whlabel[$i]['id'].' and ';
  231. $wfcid[] = $whlabel[$i]['id'];
  232. }
  233. $fhw .= $num[0].'-'.$num[1].'-'.rtrim($fhid,'~')."|";
  234. $cffpt = explode('|',trim($fpdata[$x],'|'));
  235. $cffpt[9] = rtrim($fhid,'~');
  236. $wcfpd .= implode("|",$cffpt).';';
  237. }
  238. else
  239. {
  240. $fhw .= $va."|";
  241. $wcfpd .= $fpdata[$x].';';
  242. }
  243. $x++;
  244. }
  245. }
  246. $this->db->trans_begin();
  247. if(isset($wlw[0]))
  248. {
  249. foreach ($wlw as $v)
  250. {
  251. $this->whlabel->save(array('zd'=>''),$v['id']);//专属
  252. }
  253. }
  254. if($wzdid != '')
  255. {
  256. foreach ($wfcid as $v)
  257. {
  258. $this->whlabel->save(array('zd'=>$number),$v);
  259. }
  260. }
  261. if ($this->db->trans_status() === FALSE)
  262. {
  263. $this->db->trans_rollback();
  264. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false)));
  265. }
  266. else
  267. {
  268. $this->db->trans_commit();
  269. return array('t'=>0,'whlabel'=>$fhw,'fpdata'=>$wcfpd);
  270. }
  271. }
  272. public function get_specialstock($state,$warehouse,$shop,$number,$whlabel,$fpdata,$yz=0)
  273. {
  274. if(!$whlabel || $whlabel == '|' || stripos($whlabel,$warehouse['hz']) === false)
  275. {
  276. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加特殊产品信息!','success'=>false)));exit;
  277. }
  278. //先预先判断开始,否则清除数据后造成库存错误
  279. if($state == '207' || $state == '209')//待发货状态
  280. {
  281. $pp = explode('|',trim($whlabel,'|'));
  282. $x = 0;$save = array();
  283. foreach ($pp as $va)
  284. {
  285. $x++;
  286. $num = explode('-',$va);
  287. if(stripos($va,$warehouse['hz']) !== false)
  288. {
  289. $wh = $this->specialstock->find_count("state = '0' and number = '$num[0]' and (zd = '$number' or zd = '')");//通用
  290. if($wh < $num[1])
  291. {
  292. $save[] = $x-1;continue;//提前先加X不然出错,所以要减1
  293. }
  294. }
  295. }
  296. if(isset($save[0]))
  297. {
  298. return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存不够扣减或不允许占单",'error'=>$save,'success'=>false)));exit;
  299. }
  300. if($yz == 0)
  301. {
  302. $z = $this->get_specialstock_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata);
  303. return $z;
  304. }
  305. }
  306. else//订单状态不符合
  307. {
  308. return array('t'=>0,'whlabel'=>$whlabel,'fpdata'=>$fpdata);exit;
  309. }
  310. }
  311. public function get_specialstock_zd($state,$warehouse,$shop,$number,$whlabel,$fpdata)
  312. {
  313. $fpdata = explode(';',trim($fpdata,';'));
  314. $wcfpd = '';
  315. $this->db->trans_begin();
  316. $wl = $this->whlabel->find_all("zd = '".$number."'");
  317. if($wl)
  318. {
  319. foreach ($wl as $v)
  320. {
  321. $this->whlabel->save(array('zd'=>''),$v['id']);//专属
  322. }
  323. }
  324. if($state == '207' || $state == '209')
  325. {
  326. $fhw = array();$x = 0;$wzdid = '';
  327. $pp = explode('|',trim($whlabel,'|'));
  328. foreach ($pp as $va)
  329. {
  330. $num = explode('-',$va);
  331. if(stripos($va,$warehouse['hz']) !== false)
  332. {
  333. $fhid = '';
  334. $num = explode('-',$va);
  335. $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用
  336. $fgzid = explode('~',trim($num[2],'~'));
  337. foreach ($fgzid as $vid)
  338. {
  339. $xzkc = $this->specialstock->read(rtrim($vid,$warehouse['hz']));//选择的这个库存
  340. if($xzkc['zd'] != '')
  341. {
  342. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'所选库存已被占单!请重新打开选择页面','success'=>false)));exit;
  343. }
  344. }
  345. for($i=0;$i<$num[1];$i++)
  346. {
  347. $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~';
  348. $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用
  349. $wzdid .= 'id != '.$whlabel[$i]['id'].' and ';
  350. }
  351. $fhw[] = $num[0].'-'.$num[1].'-'.rtrim($fhid,'~');
  352. $cffpt = explode('|',trim($fpdata[$x],'|'));
  353. $cffpt[9] = rtrim($fhid,'~');
  354. $wcfpd .= implode("|",$cffpt).';';
  355. }
  356. else
  357. {
  358. $fhw[] = $va;
  359. $wcfpd .= $fpdata[$x].';';
  360. }
  361. $x++;
  362. }
  363. $fhw = '|'.implode("|",$fhw).'|';
  364. }
  365. if ($this->db->trans_status() === TRUE)
  366. {
  367. $this->db->trans_commit();
  368. return array('t'=>0,'whlabel'=>$fhw,'fpdata'=>$wcfpd);exit;
  369. }
  370. else
  371. {
  372. $this->db->trans_rollback();
  373. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false)));exit;
  374. }
  375. }
  376. //预先判断仓开始
  377. public function get_yx_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata)//通用仓
  378. {
  379. $z = $this->get_whlabel($state,$warehouse,$shop,$number,$whlabel,$fpdata);
  380. return $z;
  381. }
  382. public function get_yx_specialstock($state,$warehouse,$shop,$number,$whlabel,$fpdata)//特殊仓
  383. {
  384. $pp = explode('|',trim($whlabel,'|'));
  385. $fpdata = explode(';',trim($fpdata,';'));
  386. $wcfpd = '';$fhw = array();
  387. $x = 0;$save = array();
  388. $kytskc = array();
  389. foreach ($pp as $k=>$va)
  390. {
  391. $num = explode('-',$va);
  392. $wh = $this->specialstock->find_count("state = '0' and number = '$num[0]' and zd = ''");
  393. if(!isset($num[1]))
  394. {
  395. $num[1] = 1;
  396. }
  397. if($wh >= $num[1])
  398. {
  399. $kytskc[] = $num[0].'-'.$num[1].'-z';//有可占用的
  400. }
  401. else
  402. {
  403. $kytskc[] = $num[0].'-'.$num[1].'-0';
  404. }
  405. }
  406. $y = 0;
  407. $this->db->trans_begin();
  408. foreach ($kytskc as $va)
  409. {
  410. $num = explode('-',$va);
  411. if(stripos($va,$warehouse['hz']) !== false)
  412. {
  413. $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用
  414. $fhid = '';
  415. for($i=0;$i<$num[1];$i++)
  416. {
  417. $fhid .= $whlabel[$i]['id'].$warehouse['hz'].'~';
  418. $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用
  419. }
  420. $fhw[] = $num[0].'-'.$num[1].'-'.rtrim($fhid,'~');
  421. $cffpt = explode('|',trim($fpdata[$x],'|'));
  422. $cffpt[9] = rtrim($fhid,'~');
  423. $wcfpd .= implode("|",$cffpt).';';
  424. $y++;
  425. }
  426. else
  427. {
  428. $fhw[] = $num[0].'-'.$num[1].'-0';
  429. $wcfpd .= $fpdata[$x].';';
  430. }
  431. $x++;
  432. }
  433. if($this->db->trans_status() === TRUE)
  434. {
  435. $this->db->trans_commit();
  436. return array('t'=>0,'whlabel'=>"|".implode("|",$fhw)."|",'fpdata'=>$wcfpd);exit;
  437. }
  438. else
  439. {
  440. $this->db->trans_rollback();
  441. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','success'=>false)));exit;
  442. }
  443. }
  444. //预先判断仓结束
  445. public function get_fl($hz,$whlabel,$fpdata)//特殊仓
  446. {
  447. $sfxh = 0;
  448. if($hz != '')
  449. {
  450. $num = explode('|',trim($whlabel,'|'));
  451. $bh = substr_count($whlabel,$hz);
  452. if($bh == count($num))
  453. {
  454. $sfxh = 1;//有现货
  455. }
  456. }
  457. $f = explode(';',trim($fpdata,';'));
  458. //$fl = substr_count($fpdata,'Bob');//暂时不用这个,防止产品出现大小写不一致
  459. $i = 0;
  460. foreach ($f as $v)
  461. {
  462. if(stripos($fpdata,'bob') !== false && (stripos($v,'bob') !== false || stripos($v,'wig') === false))
  463. {
  464. $i++;
  465. }
  466. }
  467. if(count($f) == $i)
  468. {
  469. $type = $this->typeclass->get_type('37','BOBTYPE');
  470. }
  471. else if(stripos($fpdata,'wig') !== false)
  472. {
  473. $type = $this->typeclass->get_type('37','WIGTYPE');
  474. }
  475. else
  476. {
  477. $type = $this->typeclass->get_type('37','OTHERTYPE');
  478. }
  479. $ckfl = $type['id'];
  480. return array('sfxh'=>$sfxh,'ckfl'=>$ckfl);
  481. }
  482. } //end class