Beihuogl.php 79 KB

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