Beihuogl.php 64 KB

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