Model_specialstock.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Model_Specialstock extends Lin_Model
  3. {
  4. function __construct(){
  5. parent::__construct();
  6. $this->load->database();
  7. $this->table = 'specialstock';
  8. $this->load_table('specialstock');
  9. }
  10. public function get_features($features)
  11. {
  12. return $this->find("features = '$features'");
  13. }
  14. public function get_supplier($supplier)
  15. {
  16. return $this->find("supplier = '$supplier'");
  17. }
  18. public function get_sku($sku)
  19. {
  20. return $this->find("sku = '$sku'");
  21. }
  22. public function get_enter($enter)
  23. {
  24. return $this->find("enter = '$enter'");
  25. }
  26. public function get_number($number)
  27. {
  28. return $this->find("number = '$number'");
  29. }
  30. public function get_cxzd($number,$zd)
  31. {
  32. return $this->find("number = '$number' and zd = '$zd'");
  33. }
  34. public function get_numberout($number,$warehouse)
  35. {
  36. return $this->find("state = '0' and number = '$number' and warehouse = '$warehouse'");
  37. }
  38. public function get_labelnumberout($shop,$number,$warehouse)
  39. {
  40. return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and zd = ''");
  41. }
  42. public function get_labelnumberout_purchase($shop,$number,$warehouse,$purchase)
  43. {
  44. return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and purchase = '$purchase' and zd = ''");
  45. }
  46. public function get_labelnumberout_purchase_nopur($shop,$number,$warehouse)
  47. {
  48. return $this->find("state = '0' and shop = '$shop' and number = '$number' and warehouse = '$warehouse' and zd = ''");
  49. }
  50. public function get_numberret($number,$warehouse,$orderinfo,$waybill)
  51. {
  52. return $this->find("state = 1 and number = '$number' and warehouse = '$warehouse' and orderinfo = '$orderinfo' and waybill = '$waybill'");
  53. }
  54. public function get_label($label)
  55. {
  56. return $this->find("label = '$label'");
  57. }
  58. public function get_title($title)
  59. {
  60. return $this->find("title like '%$title%'");
  61. }
  62. public function get_kcyz($number,$warehouse)//库存验证 检查库存是否充足----//这个判断和出库不一样!
  63. {
  64. $save = array();$x=0;
  65. $pp = explode('|',trim($number,'|'));
  66. foreach ($pp as $va)
  67. {
  68. $ckcg = 0;
  69. $num = explode('-',$va);
  70. for($i=0;$i<$num[1];$i++)
  71. {
  72. $whlabel = $this->get_numberout($num[0],$warehouse);
  73. if(!$whlabel)
  74. {
  75. $ckcg++;
  76. }
  77. }
  78. if($ckcg > 0)
  79. {
  80. $save[] = $x;
  81. }
  82. $x++;
  83. }
  84. if(count($save) > 0)
  85. {
  86. return $save;
  87. }
  88. else
  89. {
  90. return 1;
  91. }
  92. }
  93. public function get_kc($oldstate,$state,$whlabel,$oldwhlabel='',$number)//库存验证 提交订单时验证
  94. {
  95. /**
  96. if($oldwhlabel == $whlabel && $state == $oldstate)//如果没有改变仓库和产品和状态直接返回通过
  97. {
  98. return array('t'=>0);exit;
  99. }
  100. **/
  101. if(stripos($whlabel,'z|') === false && stripos($oldwhlabel,'z|') === false)//如果新老产品都不含特殊库存
  102. {
  103. return array('t'=>0);exit;
  104. }
  105. if(!$whlabel || $whlabel == '|')
  106. {
  107. return array('t'=>0);exit;
  108. }
  109. //先预先判断开始,否则清除数据后造成库存错误
  110. if(stripos($whlabel,'z|') !== false && ($state == '207' || $state == '209'))//待发货状态
  111. {
  112. $pp = explode('|',trim($whlabel,'|'));
  113. $x = 0;$save = array();
  114. foreach ($pp as $va)
  115. {
  116. $x++;
  117. $num = explode('-',$va);
  118. if(stripos($num[2],'z') !== false)//如果是特殊库存
  119. {
  120. $wh = $this->specialstock->find_count("state = '0' and number = '$num[0]' and (zd = '$number' or zd = '')");//通用
  121. if($wh < $num[1])
  122. {
  123. $save[] = $x-1;continue;//提前先加X不然出错,所以要减1
  124. }
  125. }
  126. }
  127. if(isset($save[0]))//非预设仓库提醒
  128. {
  129. return array('t'=>1,'m'=>json_encode(array('t'=>2,'msg'=>"红色商品名库存匹配错误或库存不够扣减",'error'=>$save,'success'=>false)));exit;
  130. }
  131. }
  132. $this->db->trans_begin();
  133. //预先判断结束
  134. //if($oldwhlabel != $whlabel || $state != $oldstate)
  135. //{
  136. $wl = $this->specialstock->find_all("zd = '$number'");//查找是否有占用库存情况features
  137. if($wl)//如果有那么清除所有占用
  138. {
  139. $i = 0;
  140. foreach ($wl as $v)
  141. {
  142. $this->specialstock->save(array('zd'=>''),$v['id']);//专属
  143. $i++;
  144. }
  145. if($i != count($wl))
  146. {
  147. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>"库存操作失败,请重试",'oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit;
  148. }
  149. }
  150. //}
  151. if(stripos($whlabel,'z|') !== false && isset($pp[0]) && ($state == '207' || $state == '209'))
  152. {
  153. foreach ($pp as $va)
  154. {
  155. $num = explode('-',$va);
  156. if(stripos($num[2],'z') !== false)//如果是特殊库存
  157. {
  158. $whlabel = $this->specialstock->find_all("state = '0' and number = '$num[0]' and zd = ''");//通用
  159. $xzkc = $this->specialstock->read(rtrim($num[2],'z'));//选择的这个库存
  160. if($xzkc['zd'] != '')
  161. {
  162. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'所选库存已被占单!请重新打开选择页面','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit;
  163. }
  164. $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),rtrim($num[2],'z'));//通用
  165. for($i=0;$i<$num[1]-1;$i++)
  166. {
  167. $this->specialstock->save(array('zd'=>$number,'zdlist'=>date('Y-m-d H:i:s',time())),$whlabel[$i]['id']);//通用
  168. }
  169. }
  170. }
  171. }
  172. if ($this->db->trans_status() === TRUE)
  173. {
  174. $this->db->trans_commit();
  175. return array('t'=>0);exit;
  176. }
  177. else
  178. {
  179. $this->db->trans_rollback();
  180. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'库存操作错误,请重试!','oldwarehouse'=>$oldwarehouse-1,'success'=>false)));exit;
  181. }
  182. }
  183. } //end class