Beihuogl.php 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Beihuogl extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_bhsq','bhsq');
  7. $this->load->_model("Model_shop","shop");
  8. $this->load->_model("Model_typeclass","typeclass");
  9. $this->load->_model("Model_bhccwl","bhccwl");
  10. $this->load->_model("Model_logic_u9tools","logic_u9tools");
  11. $this->load->_model("Model_whlabel","whlabel");
  12. $this->load->_model("Model_goods","goods");
  13. $this->load->_model("Model_settingtest","settingtest");
  14. $this->load->_model("Model_bhdcd","bhdcd");
  15. $this->load->_model("Model_whlabellabel","whlabellabel");
  16. }
  17. //定义方法的调用规则 获取URI第二段值
  18. public function _remap($arg,$arg_array)
  19. {
  20. if(!isset($_SESSION['api'])){
  21. header('Location: /');exit;
  22. }
  23. if($arg == 'dyapply')//
  24. {
  25. $this->_dyapply();
  26. }
  27. elseif($arg == 'dyapplyadd')//
  28. {
  29. $this->_dyapplyadd();
  30. }
  31. elseif($arg == 'dyapplyedit')//
  32. {
  33. $this->_dyapplyedit($arg_array);
  34. }
  35. elseif($arg == 'dyapplygxzt')//
  36. {
  37. $this->_dyapplygxzt();
  38. }
  39. elseif($arg == 'dyapplyexcel'){
  40. $this->_dyapplyexcel();
  41. }
  42. elseif($arg == 'ccwlshlist'){
  43. $this->_ccwlshlist();
  44. }
  45. elseif($arg == 'ccwlbhindex'){
  46. $this->_ccwlbhindex();
  47. }elseif($arg == 'dyapplysave'){
  48. $this->_dyapplysave();
  49. }elseif($arg == 'ccwlbhmake'){
  50. $this->_ccwlbhmake();
  51. }elseif($arg == 'ccwlbhedit'){
  52. $this->_ccwlbhedit($arg_array);
  53. }elseif($arg == 'ccwleditxzbh'){
  54. $this->_ccwleditxzbh();
  55. }elseif($arg == 'ccwlbhsavexzbh'){
  56. $this->_ccwlbhsavexzbh();
  57. }elseif($arg == 'ccwldelitem'){
  58. $this->_ccwldelitem();
  59. }elseif($arg == 'ccwlbhsave'){
  60. $this->_ccwlbhsave();
  61. }elseif($arg == 'ckbhindex'){
  62. $this->_ckbhindex();
  63. }elseif($arg == 'ckbhedit'){
  64. $this->_ckbhedit($arg_array);
  65. }elseif($arg == 'makeu9scd'){
  66. $this->_makeu9scd($arg_array);
  67. }elseif($arg == 'showckbh'){
  68. $this->_showckbh($arg_array);
  69. }elseif($arg == 'ddscscd'){
  70. $this->_ddscscd();
  71. }elseif($arg == 'ckdcd'){
  72. $this->_ckdcd();
  73. }elseif($arg == 'ckbherprk'){
  74. $this->_ckbherprk($arg_array);
  75. }elseif($arg == 'bhdcdsave'){
  76. $this->_bhdcdsave();
  77. }elseif($arg == 'u9scdexcel')
  78. {
  79. $this->_u9scdexcel($arg_array);
  80. }elseif($arg == 'ccwlskucheck'){
  81. $this->_ccwlskucheck();
  82. }elseif($arg == 'printlabel'){
  83. $this->_printlabel();
  84. }elseif($arg == 'deldyapply'){
  85. $this->_deldyapply();
  86. }elseif($arg == 'dcdjzrk'){
  87. $this->_dcdjzrk();
  88. }
  89. else
  90. {
  91. $this->_index();
  92. }
  93. }
  94. private function _index(){
  95. exit('No direct script access allowed 1');
  96. }
  97. //备货申请单的列表
  98. private function _dyapply(){
  99. if($this->input->method() === 'post'){
  100. $vip_id = $this->input->post('vip_id',true);
  101. $page = $this->input->post('page',true);
  102. $perpage = $this->input->post('perpage',true);
  103. $sqr = $this->input->post('sqr',true);
  104. $sqr = trim($sqr);
  105. $shop_id = $this->input->post('shop_id',true);
  106. $plat_id = $this->input->post('plat_id',true);
  107. $shop_ids = $this->input->post('shop_ids',true);
  108. $ktime = $this->input->post('ktime',true);
  109. $jtime = $this->input->post('jtime',true);
  110. $ktime = strtotime($ktime);
  111. $jtime = strtotime($jtime);
  112. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  113. if(!empty($sqr)){
  114. $where .= " and sqr = '".$sqr."' ";
  115. }
  116. if($shop_id > -1){
  117. $where .= " and shop_id = ".$shop_id." ";
  118. }else{
  119. if($vip_id == 1){
  120. }else{
  121. $where .= " and shop_id in (".$shop_ids.") ";
  122. }
  123. }
  124. if($plat_id > -1){
  125. $where .= " and plat_id = ".$plat_id." ";
  126. }
  127. //数据排序
  128. $order_str = "id desc";
  129. if(empty($page))
  130. {
  131. $start = 0;
  132. $perpage = 1;
  133. }
  134. else
  135. {
  136. $start = ($page - 1)*$perpage;
  137. }
  138. $list = $this->bhsq->find_all($where,"id,shop_id,plat_id,title,sku,sqr,sq_num,sq_status,add_time,update_time",$order_str,$start,$perpage);
  139. if(empty($list)){
  140. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  141. echo json_encode($rows);exit;
  142. }
  143. $shop_list = $this->shop->find_all("1=1","id,shopname");
  144. $shop_list = array_column($shop_list,'shopname','id');
  145. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  146. $plat_list = array_column($plat_list,'title','id');
  147. $status_list = $this->bhsq->getSqStatus();
  148. foreach($list as $k=>$v){
  149. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  150. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  151. $list[$k]['sq_status'] = isset($status_list[$v['sq_status']])?$status_list[$v['sq_status']]:"";
  152. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  153. $str = "";
  154. if($v['sq_status'] == 1 || $v['sq_status'] == 3){
  155. $str .= "<div style='text-align:center;'>";
  156. $str .= "<a href='javascript:void(0)'class='window' data-h='/beihuogl/dyapplyedit/".$v['id']."' data-t='修改' style='margin-right:4px;color: #fff;background-color:#228B22;padding:4px 10px;border-radius:5px;font-size:15px'>编辑</a>";
  157. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#4169E1;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='2' onclick='update_status(this)'>发布</a>";
  158. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #444;background-color: #ddd;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='0' onclick='update_status(this)'>取消</a>";
  159. $str .= "</div>";
  160. }
  161. if($v['sq_status'] == 0){
  162. $str .= "<div style='text-align:center;'>";
  163. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #DC143C;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='0' onclick='del_bhsq(this)'>删除</a>";
  164. $str .= "</div>";
  165. }
  166. $list[$k]['update_time'] = $str;
  167. }
  168. $total = $this->bhsq->find_count($where);
  169. $pagenum = ceil($total/$perpage);
  170. $over = $total-($start+$perpage);
  171. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  172. echo json_encode($rows);exit;
  173. }else{
  174. $user = $this->user->get_api($_SESSION['api']);
  175. $usersp = explode('|',trim($user['shop'],'|'));
  176. $this->data['usersp'] = implode(",",$usersp);
  177. $vip_id = 0;
  178. if(in_array($user['id'],[10,28])){
  179. $vip_id = 1;
  180. }
  181. $this->data['vip_id'] = $vip_id;
  182. $this->_Template('beihuogl_dyapply',$this->data);
  183. }
  184. }
  185. //备货申请单的添加
  186. private function _dyapplyadd(){
  187. if($this->input->method() === 'post'){
  188. $data = $this->input->post();
  189. $time = strtotime(date("Y-m-d"),time());
  190. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  191. if(empty($info)){
  192. $num = 1;
  193. }else{
  194. $arr = explode('-',$info['sb_no']);
  195. $num = (int)$arr[2]+1;
  196. }
  197. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  198. $sb_no = "SQ-".date("ymd")."-".$num;
  199. $insert_arr = [];
  200. $time = time();
  201. foreach($data['title'] as $k=>$v){
  202. $insert_arr[] = [
  203. 'sb_no'=>$sb_no,
  204. 'sku'=>$data['sku'][$k],
  205. 'title'=>$data['title'][$k],
  206. 'shop_id'=>$data['shop_id'],
  207. 'plat_id'=>$data['plat_id'],
  208. 'sqr'=>$data['sqr'],
  209. 'sq_num'=>$data['sq_num'][$k],
  210. 'ccwl_num'=>$data['sq_num'][$k],
  211. 'ck_num'=>$data['sq_num'][$k],
  212. 'sq_status'=>1,
  213. 'remark'=>$data['remark'],
  214. 'add_time'=>$time,
  215. 'real_time'=>$time,
  216. 'update_time'=>$time,
  217. ];
  218. }
  219. $r =$this->db->insert_batch('bhsq',$insert_arr);
  220. if($r){
  221. echo json_encode(['code'=>1,'msg'=>'添加成功']);
  222. }else{
  223. echo json_encode(['code'=>-1,'msg'=>'添加失败']);
  224. }
  225. exit;
  226. }else{
  227. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  228. $this->data['plat_list'] = $plat_list;
  229. $this->_Template('beihuogl_dyapplyadd',$this->data);
  230. }
  231. }
  232. //备货申请单的 修改
  233. private function _dyapplyedit($arg_array){
  234. if($this->input->method() === 'post'){
  235. $data = $this->input->post();
  236. $id = $data['id'];
  237. $update_arr = [
  238. 'shop_id'=>$data['shop_id'],
  239. 'plat_id'=>$data['plat_id'],
  240. 'sqr'=>$data['sqr'],
  241. 'sq_num'=>$data['sq_num'],
  242. 'ccwl_num'=>$data['sq_num'],
  243. 'ck_num'=>$data['sq_num'],
  244. 'sku'=>$data['sku'],
  245. 'remark'=>$data['remark'],
  246. ];
  247. $r = $this->bhsq->save($update_arr,$id);
  248. if($r){
  249. echo json_encode(['msg'=>'添加成功','success'=>true]);
  250. }else{
  251. echo json_encode(['msg'=>'添加失败','success'=>false]);
  252. }
  253. exit;
  254. }else{
  255. $id = $arg_array[0];
  256. $info = $this->bhsq->find("id = ".$id);
  257. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  258. $this->data['plat_list'] = $plat_list;
  259. $this->data['info'] = $info;
  260. $this->_Template('beihuogl_dyapplyedit',$this->data);
  261. }
  262. }
  263. //备货申请单的 状态申请 如 发布 或者取消
  264. private function _dyapplygxzt(){
  265. if($this->input->method() === 'post'){
  266. $data = $this->input->post();
  267. $id = (int)$data['id'];
  268. $type = (int)$data['status'];
  269. $update_arr = [];
  270. $update_arr['sq_status'] = $type;
  271. if($type == 2){
  272. $update_arr['public_time'] = time();
  273. }
  274. if($type == 3){
  275. $update_arr['ccwl_status'] = 0;
  276. $update_arr['ck_status'] = 0;
  277. $update_arr['features'] = '';
  278. $update_arr['jm'] = '';
  279. $update_arr['public_time'] = 0;
  280. $update_arr['bh_no'] = '';
  281. $update_arr['u9sc_no'] = '';
  282. }
  283. $r = $this->bhsq->save($update_arr,$id);
  284. if($r){
  285. echo json_encode(['msg'=>'修改成功','success'=>true]);
  286. }else{
  287. echo json_encode(['msg'=>'修改失败','success'=>false]);
  288. }
  289. exit;
  290. }else{
  291. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  292. }
  293. }
  294. private function _deldyapply(){
  295. if($this->input->method() === 'post'){
  296. $data = $this->input->post();
  297. $id = $data['id'];
  298. $info = $this->bhsq->read($id);
  299. if($info['sq_status'] != 0){
  300. echo json_encode(['msg'=>'此条记录不符合删除条件','success'=>false]);
  301. exit;
  302. }
  303. $r = $this->bhsq->remove($id);
  304. if($r){
  305. echo json_encode(['msg'=>'删除成功','success'=>true]);
  306. }else{
  307. echo json_encode(['msg'=>'删除失败','success'=>false]);
  308. }
  309. exit;
  310. }else{
  311. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  312. }
  313. }
  314. //备货申请单的
  315. private function _dyapplysave(){
  316. if($this->input->method() === 'post'){
  317. $data = $this->input->post();
  318. $id = (int)$data['id'];
  319. $val = $this->input->post('val',true);
  320. $column = $data['column'];
  321. if($column == 'ccwl_num'){
  322. $update_arr = [
  323. 'ccwl_num'=>(int)$val,
  324. 'ck_num'=>(int)$val,
  325. ];
  326. }elseif($column == 'sku'){
  327. $update_arr = [
  328. 'sku'=>$val,
  329. ];
  330. }elseif($column == 'ck_num'){
  331. $update_arr = [
  332. 'ck_num'=>(int)$val,
  333. ];
  334. }elseif($column == 'drck'){
  335. $update_arr = [
  336. 'drck'=>(int)$val,
  337. ];
  338. }else{
  339. echo json_encode(['msg'=>'修改信息不合规','success'=>false]);
  340. exit;
  341. }
  342. $r = $this->bhsq->save($update_arr,$id);
  343. if($r){
  344. echo json_encode(['msg'=>'修改成功','success'=>true]);
  345. }else{
  346. echo json_encode(['msg'=>'修改失败','success'=>false]);
  347. }
  348. exit;
  349. }else{
  350. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  351. }
  352. }
  353. private function _dyapplyexcel(){
  354. if($this->input->method() === 'post'){
  355. $data = $this->input->post('list',true);
  356. if(empty($data)){
  357. $json_data = $this->input->raw_input_stream;
  358. $tmp_data = json_decode($json_data,true);
  359. $data = $tmp_data['list'];
  360. if(empty($data)){
  361. echo json_encode(['success'=>false,'msg'=>'未获取要保存的数据']);
  362. exit;
  363. }
  364. }
  365. $shop_list = $this->shop->find_all("1=1","id,shortname,type");
  366. $shop_list = array_column($shop_list,null,'shortname');
  367. $time = strtotime(date("Y-m-d"),time());
  368. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  369. if(empty($info)){
  370. $num = 1;
  371. }else{
  372. $arr = explode('-',$info['sb_no']);
  373. $num = (int)$arr[2]+1;
  374. }
  375. $time = time();
  376. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  377. $sb_no = "SQ-".date("ymd")."-".$num;
  378. $insert_arr = [];
  379. $error_list= [];
  380. foreach($data as $k=>$v){
  381. $shopshortname = trim($v[4]);
  382. if($shopshortname == '无'){
  383. $shop_info = [
  384. 'id'=>0,
  385. 'type'=>0,
  386. ];
  387. }else{
  388. $shop_info = isset($shop_list[$shopshortname])?$shop_list[$shopshortname]:[];
  389. if(empty($shop_info)){
  390. $error_list[] = [
  391. 'msg'=>"第".($k+1).'行店铺不存在,请核对表格信息'.$shopshortname,
  392. ];
  393. continue;
  394. }
  395. }
  396. $num = (int)$v[3];
  397. if(empty($num)){
  398. $error_list[] = [
  399. 'msg'=>"第".($k+1).'行数量不能为空,请核对表格信息',
  400. ];
  401. continue;
  402. }
  403. $tmp_time = trim($v[0]);
  404. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tmp_time)) {
  405. $add_time = strtotime($tmp_time);
  406. }else{
  407. $error_list[] = [
  408. 'msg'=>"第".($k+1).'行日期格式不正确,请核对表格信息',
  409. ];
  410. continue;
  411. }
  412. if(empty($v[5])){
  413. $error_list[] = [
  414. 'msg'=>"第".($k+1).'行申请人信息不能为空,请核对表格信息',
  415. ];
  416. continue;
  417. }
  418. if(empty($v[1])){
  419. $error_list[] = [
  420. 'msg'=>"第".($k+1).'行产品信息不能为空,请核对表格信息',
  421. ];
  422. continue;
  423. }
  424. $insert_arr[] = [
  425. 'sb_no'=>$sb_no,
  426. 'sku'=>trim($v[2]),
  427. 'title'=>trim($v[1]),
  428. 'shop_id'=>$shop_info['id'],
  429. 'plat_id'=>$shop_info['type'],
  430. 'sqr'=>trim($v[5]),
  431. 'sq_num'=>$num,
  432. 'ccwl_num'=>$num,
  433. 'ck_num'=>$num,
  434. 'sq_status'=>1,
  435. 'remark'=>$v[6],
  436. 'add_time'=>$add_time,
  437. 'real_time'=>$time,
  438. 'update_time'=>$time,
  439. ];
  440. }
  441. $r =$this->db->insert_batch('bhsq',$insert_arr);
  442. if($r){
  443. if(empty($error_list)){
  444. echo json_encode(['success'=>true,'msg'=>'添加成功']);
  445. }else{
  446. echo json_encode(['success'=>true,'msg'=>'添加成功','error_list'=>$error_list]);
  447. }
  448. }else{
  449. echo json_encode(['success'=>false,'msg'=>'添加失败','error_list'=>$error_list]);
  450. }
  451. exit;
  452. }else{
  453. echo json_encode(['success'=>true,'msg'=>'请求失败']);
  454. exit;
  455. }
  456. }
  457. //仓储物流部的备货申请单的列表
  458. private function _ccwlshlist(){
  459. if($this->input->method() === 'post'){
  460. $vip_id = $this->input->post('vip_id',true);
  461. $page = $this->input->post('page',true);
  462. $perpage = $this->input->post('perpage',true);
  463. $sqr = $this->input->post('sqr',true);
  464. $sqr = trim($sqr);
  465. $shop_id = $this->input->post('shop_id',true);
  466. $plat_id = $this->input->post('plat_id',true);
  467. $shop_ids = $this->input->post('shop_ids',true);
  468. $ktime = $this->input->post('ktime',true);
  469. $jtime = $this->input->post('jtime',true);
  470. $ktime = strtotime($ktime);
  471. $jtime = strtotime($jtime);
  472. $where = "sq_status = 2 and ccwl_status = 0 ";
  473. $where .= " and add_time >= ".$ktime." and add_time < ".$jtime." ";
  474. if(!empty($sqr)){
  475. $where .= " and sqr = '".$sqr."' ";
  476. }
  477. if(!empty($shop_id)){
  478. $where .= " and shop_id = ".$shop_id." ";
  479. }else{
  480. if($vip_id == 1){
  481. }else{
  482. $where .= " and shop_id in (".$shop_ids.") ";
  483. }
  484. }
  485. if(!empty($plat_id)){
  486. $where .= " and plat_id = ".$plat_id." ";
  487. }
  488. //数据排序
  489. $order_str = "id desc";
  490. if(empty($page))
  491. {
  492. $start = 0;
  493. $perpage = 1;
  494. }
  495. else
  496. {
  497. $start = ($page - 1)*$perpage;
  498. }
  499. $list = $this->bhsq->find_all($where,"id,shop_id,plat_id,title,sku,sqr,sq_num,ccwl_num,add_time,update_time,erp_check",$order_str,$start,$perpage);
  500. if(empty($list)){
  501. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  502. echo json_encode($rows);exit;
  503. }
  504. $shop_list = $this->shop->find_all("1=1","id,shopname");
  505. $shop_list = array_column($shop_list,'shopname','id');
  506. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  507. $plat_list = array_column($plat_list,'title','id');
  508. foreach($list as $k=>$v){
  509. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  510. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  511. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  512. if($v['erp_check'] == 1){
  513. $list[$k]['sku'] = "<i style='color:red'>".$v['sku']."</i> <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  514. }else{
  515. $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  516. }
  517. $list[$k]['ccwl_num'] = $v['ccwl_num']." <i class='fa fa-edit' data-id='".$v['id']."' data-num='".$v['ccwl_num']."' onclick='edit_ccwl(this)'></i>";
  518. $list[$k]['update_time'] = "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#4169E1;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='3' onclick='update_status(this)'>驳回</a>";
  519. unset($list[$k]['erp_check']);
  520. }
  521. $total = $this->bhsq->find_count($where);
  522. $pagenum = ceil($total/$perpage);
  523. $over = $total-($start+$perpage);
  524. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  525. echo json_encode($rows);exit;
  526. }else{
  527. $user = $this->user->get_api($_SESSION['api']);
  528. $usersp = explode('|',trim($user['shop'],'|'));
  529. $this->data['usersp'] = implode(",",$usersp);
  530. $vip_id = 0;
  531. if(in_array($user['id'],[10,28])){
  532. $vip_id = 1;
  533. }
  534. $this->data['vip_id'] = $vip_id;
  535. $this->_Template('beihuogl_ccwlshlist',$this->data);
  536. }
  537. }
  538. //一键校验选中SKU
  539. private function _ccwlskucheck(){
  540. if($this->input->method() === 'post'){
  541. $data = $this->input->post();
  542. if(empty($data['arr_id'])){
  543. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  544. exit;
  545. }
  546. $list = $this->bhsq->find_all('id in ('.implode(',',$data['arr_id']).')');
  547. $error_list = [];
  548. $success_ids = [];
  549. $errors_ids = [];
  550. foreach($list as $k=>$v){
  551. if(empty($v['sku'])){
  552. $error_list[] = [
  553. 'msg'=>$v['value'].'请录入SKU',
  554. ];
  555. $errors_ids[] = $v['id'];
  556. continue;
  557. }
  558. $num = $this->goods->find_count("sku = '".$v['sku']."'");
  559. if(!empty($num)){
  560. $success_ids[] = $v['id'];
  561. continue;
  562. }
  563. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  564. if(empty($whlabel_info)){
  565. $error_list[] = [
  566. 'msg'=>$v['sku'].'未在进销存浏览那找到对应信息',
  567. ];
  568. $errors_ids[] = $v['id'];
  569. }
  570. }
  571. $this->db->where_in('id', $errors_ids);
  572. $this->db->update('bhsq', ['erp_check'=>1]);
  573. $this->db->where_in('id', $success_ids);
  574. $this->db->update('bhsq', ['erp_check'=>0]);
  575. if(empty($error_list)){
  576. echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
  577. exit;
  578. }else{
  579. echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
  580. exit;
  581. }
  582. }else{
  583. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  584. exit;
  585. }
  586. }
  587. //仓储物流合成备货单
  588. private function _ccwlbhmake(){
  589. if($this->input->method() === 'post'){
  590. $data = $this->input->post();
  591. if(empty($data['arr_id'])){
  592. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  593. exit;
  594. }
  595. $bh_no = $data['bh_no'];
  596. $select_id = $data['arr_id'];
  597. if(empty($select_id)){
  598. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  599. exit;
  600. }
  601. if(empty($bh_no)){
  602. $tmp_time = strtotime(date("Y-m-d"),time());
  603. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  604. $num = $num+1;
  605. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  606. $bh_no = "BH-".date("ymd")."-".$num;
  607. }else{
  608. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  609. if(!empty($info)){
  610. echo json_encode(['success'=>false,'msg'=>'生成的备货单编号已经存在']);
  611. exit;
  612. }
  613. }
  614. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  615. foreach($list as $k=>$v){
  616. if(empty($v['sku'])){
  617. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  618. exit;
  619. }
  620. }
  621. $classid = $this->logic_u9tools->getClass();
  622. $typeclass = $this->logic_u9tools->getTypeClass();
  623. foreach($list as $k=>$v){
  624. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  625. if(empty($whlabel_info)){
  626. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  627. if(empty($whlabel_info)){
  628. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  629. exit;
  630. }
  631. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  632. $this->bhsq->save([
  633. 'jm'=>$r['jm'],
  634. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  635. 'features'=>$whlabel_info['features'],
  636. ],$v['id']);
  637. }else{
  638. $this->bhsq->save([
  639. 'jm'=>$whlabel_info['jm'],
  640. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  641. 'features'=>$whlabel_info['features'],
  642. ],$v['id']);
  643. }
  644. }
  645. $this->db->trans_start();
  646. $this->db->where_in('id',$select_id);
  647. $this->db->update('bhsq',[
  648. 'bh_no'=>$bh_no,
  649. 'sq_status'=>4,
  650. 'ccwl_status'=>1,
  651. ]);
  652. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  653. $this->db->where_in('id',$select_id);
  654. $query = $this->db->get('bhsq');
  655. $result = $query->row();
  656. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  657. $time = time();
  658. $this->bhccwl->insert([
  659. 'bh_no'=>$bh_no,
  660. 'status'=>0,
  661. 'num'=>$total_ccwl_num,
  662. 'create_time'=>$time,
  663. 'update_time'=>$time,
  664. ]);
  665. if($this->db->trans_status() === FALSE){
  666. $this->db->trans_rollback();
  667. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  668. exit;
  669. }else{
  670. $this->db->trans_commit();
  671. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  672. exit;
  673. }
  674. }else{
  675. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  676. exit;
  677. }
  678. }
  679. private function getU9Drck($features){
  680. if(stripos($features,'-126-') !== false)
  681. {
  682. $drck = '12003';//进入发条库
  683. }
  684. else if(stripos($features,'-127-') !== false)
  685. {
  686. $drck = '12004';//进入发块库
  687. }
  688. else
  689. {
  690. $drck = '12006';//其它进入完成库
  691. }
  692. return $drck;
  693. }
  694. //仓储物流部的备货单列表
  695. private function _ccwlbhindex(){
  696. if($this->input->method() === 'post'){
  697. $page = $this->input->post('page',true);
  698. $perpage = $this->input->post('perpage',true);
  699. $bh_no = $this->input->post('bh_no',true);
  700. $status = $this->input->post('status',true);
  701. $ktime = $this->input->post('ktime',true);
  702. $jtime = $this->input->post('jtime',true);
  703. $ktime = strtotime($ktime);
  704. $jtime = strtotime($jtime);
  705. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  706. if(!empty($bh_no)){
  707. $where .= " and bh_no = '".$bh_no."' ";
  708. }
  709. if($status > -1){
  710. $where .= " and status = ".$status." ";
  711. }
  712. //数据排序
  713. $order_str = "id desc";
  714. if(empty($page))
  715. {
  716. $start = 0;
  717. $perpage = 1;
  718. }
  719. else
  720. {
  721. $start = ($page - 1)*$perpage;
  722. }
  723. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
  724. if(empty($list)){
  725. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  726. echo json_encode($rows);exit;
  727. }
  728. $status_list = $this->bhccwl->getStatus();
  729. foreach($list as $k=>$v){
  730. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  731. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  732. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  733. $str = "";
  734. if($v['status'] == 0){
  735. $str .= "<div style='text-align:center;'>";
  736. $str .= "<a href='javascript:void(0)'class='window' data-h='/beihuogl/ccwlbhedit/".$v['id']."' data-t='修改' style='margin-right:4px;color: #fff;background-color:#228B22;padding:4px 10px;border-radius:5px;font-size:15px'>编辑</a>";
  737. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#4169E1;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='1' onclick='update_status(this)'>发布</a>";
  738. $str .= "</div>";
  739. }
  740. $list[$k]['update_time'] = $str;
  741. }
  742. $total = $this->bhccwl->find_count($where);
  743. $pagenum = ceil($total/$perpage);
  744. $over = $total-($start+$perpage);
  745. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  746. echo json_encode($rows);exit;
  747. }else{
  748. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  749. }
  750. }
  751. //仓储物流部备货 在编辑页面添加数据
  752. private function _ccwlbhsavexzbh(){
  753. if($this->input->method() === 'post'){
  754. $data = $this->input->post();
  755. $select_id = $data['select_id'];
  756. $id = $data['id'];
  757. $bh_no = $data['bh_no'];
  758. if(empty($select_id)){
  759. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  760. exit;
  761. }
  762. $info = $this->bhccwl->read($id);
  763. if(empty($info)){
  764. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  765. exit;
  766. }
  767. if($info['bh_no'] != $bh_no){
  768. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  769. exit;
  770. }
  771. $bh_no = $info['bh_no'];
  772. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  773. foreach($list as $k=>$v){
  774. if(empty($v['sku'])){
  775. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  776. exit;
  777. }
  778. if(!empty($v['bh_no'])){
  779. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  780. exit;
  781. }
  782. }
  783. $classid = $this->logic_u9tools->getClass();
  784. $typeclass = $this->logic_u9tools->getTypeClass();
  785. foreach($list as $k=>$v){
  786. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  787. if(empty($whlabel_info)){
  788. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  789. if(empty($whlabel_info)){
  790. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  791. exit;
  792. }
  793. if(empty($v['jm'])){
  794. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  795. $this->bhsq->save([
  796. 'jm'=>$r['jm'],
  797. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  798. 'features'=>$whlabel_info['features'],
  799. ],$v['id']);
  800. }
  801. $list[$k]['jm'] = $r['jm'];
  802. }else{
  803. $this->bhsq->save([
  804. 'jm'=>$whlabel_info['jm'],
  805. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  806. 'features'=>$whlabel_info['features'],
  807. ],$v['id']);
  808. $list[$k]['jm'] = $whlabel_info['jm'];
  809. }
  810. }
  811. $status_list = $this->bhccwl->getStatus();
  812. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  813. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  814. $plat_list = array_column($plat_list,'title','id');
  815. $shop_list = $this->shop->find_all("1=1","id,shopname");
  816. $shop_list = array_column($shop_list,'shopname','id');
  817. foreach($list as $k=>$v){
  818. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  819. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  820. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  821. $list[$k]['bh_no'] = $info['bh_no'];
  822. }
  823. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  824. }else{
  825. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  826. exit;
  827. }
  828. }
  829. private function _ccwlbhedit($arg_array){
  830. if($this->input->method() === 'post'){
  831. $select_id = $this->input->post('arr_id',true);
  832. if(empty($select_id)){
  833. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  834. exit;
  835. }
  836. $id = $this->input->post('id',true);
  837. $info = $this->bhccwl->read($id);
  838. $bh_no = $info['bh_no'];
  839. $this->db->where_in('id',$select_id);
  840. $this->db->update('bhsq',[
  841. 'bh_no'=>$bh_no,
  842. 'sq_status'=>4,
  843. 'ccwl_status'=>1,
  844. ]);
  845. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  846. $this->db->where_in('id',$select_id);
  847. $query = $this->db->get('bhsq');
  848. $result = $query->row();
  849. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  850. $time = time();
  851. $this->bhccwl->save([
  852. 'num'=>$total_ccwl_num,
  853. 'update_time'=>$time,
  854. ],$info['id']);
  855. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  856. }else{
  857. $id = $arg_array[0];
  858. $info = $this->bhccwl->find("id = ".$id);
  859. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  860. $status_list = $this->bhccwl->getStatus();
  861. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  862. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  863. $plat_list = array_column($plat_list,'title','id');
  864. $shop_list = $this->shop->find_all("1=1","id,shopname");
  865. $shop_list = array_column($shop_list,'shopname','id');
  866. foreach($list as $k=>$v){
  867. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  868. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  869. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  870. }
  871. // $this->data['info'] = $info;
  872. $this->data['list'] = $list;
  873. $this->data['info'] = $info;
  874. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  875. }
  876. }
  877. private function _ccwldelitem(){
  878. if($this->input->method() === 'post'){
  879. $data = $this->input->post();
  880. $id = $data['id'];
  881. $bh_no = $data['bh_no'];
  882. $info = $this->bhsq->read($id);
  883. $ccwl_num = $info['ccwl_num'];
  884. if(empty($info)){
  885. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  886. }
  887. if(empty($info['bh_no'])){
  888. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  889. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  890. }else{
  891. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  892. }
  893. }
  894. if($info['bh_no'] != $bh_no){
  895. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  896. }
  897. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  898. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  899. $this->db->trans_start();
  900. $this->bhccwl->save([
  901. 'num'=>$ccwl_info['num'],
  902. ],$ccwl_info['id']);
  903. $this->bhsq->save([
  904. 'sq_status'=>2,
  905. 'ccwl_status'=>0,
  906. 'bh_no'=>''
  907. ],$id);
  908. if($this->db->trans_status() === FALSE){
  909. $this->db->trans_rollback();
  910. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  911. }else{
  912. $this->db->trans_commit();
  913. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  914. }
  915. }else{
  916. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  917. }
  918. }
  919. private function _ccwleditxzbh(){
  920. if($this->input->method() === 'post'){
  921. $data = $this->input->post();
  922. //超过三月没审核的 就不展示了
  923. $time = time() - 60*24*3600;
  924. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  925. if(!empty($data['sqr'])){
  926. $where .= " and sqr = '".$data['sqr']."' ";
  927. }
  928. if(!empty($data['shop_id'])){
  929. $where .= " and shop_id = ".$data['shop_id']." ";
  930. }
  931. if(!empty($data['plat_id'])){
  932. $where .= " and plat_id = ".$data['plat_id']." ";
  933. }
  934. if(!empty($data['sku'])){
  935. $where .= " and sku = '".$data['sku']."' ";
  936. }
  937. $order_str = "id desc";
  938. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  939. $shop_list = $this->shop->find_all("1=1","id,shopname");
  940. $shop_list = array_column($shop_list,'shopname','id');
  941. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  942. $plat_list = array_column($plat_list,'title','id');
  943. foreach($list as $k=>$v){
  944. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  945. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  946. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  947. }
  948. if(empty($list)){
  949. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  950. }else{
  951. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  952. }
  953. }else{
  954. $data = $this->input->get();
  955. $this->data['id'] = $data['id'];
  956. $this->data['bh_no'] = $data['bh_no'];
  957. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  958. $this->data['plat_list'] = $plat_list;
  959. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  960. }
  961. }
  962. private function _ccwlbhsave(){
  963. if($this->input->method() === 'post'){
  964. $data = $this->input->post();
  965. $id = $data['id'];
  966. $val = $data['val'];
  967. $column = $data['column'];
  968. $update_arr = [];
  969. if($column == 'status'){
  970. $update_arr = [
  971. 'status'=>(int)$val,
  972. 'update_time'=>time(),
  973. 'public_time'=>time(),
  974. ];
  975. }else{
  976. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  977. }
  978. $r = $this->bhccwl->save($update_arr,$id);
  979. if($r){
  980. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  981. }else{
  982. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  983. }
  984. }else{
  985. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  986. }
  987. }
  988. //仓库的备货单列表
  989. private function _ckbhindex(){
  990. if($this->input->method() === 'post'){
  991. $page = $this->input->post('page',true);
  992. $perpage = $this->input->post('perpage',true);
  993. $bh_no = $this->input->post('bh_no',true);
  994. $status = $this->input->post('status',true);
  995. $ktime = $this->input->post('ktime',true);
  996. $jtime = $this->input->post('jtime',true);
  997. $ktime = strtotime($ktime);
  998. $jtime = strtotime($jtime);
  999. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1000. if(!empty($bh_no)){
  1001. $where .= " and bh_no = '".$bh_no."' ";
  1002. }
  1003. if($status > -1){
  1004. $where .= " and status = ".$status." ";
  1005. }
  1006. //数据排序
  1007. $order_str = "id desc";
  1008. if(empty($page))
  1009. {
  1010. $start = 0;
  1011. $perpage = 1;
  1012. }
  1013. else
  1014. {
  1015. $start = ($page - 1)*$perpage;
  1016. }
  1017. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1018. if(empty($list)){
  1019. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1020. echo json_encode($rows);exit;
  1021. }
  1022. $status_list = $this->bhccwl->getCkStatus();
  1023. foreach($list as $k=>$v){
  1024. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1025. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1026. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1027. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1028. $str = "";
  1029. if($v['ck_status'] == 0){
  1030. $str .= "<div style='text-align:center;'>";
  1031. $str .= "<a href='javascript:void(0)'class='window' data-h='/beihuogl/ckbhedit/".$v['id']."' data-t='修改' style='margin-right:4px;color: #fff;background-color:#228B22;padding:4px 10px;border-radius:5px;font-size:15px'>审核</a>";
  1032. // $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#4169E1;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-type='1' onclick='update_status(this)'>审核</a>";
  1033. $str .= "</div>";
  1034. }
  1035. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1036. $str .= "<div style='text-align:center;'>";
  1037. $str .= "<a href='javascript:void(0)' class='window' data-h='/beihuogl/makeu9scd/".$v['id']."' data-t='修改' style='margin-right:4px;color: #fff;background-color:#0099FF;padding:4px 10px;border-radius:5px;font-size:15px' >生成u9生产单</a>";
  1038. $str .= "</div>";
  1039. }
  1040. if($v['ck_status'] > 2){
  1041. $str .= "<div style='text-align:center;'>";
  1042. $str .= "<a href='/beihuogl/u9scdexcel/".$v['id']."' data-t='修改' style='margin-right:4px;color: #fff;background-color:#D2691E;padding:4px 10px;border-radius:5px;font-size:15px' >生产单EXCEL下载</a>";
  1043. $str .= "</div>";
  1044. }
  1045. $list[$k]['update_time'] = $str;
  1046. }
  1047. $total = $this->bhccwl->find_count($where);
  1048. $pagenum = ceil($total/$perpage);
  1049. $over = $total-($start+$perpage);
  1050. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1051. echo json_encode($rows);exit;
  1052. }else{
  1053. $this->_Template('beihuogl_ckbhindex',$this->data);
  1054. }
  1055. }
  1056. private function _ckbhedit($arg_array){
  1057. if($this->input->method() === 'post'){
  1058. $id = $this->input->post('id',true);
  1059. $bh_no = $this->input->post('bh_no',true);
  1060. $info = $this->bhccwl->read($id);
  1061. if(empty($info)){
  1062. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1063. }
  1064. if($info['ck_status'] == 0 && $info['status'] == 1){
  1065. }else{
  1066. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1067. }
  1068. if($info['bh_no'] != $bh_no){
  1069. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1070. }
  1071. $num = 0;
  1072. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1073. foreach($list as $k=>$v){
  1074. $num += $v['ck_num'];
  1075. }
  1076. $r = $this->bhccwl->save([
  1077. 'ck_status'=>1,
  1078. 'ck_num'=>$num,
  1079. 'update_time'=>time(),
  1080. 'ckpublic_time'=>time(),
  1081. ],$id);
  1082. if($r){
  1083. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1084. }else{
  1085. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1086. }
  1087. }else{
  1088. $id = $arg_array[0];
  1089. $info = $this->bhccwl->find("id = ".$id);
  1090. $status_list = $this->bhccwl->getCkStatus();
  1091. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1092. $drck_list = $this->bhccwl->getDrck();
  1093. $this->data['drck_list'] = $drck_list;
  1094. $this->data['drck_json'] = json_encode($drck_list);
  1095. $this->data['info'] = $info;
  1096. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1097. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1098. $shop_list = array_column($shop_list,'shopname','id');
  1099. foreach($list as $k=>$v){
  1100. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1101. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1102. }
  1103. $this->data['list'] = $list;
  1104. $this->_Template('beihuogl_ckbhedit',$this->data);
  1105. }
  1106. }
  1107. private function _makeu9scd($arg_array){
  1108. if($this->input->method() === 'post'){
  1109. $data = $this->input->post(null,true);
  1110. $info = $this->bhccwl->read($data['id']);
  1111. if(empty($info)){
  1112. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1113. }
  1114. if($info['ck_status'] == 1 && $info['status'] == 1){
  1115. }else{
  1116. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1117. exit;
  1118. }
  1119. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1120. $params = [
  1121. 'org_code'=>"120",//组织代码 龙盈工厂
  1122. 'djhlx'=>'2000',//单号类型 备货生产单
  1123. 'scbm_code'=>"12008",//龙盈生产部门
  1124. "time"=>time(),
  1125. 'owner_org_code'=>"120",
  1126. 'title'=>$info['bh_no'],
  1127. 'shipremarks'=>$info['bh_no'],
  1128. ];
  1129. $final_list = [];
  1130. foreach($list as $k=>$v){
  1131. $final_list[] =[
  1132. 'do_id'=>$v['id'],
  1133. 'drck'=>$v['drck'],
  1134. 'jm'=>$v['jm'],
  1135. 'sl'=>$v['ck_num'],
  1136. ];
  1137. }
  1138. $params['list'] = $final_list;
  1139. $token = $this->settingtest->get_yytoken_120();
  1140. $res = $this->apiyyv1->scdCreate($params,$token);
  1141. if(empty($res[0]['Data'])){
  1142. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1143. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1144. }
  1145. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1146. $r_s_list = $res[0]['Data'];
  1147. foreach($list as $k=>$v){
  1148. $list[$k]['u9_data'] = $r_s_list[$k];
  1149. }
  1150. //m_isSucess
  1151. $flag_status = 0;//判断是否有创建失败的
  1152. $u9sc_status = 0;//判断是否有创建成功的
  1153. foreach($list as $k=>$v){
  1154. if($v['u9_data']['m_isSucess']== 1){
  1155. $u9sc_status += 1;
  1156. $this->bhsq->save([
  1157. 'is_u9sc'=>1,
  1158. 'u9sc_no'=>$v['u9_data']['m_code'],
  1159. ],$v['id']);
  1160. }else{
  1161. $flag_status += 0;
  1162. $this->bhsq->save([
  1163. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1164. ],$v['id']);
  1165. }
  1166. }
  1167. $len = count($list);
  1168. //都创建失败了 就直接gg
  1169. if($u9sc_status == 0){
  1170. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1171. }
  1172. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1173. $this->bhccwl->save([
  1174. 'ck_status'=>2,
  1175. ],$info['id']);
  1176. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1177. }
  1178. if($u9sc_status == $len){
  1179. $this->bhccwl->save([
  1180. 'ck_status'=>3,
  1181. ],$info['id']);
  1182. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1183. }
  1184. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1185. }else{
  1186. $id = $arg_array[0];
  1187. $info = $this->bhccwl->read($id);
  1188. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1189. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1190. $shop_list = array_column($shop_list,'shopname','id');
  1191. $drck_list = $this->bhccwl->getDrck();
  1192. $status_list = $this->bhccwl->getCkStatus();
  1193. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1194. foreach($list as $k=>$v){
  1195. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1196. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1197. }
  1198. $this->data['list'] = $list;
  1199. $this->data['info'] = $info;
  1200. $this->_Template('beihuogl_makeu9scd',$this->data);
  1201. }
  1202. }
  1203. private function _ddscscd(){
  1204. if($this->input->method() === 'post'){
  1205. $id = $this->input->post('id',true);
  1206. $bh_no = $this->input->post('bh_no',true);
  1207. $bhsq_info = $this->bhsq->read($id);
  1208. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1209. if(empty($bhccwl_info)){
  1210. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1211. }
  1212. // if($bhccwl_info['ck_status'] != 1){
  1213. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1214. // exit;
  1215. // }
  1216. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1217. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1218. exit;
  1219. }
  1220. if(!empty($bhsq_info['u9sc_no'])){
  1221. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1222. exit;
  1223. }
  1224. $params = [
  1225. 'org_code'=>"120",//组织代码 龙盈工厂
  1226. 'djhlx'=>'2000',//单号类型 备货生产单
  1227. 'scbm_code'=>"12008",//龙盈生产部门
  1228. "time"=>time(),
  1229. 'owner_org_code'=>"120",
  1230. 'title'=>$bhccwl_info['bh_no'],
  1231. 'shipremarks'=>$bhccwl_info['bh_no'],
  1232. ];
  1233. $list[] = [
  1234. 'do_id'=>$bhsq_info['id'],
  1235. 'drck'=>$bhsq_info['drck'],
  1236. 'jm'=>$bhsq_info['jm'],
  1237. 'sl'=>$bhsq_info['ck_num'],
  1238. ];
  1239. $params['list'] = $list;
  1240. $token = $this->settingtest->get_yytoken_120();
  1241. $res = $this->apiyyv1->scdCreate($params,$token);
  1242. if(empty($res[0]['Data'])){
  1243. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1244. }
  1245. if($res[0]['Data'][0]['m_isSucess']== 1){
  1246. $this->bhsq->save([
  1247. 'is_u9sc'=>1,
  1248. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1249. ],$bhsq_info['id']);
  1250. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1251. if(empty($tmp_list)){
  1252. $tmp_status = 3;
  1253. }else{
  1254. $tmp_status = 2;
  1255. }
  1256. $this->bhccwl->save([
  1257. 'ck_status'=>$tmp_status,
  1258. ],$bhccwl_info['id']);
  1259. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1260. }else{
  1261. $this->bhsq->save([
  1262. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1263. ],$bhsq_info['id']);
  1264. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1265. }
  1266. }else{
  1267. exit('No direct script access allowed');
  1268. }
  1269. }
  1270. private function _showckbh($arg_array){
  1271. if($this->input->method() === 'post'){
  1272. exit('No direct script access allowed');
  1273. }
  1274. $id = $arg_array[0];
  1275. $drck_list = $this->bhccwl->getDrck();
  1276. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1277. $shop_list = array_column($shop_list,'shopname','id');
  1278. $info = $this->bhccwl->read($id);
  1279. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1280. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1281. foreach($list as $k=>$v){
  1282. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1283. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1284. }
  1285. $this->data['info'] = $info;
  1286. $this->data['list'] = $list;
  1287. $this->data['list_dcd'] = $list_dcd;
  1288. $this->_Template('beihuogl_showckbh',$this->data);
  1289. }
  1290. //仓库录入调出单
  1291. private function _ckdcd(){
  1292. if($this->input->method() === 'post'){
  1293. $lrdcd = $this->input->post('lrdcd',true);
  1294. if(empty($lrdcd)){
  1295. //列表展示
  1296. $page = $this->input->post('page',true);
  1297. $perpage = $this->input->post('perpage',true);
  1298. $bh_no = $this->input->post('bh_no',true);
  1299. $dcd_no = $this->input->post('dcd_no',true);
  1300. $status = $this->input->post('status',true);
  1301. $ktime = $this->input->post('ktime',true);
  1302. $jtime = $this->input->post('jtime',true);
  1303. $ktime = strtotime($ktime);
  1304. $jtime = strtotime($jtime);
  1305. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1306. if(!empty($bh_no)){
  1307. $where .= " and bh_no = '".$bh_no."' ";
  1308. }
  1309. if($status > -1){
  1310. $where .= " and status = ".$status." ";
  1311. }
  1312. if(!empty($dcd_no)){
  1313. $where .= " and dcd_no = '".$dcd_no."' ";
  1314. }
  1315. //数据排序
  1316. $order_str = "id desc";
  1317. if(empty($page))
  1318. {
  1319. $start = 0;
  1320. $perpage = 1;
  1321. }
  1322. else
  1323. {
  1324. $start = ($page - 1)*$perpage;
  1325. }
  1326. $list = $this->bhdcd->find_all($where,"id,bh_no,dcd_no,drd_no,status,jm,num,kw,create_time,rk_time,is_rk",$order_str,$start,$perpage);
  1327. if(empty($list)){
  1328. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1329. echo json_encode($rows);exit;
  1330. }
  1331. $status_list = $this->bhdcd->getStatus();
  1332. foreach($list as $k=>$v){
  1333. $list[$k]['dcd_no'] = "<h9 class='window' data-h='/beihuogl/ckbherprk/".$v['dcd_no']."' data-t='订单号:".$v['dcd_no']."'><p>".$v['dcd_no']."</p></h9>";
  1334. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1335. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1336. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1337. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1338. $str = "";
  1339. if($v['is_rk'] == 0){
  1340. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#DC143C;padding:4px 8px;border-radius:5px;font-size:13px' onclick='dcdjzrk(this)' data-id='".$v['id']."' data-num='".$v['num']."'>禁止入库</a>";
  1341. }
  1342. if(!empty($v['rk_time'])){
  1343. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#D2691E;padding:4px 8px;border-radius:5px;font-size:13px' onclick='dybq(this)' data-id='".$v['id']."' >打印标签</a>";
  1344. }
  1345. $list[$k]['rk_time'] = $str;
  1346. unset($list[$k]['is_rk']);
  1347. }
  1348. $total = $this->bhdcd->find_count($where);
  1349. $pagenum = ceil($total/$perpage);
  1350. $over = $total-($start+$perpage);
  1351. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1352. echo json_encode($rows);exit;
  1353. }else{
  1354. if(empty($lrdcd)){
  1355. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1356. }
  1357. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1358. if(!empty($num)){
  1359. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1360. }
  1361. //查询录入执行的调出单
  1362. $token = $this->settingtest->get_yytoken_120();
  1363. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1364. if(empty($res[0]['Data'])){
  1365. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1366. }
  1367. $time = time();
  1368. $final_list = [];
  1369. foreach($res[0]['Data'] as $k=>$v){
  1370. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1371. $tmp_sku = '';
  1372. $tmp_title = '';
  1373. $tmp_features = '';
  1374. $tmp_number='';
  1375. if(!empty($good_info)){
  1376. $tmp_sku = $good_info['sku'];
  1377. $tmp_title = $good_info['title'];
  1378. $tmp_features = $good_info['features'];
  1379. $tmp_number = str_replace("-","", $good_info['features']);
  1380. }
  1381. $final_list[] = [
  1382. 'sku'=>$tmp_sku,
  1383. 'dcd_no'=>$v['docno'],
  1384. 'jm'=>$v['iteminfo_itemcode'],
  1385. 'zh'=>$v['iteminfo_itemname'],
  1386. 'num'=>$v['costuomqty'],
  1387. 'real_num'=>$v['costuomqty'],
  1388. 'bh_no'=>$v['erp_no'],
  1389. 'create_time'=>$time,
  1390. 'title'=>$tmp_title,
  1391. 'features'=>$tmp_features,
  1392. 'number'=>$tmp_number,
  1393. ];
  1394. }
  1395. $r =$this->db->insert_batch('bhdcd',$final_list);
  1396. if($r){
  1397. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1398. }else{
  1399. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1400. }
  1401. exit;
  1402. }
  1403. }else{
  1404. $status_list = $this->bhdcd->getStatus();
  1405. $this->data['status_list'] = $status_list;
  1406. $this->_Template('beihuogl_ckdcd',$this->data);
  1407. }
  1408. }
  1409. private function _ckbherprk($arg_array){
  1410. if($this->input->method() === 'post'){
  1411. $data = $this->input->post(null,true);
  1412. $dcd_no = $data['dcd_no'];
  1413. $drd_no = $data['drd_no'];
  1414. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1415. $whlabel_arr = [];
  1416. $time = time();
  1417. $err_list= [];
  1418. foreach($list as $k=>$v){
  1419. if(empty($v['sku'])){
  1420. $err_list[] = $v['jm']."不存在";
  1421. continue;
  1422. }
  1423. for($i=0;$i<$v['num'];$i++){
  1424. $whlabel_arr[] = [
  1425. 'sku'=>$v['sku'],
  1426. 'number'=>$v['number'],
  1427. 'features'=>$v['features'],
  1428. 'title'=>$v['title'],
  1429. 'zh'=>$v['zh'],
  1430. 'warehouse'=>'13',
  1431. 'enter'=>$time,
  1432. 'state'=>0,
  1433. 'retreatwarehouse'=>'13',
  1434. 'time'=>$time,
  1435. 'details'=>$v['kw'],
  1436. 'bs'=>1,
  1437. 'rktype'=>9,
  1438. ];
  1439. }
  1440. }
  1441. if(!empty($err_list)){
  1442. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1443. }
  1444. $this->db->trans_start();
  1445. $this->db->insert_batch('whlabel',$whlabel_arr);
  1446. $this->db->where('dcd_no',$dcd_no);
  1447. //$this->db->where('drd_no',$drd_no);
  1448. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1449. if($this->db->trans_status() === FALSE){
  1450. $this->db->trans_rollback();
  1451. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1452. }else{
  1453. $this->db->trans_commit();
  1454. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1455. }
  1456. }else{
  1457. $dcd_no = $arg_array[0];
  1458. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1459. $jm_list = array_column($list,'jm');
  1460. $status_list = $this->bhdcd->getStatus();
  1461. $in_where = "( ";
  1462. foreach($jm_list as $k=>$v){
  1463. $in_where .= "'".$v."',";
  1464. }
  1465. $in_where = rtrim($in_where,",");
  1466. $in_where .= " )";
  1467. foreach($list as $k=>$v){
  1468. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1469. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1470. if(!empty($v['kw'])){
  1471. $list[$k]['kw'] = $v['kw'];
  1472. }else{
  1473. if(!empty($list[$k]['sku'])){
  1474. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1475. if(!empty($whlabel_info)){
  1476. if(!empty($whlabel_info['details'])){
  1477. $list[$k]['kw'] = $whlabel_info['details'];
  1478. $this->bhdcd->save([
  1479. 'kw'=>$whlabel_info['details'],
  1480. ],$v['id']);
  1481. }else{
  1482. $list[$k]['kw'] = "";
  1483. }
  1484. }else{
  1485. $list[$k]['kw'] = "";
  1486. }
  1487. }else{
  1488. $list[$k]['kw'] = "";
  1489. }
  1490. }
  1491. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1492. }
  1493. $this->data['list'] = $list;
  1494. $this->_Template('beihuogl_ckbherprk',$this->data);
  1495. }
  1496. }
  1497. private function _bhdcdsave(){
  1498. if($this->input->method() === 'post'){
  1499. $id = $this->input->post('id',true);
  1500. $val = $this->input->post('val',true);
  1501. $column = $this->input->post('column',true);
  1502. $info = $this->bhdcd->read($id);
  1503. $update_arr = [];
  1504. if($column == 'real_num'){
  1505. if($val > $info['num']){
  1506. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1507. }
  1508. $update_arr = [
  1509. 'real_num'=>(int)$val,
  1510. ];
  1511. }elseif($column == 'kw'){
  1512. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1513. if(!empty($winfo)){
  1514. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1515. if(empty($winfo)){
  1516. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1517. }
  1518. }
  1519. $update_arr = [
  1520. 'kw'=>trim($val),
  1521. ];
  1522. }else{
  1523. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1524. }
  1525. $r = $this->bhdcd->save($update_arr,$id);
  1526. if($r){
  1527. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1528. }else{
  1529. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1530. }
  1531. }else{
  1532. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1533. }
  1534. }
  1535. private function _u9scdexcel($arg_array){
  1536. $id = $arg_array[0];
  1537. $info = $this->bhccwl->read($id);
  1538. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1539. //生成excel
  1540. $filename = $info['bh_no']."备货生产单.xls";
  1541. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1542. <head>
  1543. <!--[if gte mso 9]><xml>
  1544. <x:ExcelWorkbook>
  1545. <x:ExcelWorksheets>
  1546. <x:ExcelWorksheet>
  1547. <x:Name>EXCEL</x:Name>
  1548. <x:WorksheetOptions>
  1549. <x:Print>
  1550. <x:ValidPrinterInfo />
  1551. </x:Print>
  1552. </x:WorksheetOptions>
  1553. </x:ExcelWorksheet>
  1554. </x:ExcelWorksheets>
  1555. </x:ExcelWorkbook>
  1556. </xml>
  1557. <![endif]-->
  1558. </head><body>";
  1559. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1560. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td></tr>";
  1561. foreach ($list as $key=>$value)
  1562. {
  1563. $str .= "<tr>";
  1564. $str .= "<td>". $value['bh_no']. "</td>";
  1565. $str .= "<td>". $value['title']. "</td>";
  1566. $str .= "<td>". $value['jm']. "</td>";
  1567. $str .= "<td>". $value['ck_num']. "</td>";
  1568. $str .= "<td>". $value['u9sc_no']. "</td>";
  1569. $str .= "</tr>";
  1570. }
  1571. $str .= "</table></body></html>";
  1572. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1573. header( "Content-type: application/octet-stream" );
  1574. header( "Content-Disposition: attachment; filename=".$filename );
  1575. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1576. header( "Pragma: no-cache" );
  1577. header( "Expires: 0" );
  1578. exit($str);
  1579. }
  1580. //打印标签
  1581. private function _printlabel(){
  1582. if($this->input->method() === 'post'){
  1583. $id = $this->input->post('id',true);
  1584. $xbqnum = $this->input->post('num',true);
  1585. $info = $this->bhdcd->read($id);
  1586. if(empty($info)){
  1587. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1588. }
  1589. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1590. $featurespp = explode('-', trim($featurespp, '-'));
  1591. if (isset($featurespp[5])) {
  1592. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1593. } else {
  1594. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1595. }
  1596. $label = '';
  1597. $cpid = $this->whlabellabel->find_count();
  1598. $cpid = $cpid + 1;
  1599. $time = time();
  1600. $label = time().rand(10,99);
  1601. $label = substr($label,1);
  1602. $insert_arr = [
  1603. 'purchase'=>1,
  1604. 'shop'=>'',
  1605. 'sku'=>$info['sku'],
  1606. 'number'=>$info['number'],
  1607. 'features'=>$info['features'],
  1608. 'featurespp'=>$tmp_featurespp,
  1609. 'title'=>$info['title'],
  1610. 'label'=>$label,
  1611. 'warehouse'=>13,
  1612. 'time'=>$time,
  1613. 'details'=>$info['kw'],
  1614. 'cpid'=>$cpid,
  1615. 'jm'=>$info['jm'],
  1616. 'cpbz'=>''
  1617. ];
  1618. $this->db->trans_begin();
  1619. $this->whlabellabel->insert($insert_arr);
  1620. if ($this->db->trans_status() === TRUE) {
  1621. $this->db->trans_commit();
  1622. } else {
  1623. $this->db->trans_rollback();
  1624. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  1625. exit;
  1626. }
  1627. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  1628. $details = ' <b style="font-size: 18px;">'."许昌仓</b> ".$details;
  1629. $purchase = "龙盈工厂";
  1630. echo json_encode(array('title' => $info['title'], 'num' => $label, 'bqsku' => $info['sku'], 'xbqnum' => $xbqnum, 'zh' => str_replace('自然色 ', '', rtrim($info['zh'], ' ')), 'details' => $details, 'purchase' => $purchase, 'cpbz' => "", 'usa' => 0, 'success' => true));
  1631. exit; //特殊仓目前不需要仓库选项
  1632. }else{
  1633. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1634. }
  1635. }
  1636. private function _dcdjzrk(){
  1637. if($this->input->method() === 'post'){
  1638. $id = $this->input->post('id',true);
  1639. $info = $this->bhdcd->read($id);
  1640. if($info['is_rk'] == 0){
  1641. $this->bhdcd->save(['is_rk'=>1],$id);
  1642. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1643. }else{
  1644. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1645. }
  1646. }else{
  1647. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1648. }
  1649. }
  1650. }