Beihuogl.php 74 KB

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