Beihuogl.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  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. if(!empty($error_list)){
  580. $this->db->where_in('id', $errors_ids);
  581. $this->db->update('bhsq', ['erp_check'=>1]);
  582. }
  583. if(!empty($success_ids)){
  584. $this->db->where_in('id', $success_ids);
  585. $this->db->update('bhsq', ['erp_check'=>0]);
  586. }
  587. if(empty($error_list)){
  588. echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
  589. exit;
  590. }else{
  591. echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
  592. exit;
  593. }
  594. }else{
  595. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  596. exit;
  597. }
  598. }
  599. //仓储物流合成备货单
  600. private function _ccwlbhmake(){
  601. if($this->input->method() === 'post'){
  602. $data = $this->input->post();
  603. if(empty($data['arr_id'])){
  604. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  605. exit;
  606. }
  607. $bh_no = $data['bh_no'];
  608. $select_id = $data['arr_id'];
  609. if(empty($select_id)){
  610. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  611. exit;
  612. }
  613. if(empty($bh_no)){
  614. $tmp_time = strtotime(date("Y-m-d"),time());
  615. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  616. $num = $num+1;
  617. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  618. $bh_no = "BH-".date("ymd")."-".$num;
  619. }else{
  620. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  621. if(!empty($info)){
  622. echo json_encode(['success'=>false,'msg'=>'生成的备货单编号已经存在']);
  623. exit;
  624. }
  625. }
  626. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  627. foreach($list as $k=>$v){
  628. if(empty($v['sku'])){
  629. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  630. exit;
  631. }
  632. }
  633. $classid = $this->logic_u9tools->getClass();
  634. $typeclass = $this->logic_u9tools->getTypeClass();
  635. foreach($list as $k=>$v){
  636. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  637. if(empty($whlabel_info)){
  638. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  639. if(empty($whlabel_info)){
  640. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  641. exit;
  642. }
  643. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  644. $this->bhsq->save([
  645. 'jm'=>$r['jm'],
  646. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  647. 'features'=>$whlabel_info['features'],
  648. ],$v['id']);
  649. }else{
  650. $this->bhsq->save([
  651. 'jm'=>$whlabel_info['jm'],
  652. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  653. 'features'=>$whlabel_info['features'],
  654. ],$v['id']);
  655. }
  656. }
  657. $this->db->trans_start();
  658. $this->db->where_in('id',$select_id);
  659. $this->db->update('bhsq',[
  660. 'bh_no'=>$bh_no,
  661. 'sq_status'=>4,
  662. 'ccwl_status'=>1,
  663. ]);
  664. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  665. $this->db->where_in('id',$select_id);
  666. $query = $this->db->get('bhsq');
  667. $result = $query->row();
  668. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  669. $time = time();
  670. $this->bhccwl->insert([
  671. 'bh_no'=>$bh_no,
  672. 'status'=>0,
  673. 'num'=>$total_ccwl_num,
  674. 'create_time'=>$time,
  675. 'update_time'=>$time,
  676. ]);
  677. if($this->db->trans_status() === FALSE){
  678. $this->db->trans_rollback();
  679. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  680. exit;
  681. }else{
  682. $this->db->trans_commit();
  683. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  684. exit;
  685. }
  686. }else{
  687. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  688. exit;
  689. }
  690. }
  691. private function getU9Drck($features){
  692. if(stripos($features,'-126-') !== false)
  693. {
  694. $drck = '12003';//进入发条库
  695. }
  696. else if(stripos($features,'-127-') !== false)
  697. {
  698. $drck = '12004';//进入发块库
  699. }
  700. else
  701. {
  702. $drck = '12006';//其它进入完成库
  703. }
  704. return $drck;
  705. }
  706. //仓储物流部的备货单列表
  707. private function _ccwlbhindex(){
  708. if($this->input->method() === 'post'){
  709. $page = $this->input->post('page',true);
  710. $perpage = $this->input->post('perpage',true);
  711. $bh_no = $this->input->post('bh_no',true);
  712. $status = $this->input->post('status',true);
  713. $ktime = $this->input->post('ktime',true);
  714. $jtime = $this->input->post('jtime',true);
  715. $ktime = strtotime($ktime);
  716. $jtime = strtotime($jtime);
  717. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  718. if(!empty($bh_no)){
  719. $where .= " and bh_no = '".$bh_no."' ";
  720. }
  721. if($status > -1){
  722. $where .= " and status = ".$status." ";
  723. }
  724. //数据排序
  725. $order_str = "id desc";
  726. if(empty($page))
  727. {
  728. $start = 0;
  729. $perpage = 1;
  730. }
  731. else
  732. {
  733. $start = ($page - 1)*$perpage;
  734. }
  735. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
  736. if(empty($list)){
  737. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  738. echo json_encode($rows);exit;
  739. }
  740. $status_list = $this->bhccwl->getStatus();
  741. foreach($list as $k=>$v){
  742. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  743. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  744. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  745. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  746. $str = "";
  747. if($v['status'] == 0){
  748. $str .= "<div style='text-align:center;'>";
  749. $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>";
  750. $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>";
  751. $str .= "</div>";
  752. }
  753. $list[$k]['update_time'] = $str;
  754. }
  755. $total = $this->bhccwl->find_count($where);
  756. $pagenum = ceil($total/$perpage);
  757. $over = $total-($start+$perpage);
  758. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  759. echo json_encode($rows);exit;
  760. }else{
  761. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  762. }
  763. }
  764. //仓储物流部备货 在编辑页面添加数据
  765. private function _ccwlbhsavexzbh(){
  766. if($this->input->method() === 'post'){
  767. $data = $this->input->post();
  768. $select_id = $data['select_id'];
  769. $id = $data['id'];
  770. $bh_no = $data['bh_no'];
  771. if(empty($select_id)){
  772. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  773. exit;
  774. }
  775. $info = $this->bhccwl->read($id);
  776. if(empty($info)){
  777. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  778. exit;
  779. }
  780. if($info['bh_no'] != $bh_no){
  781. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  782. exit;
  783. }
  784. $bh_no = $info['bh_no'];
  785. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  786. foreach($list as $k=>$v){
  787. if(empty($v['sku'])){
  788. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  789. exit;
  790. }
  791. if(!empty($v['bh_no'])){
  792. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  793. exit;
  794. }
  795. }
  796. $classid = $this->logic_u9tools->getClass();
  797. $typeclass = $this->logic_u9tools->getTypeClass();
  798. foreach($list as $k=>$v){
  799. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  800. if(empty($whlabel_info)){
  801. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  802. if(empty($whlabel_info)){
  803. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  804. exit;
  805. }
  806. if(empty($v['jm'])){
  807. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  808. $this->bhsq->save([
  809. 'jm'=>$r['jm'],
  810. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  811. 'features'=>$whlabel_info['features'],
  812. ],$v['id']);
  813. }
  814. $list[$k]['jm'] = $r['jm'];
  815. }else{
  816. $this->bhsq->save([
  817. 'jm'=>$whlabel_info['jm'],
  818. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  819. 'features'=>$whlabel_info['features'],
  820. ],$v['id']);
  821. $list[$k]['jm'] = $whlabel_info['jm'];
  822. }
  823. }
  824. $status_list = $this->bhccwl->getStatus();
  825. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  826. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  827. $plat_list = array_column($plat_list,'title','id');
  828. $shop_list = $this->shop->find_all("1=1","id,shopname");
  829. $shop_list = array_column($shop_list,'shopname','id');
  830. foreach($list as $k=>$v){
  831. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  832. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  833. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  834. $list[$k]['bh_no'] = $info['bh_no'];
  835. }
  836. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  837. }else{
  838. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  839. exit;
  840. }
  841. }
  842. private function _ccwlbhedit($arg_array){
  843. if($this->input->method() === 'post'){
  844. $select_id = $this->input->post('arr_id',true);
  845. if(empty($select_id)){
  846. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  847. exit;
  848. }
  849. $id = $this->input->post('id',true);
  850. $info = $this->bhccwl->read($id);
  851. $bh_no = $info['bh_no'];
  852. $this->db->where_in('id',$select_id);
  853. $this->db->update('bhsq',[
  854. 'bh_no'=>$bh_no,
  855. 'sq_status'=>4,
  856. 'ccwl_status'=>1,
  857. ]);
  858. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  859. $this->db->where_in('id',$select_id);
  860. $query = $this->db->get('bhsq');
  861. $result = $query->row();
  862. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  863. $time = time();
  864. $this->bhccwl->save([
  865. 'num'=>$total_ccwl_num,
  866. 'update_time'=>$time,
  867. ],$info['id']);
  868. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  869. }else{
  870. $id = $arg_array[0];
  871. $info = $this->bhccwl->find("id = ".$id);
  872. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  873. $status_list = $this->bhccwl->getStatus();
  874. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  875. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  876. $plat_list = array_column($plat_list,'title','id');
  877. $shop_list = $this->shop->find_all("1=1","id,shopname");
  878. $shop_list = array_column($shop_list,'shopname','id');
  879. foreach($list as $k=>$v){
  880. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  881. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  882. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  883. }
  884. // $this->data['info'] = $info;
  885. $this->data['list'] = $list;
  886. $this->data['info'] = $info;
  887. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  888. }
  889. }
  890. private function _ccwldelitem(){
  891. if($this->input->method() === 'post'){
  892. $data = $this->input->post();
  893. $id = $data['id'];
  894. $bh_no = $data['bh_no'];
  895. $info = $this->bhsq->read($id);
  896. $ccwl_num = $info['ccwl_num'];
  897. if(empty($info)){
  898. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  899. }
  900. if(empty($info['bh_no'])){
  901. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  902. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  903. }else{
  904. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  905. }
  906. }
  907. if($info['bh_no'] != $bh_no){
  908. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  909. }
  910. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  911. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  912. $this->db->trans_start();
  913. $this->bhccwl->save([
  914. 'num'=>$ccwl_info['num'],
  915. ],$ccwl_info['id']);
  916. $this->bhsq->save([
  917. 'sq_status'=>2,
  918. 'ccwl_status'=>0,
  919. 'bh_no'=>''
  920. ],$id);
  921. if($this->db->trans_status() === FALSE){
  922. $this->db->trans_rollback();
  923. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  924. }else{
  925. $this->db->trans_commit();
  926. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  927. }
  928. }else{
  929. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  930. }
  931. }
  932. private function _ccwleditxzbh(){
  933. if($this->input->method() === 'post'){
  934. $data = $this->input->post();
  935. //超过三月没审核的 就不展示了
  936. $time = time() - 60*24*3600;
  937. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  938. if(!empty($data['sqr'])){
  939. $where .= " and sqr = '".$data['sqr']."' ";
  940. }
  941. if(!empty($data['shop_id'])){
  942. $where .= " and shop_id = ".$data['shop_id']." ";
  943. }
  944. if(!empty($data['plat_id'])){
  945. $where .= " and plat_id = ".$data['plat_id']." ";
  946. }
  947. if(!empty($data['sku'])){
  948. $where .= " and sku = '".$data['sku']."' ";
  949. }
  950. $order_str = "id desc";
  951. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  952. $shop_list = $this->shop->find_all("1=1","id,shopname");
  953. $shop_list = array_column($shop_list,'shopname','id');
  954. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  955. $plat_list = array_column($plat_list,'title','id');
  956. foreach($list as $k=>$v){
  957. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  958. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  959. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  960. }
  961. if(empty($list)){
  962. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  963. }else{
  964. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  965. }
  966. }else{
  967. $data = $this->input->get();
  968. $this->data['id'] = $data['id'];
  969. $this->data['bh_no'] = $data['bh_no'];
  970. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  971. $this->data['plat_list'] = $plat_list;
  972. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  973. }
  974. }
  975. private function _ccwlbhsave(){
  976. if($this->input->method() === 'post'){
  977. $data = $this->input->post();
  978. $id = $data['id'];
  979. $val = $data['val'];
  980. $column = $data['column'];
  981. $update_arr = [];
  982. if($column == 'status'){
  983. $update_arr = [
  984. 'status'=>(int)$val,
  985. 'update_time'=>time(),
  986. 'public_time'=>time(),
  987. ];
  988. }else{
  989. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  990. }
  991. $r = $this->bhccwl->save($update_arr,$id);
  992. if($r){
  993. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  994. }else{
  995. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  996. }
  997. }else{
  998. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  999. }
  1000. }
  1001. //仓库的备货单列表
  1002. private function _ckbhindex(){
  1003. if($this->input->method() === 'post'){
  1004. $page = $this->input->post('page',true);
  1005. $perpage = $this->input->post('perpage',true);
  1006. $bh_no = $this->input->post('bh_no',true);
  1007. $status = $this->input->post('status',true);
  1008. $ktime = $this->input->post('ktime',true);
  1009. $jtime = $this->input->post('jtime',true);
  1010. $ktime = strtotime($ktime);
  1011. $jtime = strtotime($jtime);
  1012. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1013. if(!empty($bh_no)){
  1014. $where .= " and bh_no = '".$bh_no."' ";
  1015. }
  1016. if($status > -1){
  1017. $where .= " and status = ".$status." ";
  1018. }
  1019. //数据排序
  1020. $order_str = "id desc";
  1021. if(empty($page))
  1022. {
  1023. $start = 0;
  1024. $perpage = 1;
  1025. }
  1026. else
  1027. {
  1028. $start = ($page - 1)*$perpage;
  1029. }
  1030. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1031. if(empty($list)){
  1032. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1033. echo json_encode($rows);exit;
  1034. }
  1035. $status_list = $this->bhccwl->getCkStatus();
  1036. foreach($list as $k=>$v){
  1037. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1038. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1039. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1040. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1041. $str = "";
  1042. if($v['ck_status'] == 0){
  1043. $str .= "<div style='text-align:center;'>";
  1044. $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>";
  1045. // $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>";
  1046. $str .= "</div>";
  1047. }
  1048. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1049. $str .= "<div style='text-align:center;'>";
  1050. $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>";
  1051. $str .= "</div>";
  1052. }
  1053. if($v['ck_status'] > 2){
  1054. $str .= "<div style='text-align:center;'>";
  1055. $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>";
  1056. $str .= "</div>";
  1057. }
  1058. $list[$k]['update_time'] = $str;
  1059. }
  1060. $total = $this->bhccwl->find_count($where);
  1061. $pagenum = ceil($total/$perpage);
  1062. $over = $total-($start+$perpage);
  1063. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1064. echo json_encode($rows);exit;
  1065. }else{
  1066. $this->_Template('beihuogl_ckbhindex',$this->data);
  1067. }
  1068. }
  1069. private function _ckbhedit($arg_array){
  1070. if($this->input->method() === 'post'){
  1071. $id = $this->input->post('id',true);
  1072. $bh_no = $this->input->post('bh_no',true);
  1073. $info = $this->bhccwl->read($id);
  1074. if(empty($info)){
  1075. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1076. }
  1077. if($info['ck_status'] == 0 && $info['status'] == 1){
  1078. }else{
  1079. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1080. }
  1081. if($info['bh_no'] != $bh_no){
  1082. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1083. }
  1084. $num = 0;
  1085. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1086. foreach($list as $k=>$v){
  1087. $num += $v['ck_num'];
  1088. }
  1089. $r = $this->bhccwl->save([
  1090. 'ck_status'=>1,
  1091. 'ck_num'=>$num,
  1092. 'update_time'=>time(),
  1093. 'ckpublic_time'=>time(),
  1094. ],$id);
  1095. if($r){
  1096. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1097. }else{
  1098. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1099. }
  1100. }else{
  1101. $id = $arg_array[0];
  1102. $info = $this->bhccwl->find("id = ".$id);
  1103. $status_list = $this->bhccwl->getCkStatus();
  1104. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1105. $drck_list = $this->bhccwl->getDrck();
  1106. $this->data['drck_list'] = $drck_list;
  1107. $this->data['drck_json'] = json_encode($drck_list);
  1108. $this->data['info'] = $info;
  1109. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1110. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1111. $shop_list = array_column($shop_list,'shopname','id');
  1112. foreach($list as $k=>$v){
  1113. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1114. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1115. }
  1116. $this->data['list'] = $list;
  1117. $this->_Template('beihuogl_ckbhedit',$this->data);
  1118. }
  1119. }
  1120. private function _makeu9scd($arg_array){
  1121. if($this->input->method() === 'post'){
  1122. $data = $this->input->post(null,true);
  1123. $info = $this->bhccwl->read($data['id']);
  1124. if(empty($info)){
  1125. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1126. }
  1127. if($info['ck_status'] == 1 && $info['status'] == 1){
  1128. }else{
  1129. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1130. exit;
  1131. }
  1132. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1133. $params = [
  1134. 'org_code'=>"120",//组织代码 龙盈工厂
  1135. 'djhlx'=>'2000',//单号类型 备货生产单
  1136. 'scbm_code'=>"12008",//龙盈生产部门
  1137. "time"=>time(),
  1138. 'owner_org_code'=>"120",
  1139. 'title'=>$info['bh_no'],
  1140. 'shipremarks'=>$info['bh_no'],
  1141. ];
  1142. $final_list = [];
  1143. foreach($list as $k=>$v){
  1144. $final_list[] =[
  1145. 'do_id'=>$v['id'],
  1146. 'drck'=>$v['drck'],
  1147. 'jm'=>$v['jm'],
  1148. 'sl'=>$v['ck_num'],
  1149. ];
  1150. }
  1151. $params['list'] = $final_list;
  1152. $token = $this->settingtest->get_yytoken_120();
  1153. $res = $this->apiyyv1->scdCreate($params,$token);
  1154. if(empty($res[0]['Data'])){
  1155. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1156. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1157. }
  1158. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1159. $r_s_list = $res[0]['Data'];
  1160. foreach($list as $k=>$v){
  1161. $list[$k]['u9_data'] = $r_s_list[$k];
  1162. }
  1163. //m_isSucess
  1164. $flag_status = 0;//判断是否有创建失败的
  1165. $u9sc_status = 0;//判断是否有创建成功的
  1166. foreach($list as $k=>$v){
  1167. if($v['u9_data']['m_isSucess']== 1){
  1168. $u9sc_status += 1;
  1169. $this->bhsq->save([
  1170. 'is_u9sc'=>1,
  1171. 'u9sc_no'=>$v['u9_data']['m_code'],
  1172. ],$v['id']);
  1173. }else{
  1174. $flag_status += 0;
  1175. $this->bhsq->save([
  1176. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1177. ],$v['id']);
  1178. }
  1179. }
  1180. $len = count($list);
  1181. //都创建失败了 就直接gg
  1182. if($u9sc_status == 0){
  1183. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1184. }
  1185. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1186. $this->bhccwl->save([
  1187. 'ck_status'=>2,
  1188. ],$info['id']);
  1189. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1190. }
  1191. if($u9sc_status == $len){
  1192. $this->bhccwl->save([
  1193. 'ck_status'=>3,
  1194. ],$info['id']);
  1195. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1196. }
  1197. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1198. }else{
  1199. $id = $arg_array[0];
  1200. $info = $this->bhccwl->read($id);
  1201. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1202. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1203. $shop_list = array_column($shop_list,'shopname','id');
  1204. $drck_list = $this->bhccwl->getDrck();
  1205. $status_list = $this->bhccwl->getCkStatus();
  1206. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1207. foreach($list as $k=>$v){
  1208. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1209. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1210. }
  1211. $this->data['list'] = $list;
  1212. $this->data['info'] = $info;
  1213. $this->_Template('beihuogl_makeu9scd',$this->data);
  1214. }
  1215. }
  1216. private function _ddscscd(){
  1217. if($this->input->method() === 'post'){
  1218. $id = $this->input->post('id',true);
  1219. $bh_no = $this->input->post('bh_no',true);
  1220. $bhsq_info = $this->bhsq->read($id);
  1221. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1222. if(empty($bhccwl_info)){
  1223. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1224. }
  1225. // if($bhccwl_info['ck_status'] != 1){
  1226. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1227. // exit;
  1228. // }
  1229. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1230. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1231. exit;
  1232. }
  1233. if(!empty($bhsq_info['u9sc_no'])){
  1234. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1235. exit;
  1236. }
  1237. $params = [
  1238. 'org_code'=>"120",//组织代码 龙盈工厂
  1239. 'djhlx'=>'2000',//单号类型 备货生产单
  1240. 'scbm_code'=>"12008",//龙盈生产部门
  1241. "time"=>time(),
  1242. 'owner_org_code'=>"120",
  1243. 'title'=>$bhccwl_info['bh_no'],
  1244. 'shipremarks'=>$bhccwl_info['bh_no'],
  1245. ];
  1246. $list[] = [
  1247. 'do_id'=>$bhsq_info['id'],
  1248. 'drck'=>$bhsq_info['drck'],
  1249. 'jm'=>$bhsq_info['jm'],
  1250. 'sl'=>$bhsq_info['ck_num'],
  1251. ];
  1252. $params['list'] = $list;
  1253. $token = $this->settingtest->get_yytoken_120();
  1254. $res = $this->apiyyv1->scdCreate($params,$token);
  1255. if(empty($res[0]['Data'])){
  1256. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1257. }
  1258. if($res[0]['Data'][0]['m_isSucess']== 1){
  1259. $this->bhsq->save([
  1260. 'is_u9sc'=>1,
  1261. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1262. ],$bhsq_info['id']);
  1263. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1264. if(empty($tmp_list)){
  1265. $tmp_status = 3;
  1266. }else{
  1267. $tmp_status = 2;
  1268. }
  1269. $this->bhccwl->save([
  1270. 'ck_status'=>$tmp_status,
  1271. ],$bhccwl_info['id']);
  1272. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1273. }else{
  1274. $this->bhsq->save([
  1275. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1276. ],$bhsq_info['id']);
  1277. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1278. }
  1279. }else{
  1280. exit('No direct script access allowed');
  1281. }
  1282. }
  1283. private function _showckbh($arg_array){
  1284. if($this->input->method() === 'post'){
  1285. exit('No direct script access allowed');
  1286. }
  1287. $id = $arg_array[0];
  1288. $drck_list = $this->bhccwl->getDrck();
  1289. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1290. $shop_list = array_column($shop_list,'shopname','id');
  1291. $info = $this->bhccwl->read($id);
  1292. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1293. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1294. foreach($list as $k=>$v){
  1295. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1296. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1297. }
  1298. $this->data['info'] = $info;
  1299. $this->data['list'] = $list;
  1300. $this->data['list_dcd'] = $list_dcd;
  1301. $this->_Template('beihuogl_showckbh',$this->data);
  1302. }
  1303. //仓库录入调出单
  1304. private function _ckdcd(){
  1305. if($this->input->method() === 'post'){
  1306. $lrdcd = $this->input->post('lrdcd',true);
  1307. if(empty($lrdcd)){
  1308. //列表展示
  1309. $page = $this->input->post('page',true);
  1310. $perpage = $this->input->post('perpage',true);
  1311. $bh_no = $this->input->post('bh_no',true);
  1312. $dcd_no = $this->input->post('dcd_no',true);
  1313. $status = $this->input->post('status',true);
  1314. $ktime = $this->input->post('ktime',true);
  1315. $jtime = $this->input->post('jtime',true);
  1316. $ktime = strtotime($ktime);
  1317. $jtime = strtotime($jtime);
  1318. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1319. if(!empty($bh_no)){
  1320. $where .= " and bh_no = '".$bh_no."' ";
  1321. }
  1322. if($status > -1){
  1323. $where .= " and status = ".$status." ";
  1324. }
  1325. if(!empty($dcd_no)){
  1326. $where .= " and dcd_no = '".$dcd_no."' ";
  1327. }
  1328. //数据排序
  1329. $order_str = "id desc";
  1330. if(empty($page))
  1331. {
  1332. $start = 0;
  1333. $perpage = 1;
  1334. }
  1335. else
  1336. {
  1337. $start = ($page - 1)*$perpage;
  1338. }
  1339. $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);
  1340. if(empty($list)){
  1341. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1342. echo json_encode($rows);exit;
  1343. }
  1344. $status_list = $this->bhdcd->getStatus();
  1345. foreach($list as $k=>$v){
  1346. $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>";
  1347. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1348. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1349. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1350. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1351. $str = "";
  1352. if($v['is_rk'] == 0){
  1353. $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>";
  1354. }
  1355. if(!empty($v['rk_time'])){
  1356. $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>";
  1357. }
  1358. $list[$k]['rk_time'] = $str;
  1359. unset($list[$k]['is_rk']);
  1360. }
  1361. $total = $this->bhdcd->find_count($where);
  1362. $pagenum = ceil($total/$perpage);
  1363. $over = $total-($start+$perpage);
  1364. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1365. echo json_encode($rows);exit;
  1366. }else{
  1367. if(empty($lrdcd)){
  1368. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1369. }
  1370. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1371. if(!empty($num)){
  1372. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1373. }
  1374. //查询录入执行的调出单
  1375. $token = $this->settingtest->get_yytoken_120();
  1376. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1377. if(empty($res[0]['Data'])){
  1378. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1379. }
  1380. $time = time();
  1381. $final_list = [];
  1382. foreach($res[0]['Data'] as $k=>$v){
  1383. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1384. $tmp_sku = '';
  1385. $tmp_title = '';
  1386. $tmp_features = '';
  1387. $tmp_number='';
  1388. if(!empty($good_info)){
  1389. $tmp_sku = $good_info['sku'];
  1390. $tmp_title = $good_info['title'];
  1391. $tmp_features = $good_info['features'];
  1392. $tmp_number = str_replace("-","", $good_info['features']);
  1393. }
  1394. $final_list[] = [
  1395. 'sku'=>$tmp_sku,
  1396. 'dcd_no'=>$v['docno'],
  1397. 'jm'=>$v['iteminfo_itemcode'],
  1398. 'zh'=>$v['iteminfo_itemname'],
  1399. 'num'=>$v['costuomqty'],
  1400. 'real_num'=>$v['costuomqty'],
  1401. 'bh_no'=>$v['erp_no'],
  1402. 'create_time'=>$time,
  1403. 'title'=>$tmp_title,
  1404. 'features'=>$tmp_features,
  1405. 'number'=>$tmp_number,
  1406. ];
  1407. }
  1408. $r =$this->db->insert_batch('bhdcd',$final_list);
  1409. if($r){
  1410. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1411. }else{
  1412. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1413. }
  1414. exit;
  1415. }
  1416. }else{
  1417. $status_list = $this->bhdcd->getStatus();
  1418. $this->data['status_list'] = $status_list;
  1419. $this->_Template('beihuogl_ckdcd',$this->data);
  1420. }
  1421. }
  1422. private function _ckbherprk($arg_array){
  1423. if($this->input->method() === 'post'){
  1424. $data = $this->input->post(null,true);
  1425. $dcd_no = $data['dcd_no'];
  1426. $drd_no = $data['drd_no'];
  1427. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1428. $whlabel_arr = [];
  1429. $time = time();
  1430. $err_list= [];
  1431. foreach($list as $k=>$v){
  1432. if(empty($v['sku'])){
  1433. $err_list[] = $v['jm']."不存在";
  1434. continue;
  1435. }
  1436. for($i=0;$i<$v['num'];$i++){
  1437. $whlabel_arr[] = [
  1438. 'sku'=>$v['sku'],
  1439. 'number'=>$v['number'],
  1440. 'features'=>$v['features'],
  1441. 'title'=>$v['title'],
  1442. 'zh'=>$v['zh'],
  1443. 'warehouse'=>'13',
  1444. 'enter'=>$time,
  1445. 'state'=>0,
  1446. 'retreatwarehouse'=>'13',
  1447. 'time'=>$time,
  1448. 'details'=>$v['kw'],
  1449. 'bs'=>1,
  1450. 'rktype'=>9,
  1451. ];
  1452. }
  1453. }
  1454. if(!empty($err_list)){
  1455. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1456. }
  1457. $this->db->trans_start();
  1458. $this->db->insert_batch('whlabel',$whlabel_arr);
  1459. $this->db->where('dcd_no',$dcd_no);
  1460. //$this->db->where('drd_no',$drd_no);
  1461. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1462. if($this->db->trans_status() === FALSE){
  1463. $this->db->trans_rollback();
  1464. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1465. }else{
  1466. $this->db->trans_commit();
  1467. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1468. }
  1469. }else{
  1470. $dcd_no = $arg_array[0];
  1471. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1472. $jm_list = array_column($list,'jm');
  1473. $status_list = $this->bhdcd->getStatus();
  1474. $in_where = "( ";
  1475. foreach($jm_list as $k=>$v){
  1476. $in_where .= "'".$v."',";
  1477. }
  1478. $in_where = rtrim($in_where,",");
  1479. $in_where .= " )";
  1480. foreach($list as $k=>$v){
  1481. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1482. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1483. if(!empty($v['kw'])){
  1484. $list[$k]['kw'] = $v['kw'];
  1485. }else{
  1486. if(!empty($list[$k]['sku'])){
  1487. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1488. if(!empty($whlabel_info)){
  1489. if(!empty($whlabel_info['details'])){
  1490. $list[$k]['kw'] = $whlabel_info['details'];
  1491. $this->bhdcd->save([
  1492. 'kw'=>$whlabel_info['details'],
  1493. ],$v['id']);
  1494. }else{
  1495. $list[$k]['kw'] = "";
  1496. }
  1497. }else{
  1498. $list[$k]['kw'] = "";
  1499. }
  1500. }else{
  1501. $list[$k]['kw'] = "";
  1502. }
  1503. }
  1504. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1505. }
  1506. $this->data['list'] = $list;
  1507. $this->_Template('beihuogl_ckbherprk',$this->data);
  1508. }
  1509. }
  1510. private function _bhdcdsave(){
  1511. if($this->input->method() === 'post'){
  1512. $id = $this->input->post('id',true);
  1513. $val = $this->input->post('val',true);
  1514. $column = $this->input->post('column',true);
  1515. $info = $this->bhdcd->read($id);
  1516. $update_arr = [];
  1517. if($column == 'real_num'){
  1518. if($val > $info['num']){
  1519. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1520. }
  1521. $update_arr = [
  1522. 'real_num'=>(int)$val,
  1523. ];
  1524. }elseif($column == 'kw'){
  1525. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1526. if(!empty($winfo)){
  1527. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1528. if(empty($winfo)){
  1529. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1530. }
  1531. }
  1532. $update_arr = [
  1533. 'kw'=>trim($val),
  1534. ];
  1535. }else{
  1536. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1537. }
  1538. $r = $this->bhdcd->save($update_arr,$id);
  1539. if($r){
  1540. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1541. }else{
  1542. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1543. }
  1544. }else{
  1545. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1546. }
  1547. }
  1548. private function _u9scdexcel($arg_array){
  1549. $id = $arg_array[0];
  1550. $info = $this->bhccwl->read($id);
  1551. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1552. //生成excel
  1553. $filename = $info['bh_no']."备货生产单.xls";
  1554. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1555. <head>
  1556. <!--[if gte mso 9]><xml>
  1557. <x:ExcelWorkbook>
  1558. <x:ExcelWorksheets>
  1559. <x:ExcelWorksheet>
  1560. <x:Name>EXCEL</x:Name>
  1561. <x:WorksheetOptions>
  1562. <x:Print>
  1563. <x:ValidPrinterInfo />
  1564. </x:Print>
  1565. </x:WorksheetOptions>
  1566. </x:ExcelWorksheet>
  1567. </x:ExcelWorksheets>
  1568. </x:ExcelWorkbook>
  1569. </xml>
  1570. <![endif]-->
  1571. </head><body>";
  1572. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1573. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td></tr>";
  1574. foreach ($list as $key=>$value)
  1575. {
  1576. $str .= "<tr>";
  1577. $str .= "<td>". $value['bh_no']. "</td>";
  1578. $str .= "<td>". $value['title']. "</td>";
  1579. $str .= "<td>". $value['jm']. "</td>";
  1580. $str .= "<td>". $value['ck_num']. "</td>";
  1581. $str .= "<td>". $value['u9sc_no']. "</td>";
  1582. $str .= "</tr>";
  1583. }
  1584. $str .= "</table></body></html>";
  1585. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1586. header( "Content-type: application/octet-stream" );
  1587. header( "Content-Disposition: attachment; filename=".$filename );
  1588. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1589. header( "Pragma: no-cache" );
  1590. header( "Expires: 0" );
  1591. exit($str);
  1592. }
  1593. //打印标签
  1594. private function _printlabel(){
  1595. if($this->input->method() === 'post'){
  1596. $id = $this->input->post('id',true);
  1597. $xbqnum = $this->input->post('num',true);
  1598. $info = $this->bhdcd->read($id);
  1599. if(empty($info)){
  1600. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1601. }
  1602. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1603. $featurespp = explode('-', trim($featurespp, '-'));
  1604. if (isset($featurespp[5])) {
  1605. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1606. } else {
  1607. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1608. }
  1609. $label = '';
  1610. $cpid = $this->whlabellabel->find_count();
  1611. $cpid = $cpid + 1;
  1612. $time = time();
  1613. $label = time().rand(10,99);
  1614. $label = substr($label,1);
  1615. $insert_arr = [
  1616. 'purchase'=>1,
  1617. 'shop'=>'',
  1618. 'sku'=>$info['sku'],
  1619. 'number'=>$info['number'],
  1620. 'features'=>$info['features'],
  1621. 'featurespp'=>$tmp_featurespp,
  1622. 'title'=>$info['title'],
  1623. 'label'=>$label,
  1624. 'warehouse'=>13,
  1625. 'time'=>$time,
  1626. 'details'=>$info['kw'],
  1627. 'cpid'=>$cpid,
  1628. 'jm'=>$info['jm'],
  1629. 'cpbz'=>''
  1630. ];
  1631. $this->db->trans_begin();
  1632. $this->whlabellabel->insert($insert_arr);
  1633. if ($this->db->trans_status() === TRUE) {
  1634. $this->db->trans_commit();
  1635. } else {
  1636. $this->db->trans_rollback();
  1637. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  1638. exit;
  1639. }
  1640. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  1641. $details = ' <b style="font-size: 18px;">'."许昌仓</b> ".$details;
  1642. $purchase = "龙盈工厂";
  1643. 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));
  1644. exit; //特殊仓目前不需要仓库选项
  1645. }else{
  1646. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1647. }
  1648. }
  1649. private function _dcdjzrk(){
  1650. if($this->input->method() === 'post'){
  1651. $id = $this->input->post('id',true);
  1652. $info = $this->bhdcd->read($id);
  1653. if($info['is_rk'] == 0){
  1654. $this->bhdcd->save(['is_rk'=>1],$id);
  1655. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1656. }else{
  1657. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1658. }
  1659. }else{
  1660. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1661. }
  1662. }
  1663. private function _dyapplyyjsh(){
  1664. if($this->input->method() === 'post'){
  1665. $arr_id = $this->input->post('arr_id',true);
  1666. $this->db->where_in('id',$arr_id);
  1667. $this->db->where('sq_status',1);
  1668. $this->db->update('bhsq',['sq_status'=>2]);
  1669. echo json_encode(['success'=>true,'msg'=>'审核通过']);exit;
  1670. }else{
  1671. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1672. }
  1673. }
  1674. }