Beihuogl.php 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  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. $this->load->_model("Model_warehouse","warehouse");
  17. $this->load->_model("Model_bhsccx","bhsccx");
  18. }
  19. //定义方法的调用规则 获取URI第二段值
  20. public function _remap($arg,$arg_array)
  21. {
  22. if(!isset($_SESSION['api'])){
  23. header('Location: /');exit;
  24. }
  25. if($arg == 'dyapply')//
  26. {
  27. $this->_dyapply();
  28. }
  29. elseif($arg == 'dyapplyadd')//
  30. {
  31. $this->_dyapplyadd();
  32. }
  33. elseif($arg == 'dyapplyedit')//
  34. {
  35. $this->_dyapplyedit($arg_array);
  36. }
  37. elseif($arg == 'dyapplygxzt')//
  38. {
  39. $this->_dyapplygxzt();
  40. }
  41. elseif($arg == 'dyapplyexcel'){
  42. $this->_dyapplyexcel();
  43. }
  44. elseif($arg == 'ccwlshlist'){
  45. $this->_ccwlshlist();
  46. }
  47. elseif($arg == 'ccwlbhindex'){
  48. $this->_ccwlbhindex();
  49. }elseif($arg == 'dyapplysave'){
  50. $this->_dyapplysave();
  51. }elseif($arg == 'ccwlbhmake'){
  52. $this->_ccwlbhmake();
  53. }elseif($arg == 'ccwlbhedit'){
  54. $this->_ccwlbhedit($arg_array);
  55. }elseif($arg == 'ccwleditxzbh'){
  56. $this->_ccwleditxzbh();
  57. }elseif($arg == 'ccwlbhsavexzbh'){
  58. $this->_ccwlbhsavexzbh();
  59. }elseif($arg == 'ccwldelitem'){
  60. $this->_ccwldelitem();
  61. }elseif($arg == 'ccwlbhsave'){
  62. $this->_ccwlbhsave();
  63. }elseif($arg == 'ccwlbhzhcheck'){
  64. $this->_ccwlbhzhcheck();
  65. }elseif($arg == 'ckbhindex'){
  66. $this->_ckbhindex();
  67. }elseif($arg == 'ckbhedit'){
  68. $this->_ckbhedit($arg_array);
  69. }elseif($arg == 'makeu9scd'){
  70. $this->_makeu9scd($arg_array);
  71. }elseif($arg == 'showckbh'){
  72. $this->_showckbh($arg_array);
  73. }elseif($arg == 'ddscscd'){
  74. $this->_ddscscd();
  75. }elseif($arg == 'ckdcd'){
  76. $this->_ckdcd();
  77. }elseif($arg == 'ckbherprk'){
  78. $this->_ckbherprk($arg_array);
  79. }elseif($arg == 'bhdcdsave'){
  80. $this->_bhdcdsave();
  81. }elseif($arg == 'u9scdexcel')
  82. {
  83. $this->_u9scdexcel($arg_array);
  84. }elseif($arg == 'ccwlskucheck'){
  85. $this->_ccwlskucheck();
  86. }elseif($arg == 'printlabel'){
  87. $this->_printlabel();
  88. }elseif($arg == 'deldyapply'){
  89. $this->_deldyapply();
  90. }elseif($arg == 'dcdjzrk'){
  91. $this->_dcdjzrk();
  92. }elseif($arg == 'dyapplyyjsh'){
  93. $this->_dyapplyyjsh();
  94. }elseif($arg == 'ccwlbhdownload'){
  95. $this->_ccwlbhdownload();
  96. }elseif($arg == 'ckexcel'){
  97. $this->_ckexcel($arg_array);
  98. }elseif($arg == 'checkdcdsku'){
  99. $this->_checkdcdsku($arg_array);
  100. }elseif($arg == 'dcdkwyz'){
  101. $this->_dcdkwyz();
  102. }elseif($arg == 'bhcxsave'){
  103. $this->_bhcxsave();
  104. }elseif($arg == 'bhcxlist'){
  105. $this->_bhcxlist();
  106. }elseif($arg == 'bhcxshlist'){
  107. $this->_bhcxshlist();
  108. }elseif($arg == 'updatestatus'){
  109. $this->_updatestatus();
  110. }elseif($arg == 'bhcxedit'){
  111. $this->_bhcxedit($arg_array);
  112. }elseif($arg == 'bhcxlistexcel'){
  113. $this->_bhcxlistexcel();
  114. }elseif($arg == 'wlrlpdc'){
  115. $this->_wlrlpdc();
  116. }
  117. else
  118. {
  119. $this->_index();
  120. }
  121. }
  122. private function _index(){
  123. exit('No direct script access allowed 1');
  124. }
  125. //备货申请单的列表
  126. private function _dyapply(){
  127. if($this->input->method() === 'post'){
  128. $vip_id = $this->input->post('vip_id',true);
  129. $page = $this->input->post('page',true);
  130. $perpage = $this->input->post('perpage',true);
  131. $sqr = $this->input->post('sqr',true);
  132. $sqr = trim($sqr);
  133. $sq_status = $this->input->post('sq_status',true);
  134. $shop_id = $this->input->post('shop_id',true);
  135. $plat_id = $this->input->post('plat_id',true);
  136. $shop_ids = $this->input->post('shop_ids',true);
  137. $ktime = $this->input->post('ktime',true);
  138. $jtime = $this->input->post('jtime',true);
  139. $ktime = strtotime($ktime);
  140. $jtime = strtotime($jtime);
  141. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  142. if(!empty($sqr)){
  143. $where .= " and sqr = '".$sqr."' ";
  144. }
  145. if($shop_id > -1){
  146. $where .= " and shop_id = ".$shop_id." ";
  147. }else{
  148. if($vip_id == 1){
  149. }else{
  150. $where .= " and shop_id in (".$shop_ids.") ";
  151. }
  152. }
  153. if($sq_status > -1){
  154. $where .= " and sq_status = ".$sq_status." ";
  155. }
  156. if($plat_id > -1){
  157. $where .= " and plat_id = ".$plat_id." ";
  158. }
  159. //数据排序
  160. $order_str = "id desc";
  161. if(empty($page))
  162. {
  163. $start = 0;
  164. $perpage = 1;
  165. }
  166. else
  167. {
  168. $start = ($page - 1)*$perpage;
  169. }
  170. $list = $this->bhsq->find_all($where,"id,shop_id,plat_id,title,sku,sqr,sq_num,sq_status,add_time,update_time,bh_no,u9sc_no,is_cx",$order_str,$start,$perpage);
  171. if(empty($list)){
  172. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  173. echo json_encode($rows);exit;
  174. }
  175. $shop_list = $this->shop->find_all("1=1","id,shopname");
  176. $shop_list = array_column($shop_list,'shopname','id');
  177. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  178. $plat_list = array_column($plat_list,'title','id');
  179. $status_list = $this->bhsq->getSqStatus();
  180. foreach($list as $k=>$v){
  181. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  182. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  183. $list[$k]['sq_status'] = isset($status_list[$v['sq_status']])?$status_list[$v['sq_status']]:"";
  184. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  185. $str = "<div style='text-align:center;'>";
  186. if($v['sq_status'] == 1 || $v['sq_status'] == 3){
  187. $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>";
  188. $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>";
  189. $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>";
  190. }
  191. if($v['sq_status'] == 0){
  192. $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>";
  193. }
  194. if(!empty($v['u9sc_no']) && ($v['is_cx'] != 1)){
  195. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-title='".$v['title']."' data-id='".$v['id']."' data-u9sc_no='".$v['u9sc_no']."' data-bh_no='".$v['bh_no']."' onclick='cx_bhsq(this)'>生产撤销</a>";
  196. }
  197. $str .= "</div>";
  198. $list[$k]['update_time'] = $str;
  199. unset($list[$k]['bh_no']);
  200. unset($list[$k]['u9sc_no']);
  201. unset($list[$k]['is_cx']);
  202. }
  203. $total = $this->bhsq->find_count($where);
  204. $pagenum = ceil($total/$perpage);
  205. $over = $total-($start+$perpage);
  206. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  207. echo json_encode($rows);exit;
  208. }else{
  209. $user = $this->user->get_api($_SESSION['api']);
  210. $usersp = explode('|',trim($user['shop'],'|'));
  211. $this->data['usersp'] = implode(",",$usersp);
  212. $vip_id = 0;
  213. if(in_array($user['id'],[10,28])){
  214. $vip_id = 1;
  215. }
  216. $status_list = $this->bhsq->getSqStatus();
  217. $this->data['status_list'] = $status_list;
  218. $this->data['vip_id'] = $vip_id;
  219. $this->_Template('beihuogl_dyapply',$this->data);
  220. }
  221. }
  222. //备货申请单的添加
  223. private function _dyapplyadd(){
  224. if($this->input->method() === 'post'){
  225. $data = $this->input->post();
  226. $time = strtotime(date("Y-m-d"),time());
  227. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  228. if(empty($info)){
  229. $num = 1;
  230. }else{
  231. $arr = explode('-',$info['sb_no']);
  232. $num = (int)$arr[2]+1;
  233. }
  234. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  235. $sb_no = "SQ-".date("ymd")."-".$num;
  236. $insert_arr = [];
  237. $time = time();
  238. foreach($data['title'] as $k=>$v){
  239. $insert_arr[] = [
  240. 'sb_no'=>$sb_no,
  241. 'sku'=>$data['sku'][$k],
  242. 'title'=>$data['title'][$k],
  243. 'shop_id'=>$data['shop_id'],
  244. 'plat_id'=>$data['plat_id'],
  245. 'sqr'=>$data['sqr'],
  246. 'sq_num'=>$data['sq_num'][$k],
  247. 'ccwl_num'=>$data['sq_num'][$k],
  248. 'ck_num'=>$data['sq_num'][$k],
  249. 'sq_status'=>1,
  250. 'remark'=>$data['remark'],
  251. 'add_time'=>$time,
  252. 'real_time'=>$time,
  253. 'update_time'=>$time,
  254. ];
  255. }
  256. $r =$this->db->insert_batch('bhsq',$insert_arr);
  257. if($r){
  258. echo json_encode(['code'=>1,'msg'=>'添加成功']);
  259. }else{
  260. echo json_encode(['code'=>-1,'msg'=>'添加失败']);
  261. }
  262. exit;
  263. }else{
  264. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  265. $this->data['plat_list'] = $plat_list;
  266. $this->_Template('beihuogl_dyapplyadd',$this->data);
  267. }
  268. }
  269. //备货申请单的 修改
  270. private function _dyapplyedit($arg_array){
  271. if($this->input->method() === 'post'){
  272. $data = $this->input->post();
  273. $id = $data['id'];
  274. $update_arr = [
  275. 'shop_id'=>$data['shop_id'],
  276. 'plat_id'=>$data['plat_id'],
  277. 'sqr'=>$data['sqr'],
  278. 'sq_num'=>$data['sq_num'],
  279. 'ccwl_num'=>$data['sq_num'],
  280. 'ck_num'=>$data['sq_num'],
  281. 'sku'=>$data['sku'],
  282. 'remark'=>$data['remark'],
  283. 'title'=>$data['title'],
  284. ];
  285. $r = $this->bhsq->save($update_arr,$id);
  286. if($r){
  287. echo json_encode(['msg'=>'添加成功','success'=>true]);
  288. }else{
  289. echo json_encode(['msg'=>'添加失败','success'=>false]);
  290. }
  291. exit;
  292. }else{
  293. $id = $arg_array[0];
  294. $info = $this->bhsq->find("id = ".$id);
  295. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  296. $this->data['plat_list'] = $plat_list;
  297. $this->data['info'] = $info;
  298. $this->_Template('beihuogl_dyapplyedit',$this->data);
  299. }
  300. }
  301. //备货申请单的 状态申请 如 发布 或者取消
  302. private function _dyapplygxzt(){
  303. if($this->input->method() === 'post'){
  304. $data = $this->input->post();
  305. $id = (int)$data['id'];
  306. $type = (int)$data['status'];
  307. $update_arr = [];
  308. $update_arr['sq_status'] = $type;
  309. if($type == 2){
  310. $update_arr['public_time'] = time();
  311. }
  312. if($type == 3){
  313. $update_arr['ccwl_status'] = 0;
  314. $update_arr['ck_status'] = 0;
  315. $update_arr['features'] = '';
  316. $update_arr['jm'] = '';
  317. $update_arr['public_time'] = 0;
  318. $update_arr['erp_zh'] = '';
  319. $update_arr['bh_no'] = '';
  320. $update_arr['u9sc_no'] = '';
  321. }
  322. $r = $this->bhsq->save($update_arr,$id);
  323. if($r){
  324. echo json_encode(['msg'=>'修改成功','success'=>true]);
  325. }else{
  326. echo json_encode(['msg'=>'修改失败','success'=>false]);
  327. }
  328. exit;
  329. }else{
  330. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  331. }
  332. }
  333. private function _deldyapply(){
  334. if($this->input->method() === 'post'){
  335. $data = $this->input->post();
  336. $id = $data['id'];
  337. $info = $this->bhsq->read($id);
  338. if($info['sq_status'] != 0){
  339. echo json_encode(['msg'=>'此条记录不符合删除条件','success'=>false]);
  340. exit;
  341. }
  342. $r = $this->bhsq->remove($id);
  343. if($r){
  344. echo json_encode(['msg'=>'删除成功','success'=>true]);
  345. }else{
  346. echo json_encode(['msg'=>'删除失败','success'=>false]);
  347. }
  348. exit;
  349. }else{
  350. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  351. }
  352. }
  353. //备货申请单的
  354. private function _dyapplysave(){
  355. if($this->input->method() === 'post'){
  356. $data = $this->input->post();
  357. $id = (int)$data['id'];
  358. $val = $this->input->post('val',true);
  359. $column = $data['column'];
  360. if($column == 'ccwl_num'){
  361. $update_arr = [
  362. 'ccwl_num'=>(int)$val,
  363. 'ck_num'=>(int)$val,
  364. ];
  365. }elseif($column == 'sku'){
  366. $update_arr = [
  367. 'sku'=>$val,
  368. ];
  369. }elseif($column == 'ck_num'){
  370. $update_arr = [
  371. 'ck_num'=>(int)$val,
  372. ];
  373. }elseif($column == 'drck'){
  374. $update_arr = [
  375. 'drck'=>(int)$val,
  376. ];
  377. }else{
  378. echo json_encode(['msg'=>'修改信息不合规','success'=>false]);
  379. exit;
  380. }
  381. $r = $this->bhsq->save($update_arr,$id);
  382. if($r){
  383. echo json_encode(['msg'=>'修改成功','success'=>true]);
  384. }else{
  385. echo json_encode(['msg'=>'修改失败','success'=>false]);
  386. }
  387. exit;
  388. }else{
  389. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  390. }
  391. }
  392. private function _dyapplyexcel(){
  393. if($this->input->method() === 'post'){
  394. $data = $this->input->post('list',true);
  395. if(empty($data)){
  396. $json_data = $this->input->raw_input_stream;
  397. $tmp_data = json_decode($json_data,true);
  398. $data = $tmp_data['list'];
  399. if(empty($data)){
  400. echo json_encode(['success'=>false,'msg'=>'未获取要保存的数据']);
  401. exit;
  402. }
  403. }
  404. $shop_list = $this->shop->find_all("1=1","id,shortname,type");
  405. $shop_list = array_column($shop_list,null,'shortname');
  406. $time = strtotime(date("Y-m-d"),time());
  407. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  408. if(empty($info)){
  409. $num = 1;
  410. }else{
  411. $arr = explode('-',$info['sb_no']);
  412. $num = (int)$arr[2]+1;
  413. }
  414. $time = time();
  415. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  416. $sb_no = "SQ-".date("ymd")."-".$num;
  417. $insert_arr = [];
  418. $error_list= [];
  419. foreach($data as $k=>$v){
  420. $shopshortname = trim($v[4]);
  421. if($shopshortname == '无'){
  422. $shop_info = [
  423. 'id'=>0,
  424. 'type'=>0,
  425. ];
  426. }else{
  427. $shop_info = isset($shop_list[$shopshortname])?$shop_list[$shopshortname]:[];
  428. if(empty($shop_info)){
  429. $error_list[] = [
  430. 'msg'=>"第".($k+1).'行店铺不存在,请核对表格信息'.$shopshortname,
  431. ];
  432. continue;
  433. }
  434. }
  435. $num = (int)$v[3];
  436. if(empty($num)){
  437. $error_list[] = [
  438. 'msg'=>"第".($k+1).'行数量不能为空,请核对表格信息',
  439. ];
  440. continue;
  441. }
  442. $tmp_time = trim($v[0]);
  443. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tmp_time)) {
  444. $add_time = strtotime($tmp_time);
  445. }else{
  446. $error_list[] = [
  447. 'msg'=>"第".($k+1).'行日期格式不正确,请核对表格信息',
  448. ];
  449. continue;
  450. }
  451. if(empty($v[5])){
  452. $error_list[] = [
  453. 'msg'=>"第".($k+1).'行申请人信息不能为空,请核对表格信息',
  454. ];
  455. continue;
  456. }
  457. if(empty($v[1])){
  458. $error_list[] = [
  459. 'msg'=>"第".($k+1).'行产品信息不能为空,请核对表格信息',
  460. ];
  461. continue;
  462. }
  463. $insert_arr[] = [
  464. 'sb_no'=>$sb_no,
  465. 'sku'=>trim($v[2]),
  466. 'title'=>trim($v[1]),
  467. 'shop_id'=>$shop_info['id'],
  468. 'plat_id'=>$shop_info['type'],
  469. 'sqr'=>trim($v[5]),
  470. 'sq_num'=>$num,
  471. 'ccwl_num'=>$num,
  472. 'ck_num'=>$num,
  473. 'sq_status'=>1,
  474. 'remark'=>$v[6],
  475. 'add_time'=>$add_time,
  476. 'real_time'=>$time,
  477. 'update_time'=>$time,
  478. ];
  479. }
  480. if(empty($insert_arr)){
  481. echo json_encode(['success'=>false,'msg'=>'可存储数据为空','error_list'=>$error_list]);
  482. exit;
  483. }
  484. $r =$this->db->insert_batch('bhsq',$insert_arr);
  485. if($r){
  486. if(empty($error_list)){
  487. echo json_encode(['success'=>true,'msg'=>'添加成功']);
  488. }else{
  489. echo json_encode(['success'=>true,'msg'=>'添加成功','error_list'=>$error_list]);
  490. }
  491. }else{
  492. echo json_encode(['success'=>false,'msg'=>'添加失败','error_list'=>$error_list]);
  493. }
  494. exit;
  495. }else{
  496. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  497. exit;
  498. }
  499. }
  500. //仓储物流部的备货申请单的列表
  501. private function _ccwlshlist(){
  502. if($this->input->method() === 'post'){
  503. $vip_id = $this->input->post('vip_id',true);
  504. $page = $this->input->post('page',true);
  505. $perpage = $this->input->post('perpage',true);
  506. $sqr = $this->input->post('sqr',true);
  507. $sqr = trim($sqr);
  508. $shop_id = $this->input->post('shop_id',true);
  509. $plat_id = $this->input->post('plat_id',true);
  510. $shop_ids = $this->input->post('shop_ids',true);
  511. $ktime = $this->input->post('ktime',true);
  512. $jtime = $this->input->post('jtime',true);
  513. $ktime = strtotime($ktime);
  514. $jtime = strtotime($jtime);
  515. $where = "sq_status = 2 and ccwl_status = 0 ";
  516. $where .= " and add_time >= ".$ktime." and add_time < ".$jtime." ";
  517. if(!empty($sqr)){
  518. $where .= " and sqr = '".$sqr."' ";
  519. }
  520. if(!empty($shop_id)){
  521. $where .= " and shop_id = ".$shop_id." ";
  522. }else{
  523. if($vip_id == 1){
  524. }else{
  525. $where .= " and shop_id in (".$shop_ids.") ";
  526. }
  527. }
  528. if(!empty($plat_id)){
  529. $where .= " and plat_id = ".$plat_id." ";
  530. }
  531. //数据排序
  532. $order_str = "id desc";
  533. if(empty($page))
  534. {
  535. $start = 0;
  536. $perpage = 1;
  537. }
  538. else
  539. {
  540. $start = ($page - 1)*$perpage;
  541. }
  542. $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);
  543. if(empty($list)){
  544. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  545. echo json_encode($rows);exit;
  546. }
  547. $shop_list = $this->shop->find_all("1=1","id,shopname");
  548. $shop_list = array_column($shop_list,'shopname','id');
  549. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  550. $plat_list = array_column($plat_list,'title','id');
  551. foreach($list as $k=>$v){
  552. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  553. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  554. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  555. if($v['erp_check'] == 1){
  556. $list[$k]['sku'] = "<a style='color:red' href='javascript:void(0)' onclick='addnewgoods(this)' id='edit_sku_".$v['id']."' data-id='".$v['id']."'>".$v['sku']."</a> <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  557. }else{
  558. $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  559. }
  560. $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>";
  561. $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>";
  562. unset($list[$k]['erp_check']);
  563. }
  564. $total = $this->bhsq->find_count($where);
  565. $pagenum = ceil($total/$perpage);
  566. $over = $total-($start+$perpage);
  567. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  568. echo json_encode($rows);exit;
  569. }else{
  570. $user = $this->user->get_api($_SESSION['api']);
  571. $usersp = explode('|',trim($user['shop'],'|'));
  572. $this->data['usersp'] = implode(",",$usersp);
  573. $vip_id = 0;
  574. if(in_array($user['id'],[10,28])){
  575. $vip_id = 1;
  576. }
  577. $this->data['vip_id'] = $vip_id;
  578. $this->_Template('beihuogl_ccwlshlist',$this->data);
  579. }
  580. }
  581. //一键校验选中SKU
  582. private function _ccwlskucheck(){
  583. if($this->input->method() === 'post'){
  584. $data = $this->input->post();
  585. if(empty($data['arr_id'])){
  586. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  587. exit;
  588. }
  589. $list = $this->bhsq->find_all('id in ('.implode(',',$data['arr_id']).')');
  590. $error_list = [];
  591. $success_ids = [];
  592. $errors_ids = [];
  593. foreach($list as $k=>$v){
  594. if(empty($v['sku'])){
  595. $error_list[] = [
  596. 'msg'=>$v['value'].'请录入SKU',
  597. ];
  598. $errors_ids[] = $v['id'];
  599. continue;
  600. }
  601. $num = $this->goods->find_count("sku = '".$v['sku']."'");
  602. if(!empty($num)){
  603. $success_ids[] = $v['id'];
  604. continue;
  605. }
  606. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  607. if(empty($whlabel_info)){
  608. $error_list[] = [
  609. 'msg'=>$v['sku'].'未在进销存浏览那找到对应信息',
  610. ];
  611. $errors_ids[] = $v['id'];
  612. }
  613. }
  614. if(!empty($error_list)){
  615. $this->db->where_in('id', $errors_ids);
  616. $this->db->update('bhsq', ['erp_check'=>1]);
  617. }
  618. if(!empty($success_ids)){
  619. $this->db->where_in('id', $success_ids);
  620. $this->db->update('bhsq', ['erp_check'=>0]);
  621. }
  622. if(empty($error_list)){
  623. echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
  624. exit;
  625. }else{
  626. echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
  627. exit;
  628. }
  629. }else{
  630. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  631. exit;
  632. }
  633. }
  634. private function _ccwlbhzhcheck(){
  635. if($this->input->method() === 'post'){
  636. exit("请求方式不对");
  637. }else{
  638. $bh_no = $this->input->get('bh_no',true);
  639. if(empty($bh_no)){
  640. exit("不符合下载要求");
  641. }
  642. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  643. if(empty($info)){
  644. exit("备货单料品信息为空");
  645. }
  646. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  647. $final_list= [];
  648. $shop_list = $this->shop->find_all("1=1","id,shopname");
  649. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  650. $shop_list = array_column($shop_list,'shopname','id');
  651. $plat_list = array_column($plat_list,'title','id');
  652. $final_list= [];
  653. foreach($list as $k=>$v){
  654. $final_list[] = [
  655. 'bh_no'=>$v['bh_no'],
  656. 'shop'=>isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无",
  657. 'plat'=>isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无",
  658. 'zh'=>$v['title'],
  659. 'erp_zh'=>$v['erp_zh'],
  660. 'jm'=>$v['jm'],
  661. 'sqr'=>$v['sqr'],
  662. 'sq_num'=>$v['ccwl_num'],
  663. 'public_time'=>date("Y-m-d",$v['public_time']),
  664. 'remark'=>$v['remark'],
  665. ];
  666. }
  667. $filename = $bh_no."中文品名核对.xls";
  668. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  669. <head>
  670. <!--[if gte mso 9]><xml>
  671. <x:ExcelWorkbook>
  672. <x:ExcelWorksheets>
  673. <x:ExcelWorksheet>
  674. <x:Name>EXCEL</x:Name>
  675. <x:WorksheetOptions>
  676. <x:Print>
  677. <x:ValidPrinterInfo />
  678. </x:Print>
  679. </x:WorksheetOptions>
  680. </x:ExcelWorksheet>
  681. </x:ExcelWorksheets>
  682. </x:ExcelWorkbook>
  683. </xml>
  684. <![endif]-->
  685. </head><body>";
  686. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  687. $str .= "<tr><td>备货单号</td><td>店铺</td><td>平台</td><td>中文名称</td><td>ERP仓库品名</td><td>u9料号</td><td>申请人</td><td>申报数量<td>申请时间</td><td>备注</td></tr>";
  688. foreach ($final_list as $key=>$value)
  689. {
  690. if($value['erp_zh'] != $value['zh']){
  691. $str .= "<tr style='background-color: red;'>";
  692. }else{
  693. $str .= "<tr>";
  694. }
  695. $str .= "<td>". $value['bh_no']. "</td>";
  696. $str .= "<td>". $value['shop']. "</td>";
  697. $str .= "<td>". $value['plat']. "</td>";
  698. $str .= "<td>". $value['zh']. "</td>";
  699. $str .= "<td>". $value['erp_zh']. "</td>";
  700. $str .= "<td>". $value['jm']. "</td>";
  701. $str .= "<td>". $value['sqr']. "</td>";
  702. $str .= "<td>". $value['sq_num']. "</td>";
  703. $str .= "<td>". $value['public_time']. "</td>";
  704. $str .= "<td>". $value['remark']. "</td>";
  705. $str .= "</tr>";
  706. }
  707. $str .= "</table></body></html>";
  708. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  709. header( "Content-type: application/octet-stream" );
  710. header( "Content-Disposition: attachment; filename=".$filename );
  711. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  712. header( "Pragma: no-cache" );
  713. header( "Expires: 0" );
  714. exit($str);
  715. }
  716. }
  717. private function _ccwlbhdownload(){
  718. if($this->input->method() === 'get'){
  719. $query = $this->input->get(null,true);
  720. if(empty($query['excel'])){
  721. exit("不符合下载要求");
  722. }
  723. if($query['excel'] != 'erp'){
  724. exit("不符合下载要求");
  725. }
  726. $ids = $this->input->get('ids',true);
  727. if(empty($ids)){
  728. exit("请选择要下载的备货单");
  729. }
  730. $arr_id = [];
  731. if(stripos($ids,'|') !== false){
  732. $arr_id = explode('|', $ids);
  733. }else{
  734. $arr_id[] = $ids;
  735. }
  736. if(empty($arr_id)){
  737. exit("请选择要下载的备货单-1");
  738. }
  739. $list = $this->bhccwl->find_all('id in ('.implode(',',$arr_id).')');
  740. $batch_nos = array_column($list,'bh_no');
  741. $batch_no_str = '';
  742. foreach($batch_nos as $k=>$v){
  743. $batch_no_str .= "'".$v."',";
  744. }
  745. $batch_no_str = trim($batch_no_str,',');
  746. $bh_list = $this->bhsq->find_all("bh_no in (".$batch_no_str.")");
  747. if(empty($bh_list)){
  748. exit("备货单料品信息为空");
  749. }
  750. $shop_list = $this->shop->find_all("1=1","id,shopname");
  751. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  752. $shop_list = array_column($shop_list,'shopname','id');
  753. $plat_list = array_column($plat_list,'title','id');
  754. $final_list= [];
  755. foreach($bh_list as $k=>$v){
  756. $final_list[] = [
  757. 'bh_no'=>$v['bh_no'],
  758. 'shop'=>isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无",
  759. 'plat'=>isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无",
  760. 'zh'=>$v['title'],
  761. 'jm'=>$v['jm'],
  762. 'sqr'=>$v['sqr'],
  763. 'sq_num'=>$v['ccwl_num'],
  764. 'public_time'=>date("Y-m-d",$v['public_time']),
  765. 'remark'=>$v['remark'],
  766. ];
  767. }
  768. $filename = "备货生产单.xls";
  769. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  770. <head>
  771. <!--[if gte mso 9]><xml>
  772. <x:ExcelWorkbook>
  773. <x:ExcelWorksheets>
  774. <x:ExcelWorksheet>
  775. <x:Name>EXCEL</x:Name>
  776. <x:WorksheetOptions>
  777. <x:Print>
  778. <x:ValidPrinterInfo />
  779. </x:Print>
  780. </x:WorksheetOptions>
  781. </x:ExcelWorksheet>
  782. </x:ExcelWorksheets>
  783. </x:ExcelWorkbook>
  784. </xml>
  785. <![endif]-->
  786. </head><body>";
  787. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  788. $str .= "<tr><td>备货单号</td><td>店铺</td><td>平台</td><td>中文名称</td><td>u9料号</td><td>申请人</td><td>申报数量<td>申请时间</td><td>备注</td></tr>";
  789. foreach ($final_list as $key=>$value)
  790. {
  791. $str .= "<tr>";
  792. $str .= "<td>". $value['bh_no']. "</td>";
  793. $str .= "<td>". $value['shop']. "</td>";
  794. $str .= "<td>". $value['plat']. "</td>";
  795. $str .= "<td>". $value['zh']. "</td>";
  796. $str .= "<td>". $value['jm']. "</td>";
  797. $str .= "<td>". $value['sqr']. "</td>";
  798. $str .= "<td>". $value['sq_num']. "</td>";
  799. $str .= "<td>". $value['public_time']. "</td>";
  800. $str .= "<td>". $value['remark']. "</td>";
  801. $str .= "</tr>";
  802. }
  803. $str .= "</table></body></html>";
  804. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  805. header( "Content-type: application/octet-stream" );
  806. header( "Content-Disposition: attachment; filename=".$filename );
  807. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  808. header( "Pragma: no-cache" );
  809. header( "Expires: 0" );
  810. exit($str);
  811. }
  812. }
  813. //仓储物流合成备货单
  814. private function _ccwlbhmake(){
  815. if($this->input->method() === 'post'){
  816. $data = $this->input->post();
  817. if(empty($data['arr_id'])){
  818. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  819. exit;
  820. }
  821. $bh_no = $data['bh_no'];
  822. $select_id = $data['arr_id'];
  823. if(empty($select_id)){
  824. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  825. exit;
  826. }
  827. if(empty($bh_no)){
  828. $tmp_time = strtotime(date("Y-m-d"),time());
  829. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  830. $num = $num+1;
  831. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  832. $bh_no = "BH-".date("ymd")."-".$num;
  833. }else{
  834. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  835. if(!empty($info)){
  836. echo json_encode(['success'=>false,'msg'=>'生成的备货单编号已经存在']);
  837. exit;
  838. }
  839. }
  840. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  841. foreach($list as $k=>$v){
  842. if(empty($v['sku'])){
  843. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  844. exit;
  845. }
  846. }
  847. $classid = $this->logic_u9tools->getClass();
  848. $typeclass = $this->logic_u9tools->getTypeClass();
  849. foreach($list as $k=>$v){
  850. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm,zh','id desc');
  851. if(empty($whlabel_info)){
  852. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  853. if(empty($whlabel_info)){
  854. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  855. exit;
  856. }
  857. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  858. $this->bhsq->save([
  859. 'jm'=>$r['jm'],
  860. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  861. 'features'=>$whlabel_info['features'],
  862. 'erp_zh'=>$r['zh'],
  863. ],$v['id']);
  864. }else{
  865. $this->bhsq->save([
  866. 'jm'=>$whlabel_info['jm'],
  867. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  868. 'features'=>$whlabel_info['features'],
  869. 'erp_zh'=>$whlabel_info['zh'],
  870. ],$v['id']);
  871. }
  872. }
  873. $this->db->trans_start();
  874. $this->db->where_in('id',$select_id);
  875. $this->db->update('bhsq',[
  876. 'bh_no'=>$bh_no,
  877. 'sq_status'=>4,
  878. 'ccwl_status'=>1,
  879. ]);
  880. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  881. $this->db->where_in('id',$select_id);
  882. $query = $this->db->get('bhsq');
  883. $result = $query->row();
  884. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  885. $time = time();
  886. $this->bhccwl->insert([
  887. 'bh_no'=>$bh_no,
  888. 'status'=>0,
  889. 'num'=>$total_ccwl_num,
  890. 'create_time'=>$time,
  891. 'update_time'=>$time,
  892. ]);
  893. if($this->db->trans_status() === FALSE){
  894. $this->db->trans_rollback();
  895. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  896. exit;
  897. }else{
  898. $this->db->trans_commit();
  899. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  900. exit;
  901. }
  902. }else{
  903. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  904. exit;
  905. }
  906. }
  907. private function getU9Drck($features){
  908. if(stripos($features,'-126-') !== false)
  909. {
  910. $drck = '12003';//进入发条库
  911. }
  912. else if(stripos($features,'-127-') !== false)
  913. {
  914. $drck = '12004';//进入发块库
  915. }
  916. else
  917. {
  918. $drck = '12006';//其它进入完成库
  919. }
  920. return $drck;
  921. }
  922. //仓储物流部的备货单列表
  923. private function _ccwlbhindex(){
  924. if($this->input->method() === 'post'){
  925. $page = $this->input->post('page',true);
  926. $perpage = $this->input->post('perpage',true);
  927. $bh_no = $this->input->post('bh_no',true);
  928. $status = $this->input->post('status',true);
  929. $ktime = $this->input->post('ktime',true);
  930. $jtime = $this->input->post('jtime',true);
  931. $ktime = strtotime($ktime);
  932. $jtime = strtotime($jtime);
  933. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  934. if(!empty($bh_no)){
  935. $where .= " and bh_no = '".$bh_no."' ";
  936. }
  937. if($status > -1){
  938. $where .= " and status = ".$status." ";
  939. }
  940. //数据排序
  941. $order_str = "id desc";
  942. if(empty($page))
  943. {
  944. $start = 0;
  945. $perpage = 1;
  946. }
  947. else
  948. {
  949. $start = ($page - 1)*$perpage;
  950. }
  951. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time,ck_status",$order_str,$start,$perpage);
  952. if(empty($list)){
  953. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  954. echo json_encode($rows);exit;
  955. }
  956. $status_list = $this->bhccwl->getStatus();
  957. foreach($list as $k=>$v){
  958. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  959. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  960. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  961. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  962. $str = "";
  963. if($v['status'] == 0){
  964. $str .= "<div style='text-align:center;'>";
  965. $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>";
  966. $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>";
  967. $str .= "</div>";
  968. }
  969. if($v['status'] == 1 && $v['ck_status'] == 0){
  970. $str .= "<div style='text-align:center;'>";
  971. $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>";
  972. $str .= "</div>";
  973. }
  974. if($v['status'] == 2 && $v['ck_status'] == 0){
  975. $str .= "<div style='text-align:center;'>";
  976. $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>";
  977. $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>";
  978. $str .= "</div>";
  979. }
  980. $str .= "<div style='text-align:center;'>";
  981. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#CD5C5C;padding:4px 10px;border-radius:5px;font-size:15px' data-bh_no='".$v['bh_no']."' onclick='checkdownload(this)'>品名校验</a>";
  982. $str .= "</div>";
  983. $list[$k]['update_time'] = $str;
  984. unset($list[$k]['ck_status']);
  985. }
  986. $total = $this->bhccwl->find_count($where);
  987. $pagenum = ceil($total/$perpage);
  988. $over = $total-($start+$perpage);
  989. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  990. echo json_encode($rows);exit;
  991. }else{
  992. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  993. }
  994. }
  995. //仓储物流部备货 在编辑页面添加数据
  996. private function _ccwlbhsavexzbh(){
  997. if($this->input->method() === 'post'){
  998. $data = $this->input->post();
  999. $select_id = $data['select_id'];
  1000. $id = $data['id'];
  1001. $bh_no = $data['bh_no'];
  1002. if(empty($select_id)){
  1003. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  1004. exit;
  1005. }
  1006. $info = $this->bhccwl->read($id);
  1007. if(empty($info)){
  1008. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  1009. exit;
  1010. }
  1011. if($info['bh_no'] != $bh_no){
  1012. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  1013. exit;
  1014. }
  1015. $bh_no = $info['bh_no'];
  1016. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  1017. foreach($list as $k=>$v){
  1018. if(empty($v['sku'])){
  1019. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  1020. exit;
  1021. }
  1022. if(!empty($v['bh_no'])){
  1023. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  1024. exit;
  1025. }
  1026. }
  1027. $classid = $this->logic_u9tools->getClass();
  1028. $typeclass = $this->logic_u9tools->getTypeClass();
  1029. foreach($list as $k=>$v){
  1030. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm,zh','id desc');
  1031. if(empty($whlabel_info)){
  1032. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  1033. if(empty($whlabel_info)){
  1034. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  1035. exit;
  1036. }
  1037. if(empty($v['jm'])){
  1038. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  1039. $this->bhsq->save([
  1040. 'jm'=>$r['jm'],
  1041. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  1042. 'features'=>$whlabel_info['features'],
  1043. 'erp_zh'=>$r['zh'],
  1044. ],$v['id']);
  1045. $list[$k]['jm'] = $r['jm'];
  1046. }
  1047. }else{
  1048. $this->bhsq->save([
  1049. 'jm'=>$whlabel_info['jm'],
  1050. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  1051. 'features'=>$whlabel_info['features'],
  1052. 'erp_zh'=>$whlabel_info['zh'],
  1053. ],$v['id']);
  1054. $list[$k]['jm'] = $whlabel_info['jm'];
  1055. }
  1056. }
  1057. $status_list = $this->bhccwl->getStatus();
  1058. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  1059. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1060. $plat_list = array_column($plat_list,'title','id');
  1061. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1062. $shop_list = array_column($shop_list,'shopname','id');
  1063. foreach($list as $k=>$v){
  1064. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1065. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1066. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1067. $list[$k]['bh_no'] = $info['bh_no'];
  1068. }
  1069. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  1070. }else{
  1071. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  1072. exit;
  1073. }
  1074. }
  1075. private function _ccwlbhedit($arg_array){
  1076. if($this->input->method() === 'post'){
  1077. $select_id = $this->input->post('arr_id',true);
  1078. if(empty($select_id)){
  1079. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  1080. exit;
  1081. }
  1082. $id = $this->input->post('id',true);
  1083. $info = $this->bhccwl->read($id);
  1084. $bh_no = $info['bh_no'];
  1085. $this->db->where_in('id',$select_id);
  1086. $this->db->update('bhsq',[
  1087. 'bh_no'=>$bh_no,
  1088. 'sq_status'=>4,
  1089. 'ccwl_status'=>1,
  1090. ]);
  1091. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  1092. $this->db->where_in('id',$select_id);
  1093. $query = $this->db->get('bhsq');
  1094. $result = $query->row();
  1095. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  1096. $time = time();
  1097. $this->bhccwl->save([
  1098. 'num'=>$total_ccwl_num,
  1099. 'update_time'=>$time,
  1100. ],$info['id']);
  1101. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1102. }else{
  1103. $id = $arg_array[0];
  1104. $info = $this->bhccwl->find("id = ".$id);
  1105. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  1106. $status_list = $this->bhccwl->getStatus();
  1107. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  1108. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1109. $plat_list = array_column($plat_list,'title','id');
  1110. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1111. $shop_list = array_column($shop_list,'shopname','id');
  1112. foreach($list as $k=>$v){
  1113. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1114. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1115. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1116. }
  1117. // $this->data['info'] = $info;
  1118. $this->data['list'] = $list;
  1119. $this->data['info'] = $info;
  1120. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  1121. }
  1122. }
  1123. private function _ccwldelitem(){
  1124. if($this->input->method() === 'post'){
  1125. $data = $this->input->post();
  1126. $id = $data['id'];
  1127. $bh_no = $data['bh_no'];
  1128. $info = $this->bhsq->read($id);
  1129. $ccwl_num = $info['ccwl_num'];
  1130. if(empty($info)){
  1131. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1132. }
  1133. if(empty($info['bh_no'])){
  1134. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  1135. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1136. }else{
  1137. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1138. }
  1139. }
  1140. if($info['bh_no'] != $bh_no){
  1141. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1142. }
  1143. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  1144. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  1145. $this->db->trans_start();
  1146. $this->bhccwl->save([
  1147. 'num'=>$ccwl_info['num'],
  1148. ],$ccwl_info['id']);
  1149. $this->bhsq->save([
  1150. 'sq_status'=>2,
  1151. 'ccwl_status'=>0,
  1152. 'bh_no'=>''
  1153. ],$id);
  1154. if($this->db->trans_status() === FALSE){
  1155. $this->db->trans_rollback();
  1156. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  1157. }else{
  1158. $this->db->trans_commit();
  1159. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1160. }
  1161. }else{
  1162. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1163. }
  1164. }
  1165. private function _ccwleditxzbh(){
  1166. if($this->input->method() === 'post'){
  1167. $data = $this->input->post();
  1168. //超过三月没审核的 就不展示了
  1169. $time = time() - 60*24*3600;
  1170. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  1171. if(!empty($data['sqr'])){
  1172. $where .= " and sqr = '".$data['sqr']."' ";
  1173. }
  1174. if(!empty($data['shop_id'])){
  1175. $where .= " and shop_id = ".$data['shop_id']." ";
  1176. }
  1177. if(!empty($data['plat_id'])){
  1178. $where .= " and plat_id = ".$data['plat_id']." ";
  1179. }
  1180. if(!empty($data['sku'])){
  1181. $where .= " and sku = '".$data['sku']."' ";
  1182. }
  1183. $order_str = "id desc";
  1184. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  1185. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1186. $shop_list = array_column($shop_list,'shopname','id');
  1187. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1188. $plat_list = array_column($plat_list,'title','id');
  1189. foreach($list as $k=>$v){
  1190. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1191. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1192. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1193. }
  1194. if(empty($list)){
  1195. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  1196. }else{
  1197. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  1198. }
  1199. }else{
  1200. $data = $this->input->get();
  1201. $this->data['id'] = $data['id'];
  1202. $this->data['bh_no'] = $data['bh_no'];
  1203. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1204. $this->data['plat_list'] = $plat_list;
  1205. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  1206. }
  1207. }
  1208. private function _ccwlbhsave(){
  1209. if($this->input->method() === 'post'){
  1210. $data = $this->input->post();
  1211. $id = $data['id'];
  1212. $val = $data['val'];
  1213. $column = $data['column'];
  1214. $update_arr = [];
  1215. if($column == 'status'){
  1216. $update_arr = [
  1217. 'status'=>(int)$val,
  1218. 'update_time'=>time(),
  1219. 'public_time'=>time(),
  1220. ];
  1221. if($val == 2){
  1222. $info = $this->bhccwl->read($id);
  1223. if($info['status'] == 1 && $info['ck_status'] == 0){
  1224. }else{
  1225. echo json_encode(['success'=>false,'msg'=>'状态不对,不可撤回']);exit;
  1226. }
  1227. }
  1228. }else{
  1229. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1230. }
  1231. $r = $this->bhccwl->save($update_arr,$id);
  1232. if($r){
  1233. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1234. }else{
  1235. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  1236. }
  1237. }else{
  1238. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1239. }
  1240. }
  1241. //仓库的备货单列表
  1242. private function _ckbhindex(){
  1243. if($this->input->method() === 'post'){
  1244. $page = $this->input->post('page',true);
  1245. $perpage = $this->input->post('perpage',true);
  1246. $bh_no = $this->input->post('bh_no',true);
  1247. $status = $this->input->post('status',true);
  1248. $ktime = $this->input->post('ktime',true);
  1249. $jtime = $this->input->post('jtime',true);
  1250. $ktime = strtotime($ktime);
  1251. $jtime = strtotime($jtime);
  1252. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1253. if(!empty($bh_no)){
  1254. $where .= " and bh_no = '".$bh_no."' ";
  1255. }
  1256. if($status > -1){
  1257. $where .= " and status = ".$status." ";
  1258. }
  1259. //数据排序
  1260. $order_str = "id desc";
  1261. if(empty($page))
  1262. {
  1263. $start = 0;
  1264. $perpage = 1;
  1265. }
  1266. else
  1267. {
  1268. $start = ($page - 1)*$perpage;
  1269. }
  1270. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1271. if(empty($list)){
  1272. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1273. echo json_encode($rows);exit;
  1274. }
  1275. $status_list = $this->bhccwl->getCkStatus();
  1276. foreach($list as $k=>$v){
  1277. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1278. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1279. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1280. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1281. $str = "";
  1282. if($v['ck_status'] == 0){
  1283. $str .= "<div style='text-align:center;'>";
  1284. $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>";
  1285. $str .= "<a href='/beihuogl/ckexcel/".$v['id']."' style='margin-right:4px;color: #fff;background-color:#5F9EA0;padding:4px 10px;border-radius:5px;font-size:15px'>下载</a>";
  1286. $str .= "</div>";
  1287. }
  1288. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1289. $str .= "<div style='text-align:center;'>";
  1290. $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>";
  1291. $str .= "</div>";
  1292. }
  1293. if($v['ck_status'] > 2){
  1294. $str .= "<div style='text-align:center;'>";
  1295. $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>";
  1296. $str .= "</div>";
  1297. }
  1298. $list[$k]['update_time'] = $str;
  1299. }
  1300. $total = $this->bhccwl->find_count($where);
  1301. $pagenum = ceil($total/$perpage);
  1302. $over = $total-($start+$perpage);
  1303. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1304. echo json_encode($rows);exit;
  1305. }else{
  1306. $this->_Template('beihuogl_ckbhindex',$this->data);
  1307. }
  1308. }
  1309. private function _ckbhedit($arg_array){
  1310. if($this->input->method() === 'post'){
  1311. $id = $this->input->post('id',true);
  1312. $bh_no = $this->input->post('bh_no',true);
  1313. $info = $this->bhccwl->read($id);
  1314. if(empty($info)){
  1315. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1316. }
  1317. if($info['ck_status'] == 0 && $info['status'] == 1){
  1318. }else{
  1319. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1320. }
  1321. if($info['bh_no'] != $bh_no){
  1322. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1323. }
  1324. $num = 0;
  1325. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1326. foreach($list as $k=>$v){
  1327. $num += $v['ck_num'];
  1328. }
  1329. $r = $this->bhccwl->save([
  1330. 'ck_status'=>1,
  1331. 'ck_num'=>$num,
  1332. 'update_time'=>time(),
  1333. 'ckpublic_time'=>time(),
  1334. ],$id);
  1335. if($r){
  1336. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1337. }else{
  1338. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1339. }
  1340. }else{
  1341. $id = $arg_array[0];
  1342. $info = $this->bhccwl->find("id = ".$id);
  1343. $status_list = $this->bhccwl->getCkStatus();
  1344. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1345. $drck_list = $this->bhccwl->getDrck();
  1346. $this->data['drck_list'] = $drck_list;
  1347. $this->data['drck_json'] = json_encode($drck_list);
  1348. $this->data['info'] = $info;
  1349. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1350. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1351. $shop_list = array_column($shop_list,'shopname','id');
  1352. foreach($list as $k=>$v){
  1353. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1354. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1355. }
  1356. $this->data['list'] = $list;
  1357. $this->_Template('beihuogl_ckbhedit',$this->data);
  1358. }
  1359. }
  1360. private function _makeu9scd($arg_array){
  1361. if($this->input->method() === 'post'){
  1362. $data = $this->input->post(null,true);
  1363. $info = $this->bhccwl->read($data['id']);
  1364. if(empty($info)){
  1365. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1366. }
  1367. if($info['ck_status'] == 1 && $info['status'] == 1){
  1368. }else{
  1369. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1370. exit;
  1371. }
  1372. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1373. $params = [
  1374. 'org_code'=>"120",//组织代码 龙盈工厂
  1375. 'djhlx'=>'2000',//单号类型 备货生产单
  1376. 'scbm_code'=>"12008",//龙盈生产部门
  1377. "time"=>time(),
  1378. 'owner_org_code'=>"120",
  1379. 'title'=>$info['bh_no'],
  1380. 'shipremarks'=>$info['bh_no'],
  1381. ];
  1382. $final_list = [];
  1383. foreach($list as $k=>$v){
  1384. $final_list[] =[
  1385. 'do_id'=>$v['id'],
  1386. 'drck'=>$v['drck'],
  1387. 'jm'=>$v['jm'],
  1388. 'sl'=>$v['ck_num'],
  1389. ];
  1390. }
  1391. $params['list'] = $final_list;
  1392. $token = $this->settingtest->get_yytoken_120();
  1393. $res = $this->apiyyv1->scdCreate($params,$token);
  1394. if(empty($res[0]['Data'])){
  1395. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1396. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1397. }
  1398. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1399. $r_s_list = $res[0]['Data'];
  1400. foreach($list as $k=>$v){
  1401. $list[$k]['u9_data'] = $r_s_list[$k];
  1402. }
  1403. //m_isSucess
  1404. $flag_status = 0;//判断是否有创建失败的
  1405. $u9sc_status = 0;//判断是否有创建成功的
  1406. foreach($list as $k=>$v){
  1407. if($v['u9_data']['m_isSucess']== 1){
  1408. $u9sc_status += 1;
  1409. $this->bhsq->save([
  1410. 'is_u9sc'=>1,
  1411. 'u9sc_no'=>$v['u9_data']['m_code'],
  1412. ],$v['id']);
  1413. }else{
  1414. if($v['ck_num'] > 0){
  1415. $flag_status += 0;
  1416. $this->bhsq->save([
  1417. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1418. ],$v['id']);
  1419. }else{
  1420. $u9sc_status += 1;
  1421. }
  1422. }
  1423. }
  1424. $len = count($list);
  1425. //都创建失败了 就直接gg
  1426. if($u9sc_status == 0){
  1427. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1428. }
  1429. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1430. $this->bhccwl->save([
  1431. 'ck_status'=>2,
  1432. ],$info['id']);
  1433. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1434. }
  1435. if($u9sc_status == $len){
  1436. $this->bhccwl->save([
  1437. 'ck_status'=>3,
  1438. ],$info['id']);
  1439. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1440. }
  1441. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1442. }else{
  1443. $id = $arg_array[0];
  1444. $info = $this->bhccwl->read($id);
  1445. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1446. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1447. $shop_list = array_column($shop_list,'shopname','id');
  1448. $drck_list = $this->bhccwl->getDrck();
  1449. $status_list = $this->bhccwl->getCkStatus();
  1450. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1451. foreach($list as $k=>$v){
  1452. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1453. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1454. }
  1455. $this->data['list'] = $list;
  1456. $this->data['info'] = $info;
  1457. $this->_Template('beihuogl_makeu9scd',$this->data);
  1458. }
  1459. }
  1460. private function _ddscscd(){
  1461. if($this->input->method() === 'post'){
  1462. $id = $this->input->post('id',true);
  1463. $bh_no = $this->input->post('bh_no',true);
  1464. $bhsq_info = $this->bhsq->read($id);
  1465. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1466. if(empty($bhccwl_info)){
  1467. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1468. }
  1469. // if($bhccwl_info['ck_status'] != 1){
  1470. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1471. // exit;
  1472. // }
  1473. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1474. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1475. exit;
  1476. }
  1477. if(!empty($bhsq_info['u9sc_no'])){
  1478. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1479. exit;
  1480. }
  1481. $params = [
  1482. 'org_code'=>"120",//组织代码 龙盈工厂
  1483. 'djhlx'=>'2000',//单号类型 备货生产单
  1484. 'scbm_code'=>"12008",//龙盈生产部门
  1485. "time"=>time(),
  1486. 'owner_org_code'=>"120",
  1487. 'title'=>$bhccwl_info['bh_no'],
  1488. 'shipremarks'=>$bhccwl_info['bh_no'],
  1489. ];
  1490. $list[] = [
  1491. 'do_id'=>$bhsq_info['id'],
  1492. 'drck'=>$bhsq_info['drck'],
  1493. 'jm'=>$bhsq_info['jm'],
  1494. 'sl'=>$bhsq_info['ck_num'],
  1495. ];
  1496. $params['list'] = $list;
  1497. $token = $this->settingtest->get_yytoken_120();
  1498. $res = $this->apiyyv1->scdCreate($params,$token);
  1499. if(empty($res[0]['Data'])){
  1500. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1501. }
  1502. if($res[0]['Data'][0]['m_isSucess']== 1){
  1503. $this->bhsq->save([
  1504. 'is_u9sc'=>1,
  1505. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1506. ],$bhsq_info['id']);
  1507. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1508. if(empty($tmp_list)){
  1509. $tmp_status = 3;
  1510. }else{
  1511. $tmp_status = 2;
  1512. }
  1513. $this->bhccwl->save([
  1514. 'ck_status'=>$tmp_status,
  1515. ],$bhccwl_info['id']);
  1516. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1517. }else{
  1518. $this->bhsq->save([
  1519. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1520. ],$bhsq_info['id']);
  1521. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1522. }
  1523. }else{
  1524. exit('No direct script access allowed');
  1525. }
  1526. }
  1527. private function _showckbh($arg_array){
  1528. if($this->input->method() === 'post'){
  1529. exit('No direct script access allowed');
  1530. }
  1531. $id = $arg_array[0];
  1532. $drck_list = $this->bhccwl->getDrck();
  1533. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1534. $shop_list = array_column($shop_list,'shopname','id');
  1535. $info = $this->bhccwl->read($id);
  1536. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1537. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1538. foreach($list as $k=>$v){
  1539. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1540. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1541. }
  1542. $this->data['info'] = $info;
  1543. $this->data['list'] = $list;
  1544. $this->data['list_dcd'] = $list_dcd;
  1545. $this->_Template('beihuogl_showckbh',$this->data);
  1546. }
  1547. //仓库录入调出单
  1548. private function _ckdcd(){
  1549. if($this->input->method() === 'post'){
  1550. $lrdcd = $this->input->post('lrdcd',true);
  1551. if(empty($lrdcd)){
  1552. //列表展示
  1553. $page = $this->input->post('page',true);
  1554. $perpage = $this->input->post('perpage',true);
  1555. $bh_no = $this->input->post('bh_no',true);
  1556. $dcd_no = $this->input->post('dcd_no',true);
  1557. $status = $this->input->post('status',true);
  1558. $ktime = $this->input->post('ktime',true);
  1559. $jtime = $this->input->post('jtime',true);
  1560. $ktime = strtotime($ktime);
  1561. $jtime = strtotime($jtime);
  1562. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1563. if(!empty($bh_no)){
  1564. $where .= " and bh_no = '".$bh_no."' ";
  1565. }
  1566. if($status > -1){
  1567. $where .= " and status = ".$status." ";
  1568. }
  1569. if(!empty($dcd_no)){
  1570. $where .= " and dcd_no = '".$dcd_no."' ";
  1571. }
  1572. //数据排序
  1573. $order_str = "id desc";
  1574. if(empty($page))
  1575. {
  1576. $start = 0;
  1577. $perpage = 1;
  1578. }
  1579. else
  1580. {
  1581. $start = ($page - 1)*$perpage;
  1582. }
  1583. $list = $this->bhdcd->find_all($where,"id,bh_no,dcd_no,drd_no,status,jm,num,kw,create_time,rk_time,is_rk,szkw,printnum",$order_str,$start,$perpage);
  1584. if(empty($list)){
  1585. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1586. echo json_encode($rows);exit;
  1587. }
  1588. $status_list = $this->bhdcd->getStatus();
  1589. foreach($list as $k=>$v){
  1590. $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>";
  1591. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1592. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1593. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1594. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1595. $str = "";
  1596. if(!empty($v['rk_time'])){
  1597. if(empty($v['printnum'])){
  1598. $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>";
  1599. }else{
  1600. $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']."' >打印标签(".$v['printnum'].")</a>";
  1601. }
  1602. }else{
  1603. if($v['is_rk'] == 0){
  1604. $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='dcdrk(this)' data-type='1' data-id='".$v['id']."' data-num='".$v['num']."'>禁止入库</a>";
  1605. }else{
  1606. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#778899;padding:4px 8px;border-radius:5px;font-size:13px' onclick='dcdrk(this)' data-type='2' data-id='".$v['id']."' data-num='".$v['num']."'>允许入库</a>";
  1607. }
  1608. if(empty($v['szkw'])){
  1609. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#9932CC;padding:4px 8px;border-radius:5px;font-size:13px' onclick='dcdyz(this)' data-type='1' data-id='".$v['id']."' data-num='".$v['num']."'>禁止验证</a>";
  1610. }else{
  1611. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color:#00CED1;padding:4px 8px;border-radius:5px;font-size:13px' onclick='dcdyz(this)' data-type='2' data-id='".$v['id']."' data-num='".$v['num']."'>允许验证</a>";
  1612. }
  1613. }
  1614. $list[$k]['rk_time'] = $str;
  1615. unset($list[$k]['is_rk']);
  1616. unset($list[$k]['szkw']);
  1617. unset($list[$k]['printnum']);
  1618. }
  1619. $total = $this->bhdcd->find_count($where);
  1620. $pagenum = ceil($total/$perpage);
  1621. $over = $total-($start+$perpage);
  1622. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1623. echo json_encode($rows);exit;
  1624. }else{
  1625. if(empty($lrdcd)){
  1626. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1627. }
  1628. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1629. if(!empty($num)){
  1630. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1631. }
  1632. //查询录入执行的调出单
  1633. $token = $this->settingtest->get_yytoken_120();
  1634. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1635. if(empty($res[0]['Data'])){
  1636. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1637. }
  1638. $time = time();
  1639. $final_list = [];
  1640. foreach($res[0]['Data'] as $k=>$v){
  1641. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1642. $tmp_sku = '';
  1643. $tmp_title = '';
  1644. $tmp_features = '';
  1645. $tmp_number='';
  1646. if(!empty($good_info)){
  1647. if(strpos($tmp_features, "-127-") !== false){
  1648. $tmp_features = $good_info['features'];
  1649. $tmp_features = str_replace('-195-','-', $tmp_features);
  1650. $tmp_features = str_replace('-197-', '-', $tmp_features);
  1651. $tmp_features = str_replace('-72-', '-', $tmp_features);
  1652. $good_info = $this->goods->find("features' = '".$tmp_features."' ");
  1653. if(empty($good_info)){
  1654. $tmp_features = "";
  1655. }else{
  1656. $tmp_sku = $good_info['sku'];
  1657. $tmp_title = $good_info['title'];
  1658. $tmp_features = $good_info['features'];
  1659. $tmp_number = str_replace("-","", $good_info['features']);
  1660. }
  1661. }else{
  1662. $tmp_sku = $good_info['sku'];
  1663. $tmp_title = $good_info['title'];
  1664. $tmp_features = $good_info['features'];
  1665. $tmp_number = str_replace("-","", $good_info['features']);
  1666. }
  1667. }
  1668. $final_list[] = [
  1669. 'sku'=>$tmp_sku,
  1670. 'dcd_no'=>$v['docno'],
  1671. 'jm'=>$v['iteminfo_itemcode'],
  1672. 'zh'=>$v['iteminfo_itemname'],
  1673. 'num'=>$v['costuomqty'],
  1674. 'real_num'=>$v['costuomqty'],
  1675. 'bh_no'=>$v['erp_no'],
  1676. 'create_time'=>$time,
  1677. 'title'=>$tmp_title,
  1678. 'features'=>$tmp_features,
  1679. 'number'=>$tmp_number,
  1680. ];
  1681. }
  1682. $r =$this->db->insert_batch('bhdcd',$final_list);
  1683. if($r){
  1684. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1685. }else{
  1686. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1687. }
  1688. exit;
  1689. }
  1690. }else{
  1691. $status_list = $this->bhdcd->getStatus();
  1692. $this->data['status_list'] = $status_list;
  1693. $this->_Template('beihuogl_ckdcd',$this->data);
  1694. }
  1695. }
  1696. private function _checkdcdsku($arg_array){
  1697. $dcd_no = $arg_array[0];
  1698. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' ");
  1699. $err_list = [];
  1700. foreach($list as $k=>$v){
  1701. if(empty($v['sku'])){
  1702. $goods_info = $this->goods->find("jm = '".$v['jm']."' ");
  1703. if(!empty($goods_info)){
  1704. $update_arr = [
  1705. 'sku'=>$goods_info['sku'],
  1706. 'title'=>$goods_info['title'],
  1707. 'number'=>trim(str_replace("-","",$goods_info['features'])),
  1708. 'features'=>$goods_info['features'],
  1709. ];
  1710. $this->bhdcd->save($update_arr,$v['id']);
  1711. }else{
  1712. $err_list[] = $v['jm'];
  1713. }
  1714. }
  1715. }
  1716. if(empty($err_list)){
  1717. echo json_encode(['success'=>true,'msg'=>'校验成功,可入库']);
  1718. }else{
  1719. echo json_encode(['success'=>false,'msg'=>'校验失败,请点击未录入料品导出']);
  1720. }
  1721. }
  1722. private function _ckbherprk($arg_array){
  1723. if($this->input->method() === 'post'){
  1724. $data = $this->input->post(null,true);
  1725. $dcd_no = $data['dcd_no'];
  1726. $drd_no = $data['drd_no'];
  1727. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1728. $spec_arr = $whlabel_arr = [];
  1729. $time = time();
  1730. $err_list= [];
  1731. foreach($list as $k=>$v){
  1732. if(empty($v['sku'])){
  1733. $err_list[] = $v['jm']."不存在";
  1734. continue;
  1735. }
  1736. //仓库不是特殊仓 且 设置了要校验库位
  1737. if(($v['erp_warehouse'] != 12) && empty($v['szkw'])){
  1738. $tmp_info = $this->whlabel->find("warehouse = '".$v['erp_warehouse']."' and sku = '".$v['sku']."' and details != 'DZ001' ","*","id desc");
  1739. if(!empty($tmp_info)){
  1740. if(!empty($tmp_info['details'])){
  1741. if($tmp_info['details'] != $v['kw']){
  1742. $err_list[] = $v['jm']."的库位信息";
  1743. continue;
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if($v['erp_warehouse'] == '12'){
  1749. //特殊仓处理方案
  1750. for($i=0;$i<$v['num'];$i++){
  1751. $spec_arr[] = [
  1752. 'purchase'=>1,
  1753. 'sku'=>$v['sku'],
  1754. 'number'=>$v['number'],
  1755. 'features'=>$v['features'],
  1756. 'featurespp'=>'',
  1757. 'label'=>'',
  1758. 'title'=>$v['title'],
  1759. // 'zh'=>$v['zh'],
  1760. 'warehouse'=>$v['erp_warehouse'],
  1761. 'enter'=>$time,
  1762. 'state'=>0,
  1763. 'retreatwarehouse'=>$v['erp_warehouse'],
  1764. 'time'=>$time,
  1765. 'details'=>$v['kw'],
  1766. 'bs'=>1,
  1767. 'rktype'=>9,
  1768. ];
  1769. }
  1770. }else{
  1771. for($i=0;$i<$v['num'];$i++){
  1772. $whlabel_arr[] = [
  1773. 'purchase'=>1,
  1774. 'sku'=>$v['sku'],
  1775. 'number'=>$v['number'],
  1776. 'features'=>$v['features'],
  1777. 'title'=>$v['title'],
  1778. 'zh'=>$v['zh'],
  1779. 'warehouse'=>$v['erp_warehouse'],
  1780. 'enter'=>$time,
  1781. 'state'=>0,
  1782. 'retreatwarehouse'=>$v['erp_warehouse'],
  1783. 'time'=>$time,
  1784. 'details'=>$v['kw'],
  1785. 'bs'=>1,
  1786. 'rktype'=>9,
  1787. ];
  1788. }
  1789. }
  1790. }
  1791. if(!empty($err_list)){
  1792. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1793. }
  1794. $this->db->trans_start();
  1795. if(!empty($whlabel_arr)){
  1796. $this->db->insert_batch('whlabel',$whlabel_arr);
  1797. }
  1798. if(!empty($spec_arr)){
  1799. $this->db->insert_batch('specialstock',$spec_arr);
  1800. }
  1801. $this->db->where('dcd_no',$dcd_no);
  1802. //$this->db->where('drd_no',$drd_no);
  1803. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1804. if($this->db->trans_status() === FALSE){
  1805. $this->db->trans_rollback();
  1806. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1807. }else{
  1808. $this->db->trans_commit();
  1809. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1810. }
  1811. }else{
  1812. $dcd_no = $arg_array[0];
  1813. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1814. $jm_list = array_column($list,'jm');
  1815. $status_list = $this->bhdcd->getStatus();
  1816. $in_where = "( ";
  1817. foreach($jm_list as $k=>$v){
  1818. $in_where .= "'".$v."',";
  1819. }
  1820. $in_where = rtrim($in_where,",");
  1821. $in_where .= " )";
  1822. $warehouse_list = [
  1823. 12=>'特殊仓',
  1824. 13=>'许昌仓',
  1825. 16=>'定制头套仓'
  1826. ];
  1827. foreach($list as $k=>$v){
  1828. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1829. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1830. $list[$k]['warehouse_show'] = isset($warehouse_list[$v['erp_warehouse']])?$warehouse_list[$v['erp_warehouse']]:"";
  1831. if(!empty($v['kw'])){
  1832. $list[$k]['kw'] = $v['kw'];
  1833. }else{
  1834. if(!empty($list[$k]['sku']) && $list[$k]['erp_warehouse'] != 12){
  1835. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1836. if(!empty($whlabel_info)){
  1837. if(!empty($whlabel_info['details'])){
  1838. $list[$k]['kw'] = $whlabel_info['details'];
  1839. $this->bhdcd->save([
  1840. 'kw'=>$whlabel_info['details'],
  1841. ],$v['id']);
  1842. }else{
  1843. $list[$k]['kw'] = "";
  1844. }
  1845. }else{
  1846. $list[$k]['kw'] = "";
  1847. }
  1848. }else{
  1849. $list[$k]['kw'] = "";
  1850. }
  1851. }
  1852. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1853. }
  1854. $this->data['list'] = $list;
  1855. $this->_Template('beihuogl_ckbherprk',$this->data);
  1856. }
  1857. }
  1858. private function _bhdcdsave(){
  1859. if($this->input->method() === 'post'){
  1860. $id = $this->input->post('id',true);
  1861. $val = $this->input->post('val',true);
  1862. $column = $this->input->post('column',true);
  1863. $info = $this->bhdcd->read($id);
  1864. $update_arr = [];
  1865. if($column == 'real_num'){
  1866. if($val > $info['num']){
  1867. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1868. }
  1869. $update_arr = [
  1870. 'real_num'=>(int)$val,
  1871. ];
  1872. }elseif($column == 'kw'){
  1873. if($info['erp_warehouse'] == '12'){
  1874. if(empty($val)){
  1875. $this->db->where('id', $id);
  1876. $ok = $this->db->update('bhdcd', ['kw' => '']);
  1877. if ($ok && empty($this->db->error()['code'])) {
  1878. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1879. } else {
  1880. echo json_encode(['success'=>false,'msg'=>'保存失败','err'=>$this->db->error()]);
  1881. }
  1882. exit;
  1883. }else{
  1884. echo json_encode(['success'=>false,'msg'=>'特殊仓不设置库位']);exit;
  1885. }
  1886. }else{
  1887. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1888. if(!empty($winfo)){
  1889. $ycz_kw = $winfo['details'];
  1890. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1891. if(empty($winfo) && ($ycz_kw != 'DZ001') ){
  1892. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1893. }
  1894. }
  1895. $update_arr = [
  1896. 'kw'=>empty($val)?'':trim($val),
  1897. ];
  1898. }
  1899. }elseif($column == 'ck'){
  1900. $update_arr = [
  1901. 'erp_warehouse'=>trim($val),
  1902. ];
  1903. }else{
  1904. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1905. }
  1906. $r = $this->bhdcd->save($update_arr,$id);
  1907. if($r){
  1908. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1909. }else{
  1910. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1911. }
  1912. }else{
  1913. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1914. }
  1915. }
  1916. private function _u9scdexcel($arg_array){
  1917. $id = $arg_array[0];
  1918. $info = $this->bhccwl->read($id);
  1919. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1920. $shop_list = $this->shop->find_all("id > 0");
  1921. $shop_list = array_column($shop_list,'shopname','id');
  1922. foreach($list as $k=>$v){
  1923. $list[$k]['shop_show'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:'';
  1924. }
  1925. //生成excel
  1926. $filename = $info['bh_no']."备货生产单.xls";
  1927. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1928. <head>
  1929. <!--[if gte mso 9]><xml>
  1930. <x:ExcelWorkbook>
  1931. <x:ExcelWorksheets>
  1932. <x:ExcelWorksheet>
  1933. <x:Name>EXCEL</x:Name>
  1934. <x:WorksheetOptions>
  1935. <x:Print>
  1936. <x:ValidPrinterInfo />
  1937. </x:Print>
  1938. </x:WorksheetOptions>
  1939. </x:ExcelWorksheet>
  1940. </x:ExcelWorksheets>
  1941. </x:ExcelWorkbook>
  1942. </xml>
  1943. <![endif]-->
  1944. </head><body>";
  1945. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1946. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td><td>申请人</td><td>店铺</td><td>备注</td></tr>";
  1947. foreach ($list as $key=>$value)
  1948. {
  1949. $str .= "<tr>";
  1950. $str .= "<td>". $value['bh_no']. "</td>";
  1951. $str .= "<td>". $value['title']. "</td>";
  1952. $str .= "<td>". $value['jm']. "</td>";
  1953. $str .= "<td>". $value['ck_num']. "</td>";
  1954. $str .= "<td>". $value['u9sc_no']. "</td>";
  1955. $str .= "<td>". $value['sqr']. "</td>";
  1956. $str .= "<td>". $value['shop_show']. "</td>";
  1957. $str .= "<td>". $value['remark']. "</td>";
  1958. $str .= "</tr>";
  1959. }
  1960. $str .= "</table></body></html>";
  1961. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1962. header( "Content-type: application/octet-stream" );
  1963. header( "Content-Disposition: attachment; filename=".$filename );
  1964. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1965. header( "Pragma: no-cache" );
  1966. header( "Expires: 0" );
  1967. exit($str);
  1968. }
  1969. //打印标签
  1970. private function _printlabel(){
  1971. if($this->input->method() === 'post'){
  1972. $id = $this->input->post('id',true);
  1973. $xbqnum = $this->input->post('num',true);
  1974. $info = $this->bhdcd->read($id);
  1975. if(empty($info)){
  1976. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1977. }
  1978. $print_num = empty($info['printnum'])?0:(int)$info['printnum'];
  1979. $print_num = $print_num + 1;
  1980. $this->bhdcd->save([
  1981. 'printnum'=>$print_num*1
  1982. ],$id);
  1983. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1984. $featurespp = explode('-', trim($featurespp, '-'));
  1985. if (isset($featurespp[5])) {
  1986. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1987. } else {
  1988. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1989. }
  1990. $label = '';
  1991. $cpid = $this->whlabellabel->find_count();
  1992. $cpid = $cpid + 1;
  1993. $time = time();
  1994. $label = time().rand(10,99);
  1995. $label = substr($label,1);
  1996. $insert_arr = [
  1997. 'purchase'=>1,
  1998. 'shop'=>'',
  1999. 'sku'=>$info['sku'],
  2000. 'number'=>$info['number'],
  2001. 'features'=>$info['features'],
  2002. 'featurespp'=>$tmp_featurespp,
  2003. 'title'=>$info['title'],
  2004. 'label'=>$label,
  2005. 'warehouse'=>$info['erp_warehouse'],
  2006. 'time'=>$time,
  2007. 'details'=>empty($info['kw'])?'':$info['kw'],
  2008. 'cpid'=>$cpid,
  2009. 'jm'=>$info['jm'],
  2010. 'cpbz'=>''
  2011. ];
  2012. $warehouse_info = $this->warehouse->read($info['erp_warehouse']);
  2013. if(empty($warehouse_info)){
  2014. $warehouse_name = "仓库异常";
  2015. }else{
  2016. $warehouse_name = $warehouse_info['title'];
  2017. }
  2018. $this->db->trans_begin();
  2019. $this->whlabellabel->insert($insert_arr);
  2020. if ($this->db->trans_status() === TRUE) {
  2021. $this->db->trans_commit();
  2022. } else {
  2023. $this->db->trans_rollback();
  2024. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  2025. exit;
  2026. }
  2027. if(empty($info['kw'])){
  2028. $details = '<font style="font-size: 18px;">' . $cpid . '</font>' ;
  2029. }else{
  2030. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  2031. }
  2032. $details = ' <b style="font-size: 18px;">'.$warehouse_name."</b> ".$details;
  2033. $purchase = "龙盈工厂";
  2034. 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));
  2035. exit; //特殊仓目前不需要仓库选项
  2036. }else{
  2037. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2038. }
  2039. }
  2040. private function _dcdjzrk(){
  2041. if($this->input->method() === 'post'){
  2042. $id = $this->input->post('id',true);
  2043. $type = $this->input->post('type',true);
  2044. $is_rk = 0;
  2045. if($type == 1){
  2046. $is_rk = 1;
  2047. }else{
  2048. $is_rk = 0;
  2049. }
  2050. $info = $this->bhdcd->read($id);
  2051. if($info['is_rk'] != $is_rk){
  2052. $this->bhdcd->save(['is_rk'=>$is_rk],$id);
  2053. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  2054. }else{
  2055. if($type ==1){
  2056. echo json_encode(['success'=>false,'msg'=>'此条信息已禁止入库']);exit;
  2057. }else{
  2058. echo json_encode(['success'=>false,'msg'=>'此条信息已允许入库']);exit;
  2059. }
  2060. }
  2061. }else{
  2062. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2063. }
  2064. }
  2065. private function _dyapplyyjsh(){
  2066. if($this->input->method() === 'post'){
  2067. $arr_id = $this->input->post('arr_id',true);
  2068. $this->db->where_in('id',$arr_id);
  2069. $this->db->where('sq_status',1);
  2070. $this->db->update('bhsq',['sq_status'=>2]);
  2071. echo json_encode(['success'=>true,'msg'=>'审核通过']);exit;
  2072. }else{
  2073. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2074. }
  2075. }
  2076. private function _dcdkwyz(){
  2077. if($this->input->method() === 'post'){
  2078. $id = $this->input->post('id',true);
  2079. $type = $this->input->post('type',true);
  2080. $szkw = 0;
  2081. if($type == 1){
  2082. $szkw = 1;
  2083. }else{
  2084. $szkw = 0;
  2085. }
  2086. $info = $this->bhdcd->read($id);
  2087. if($info['szkw'] != $szkw){
  2088. $this->bhdcd->save(['szkw'=>$szkw],$id);
  2089. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  2090. }else{
  2091. if($type ==1){
  2092. echo json_encode(['success'=>false,'msg'=>'此条信息已禁止验证库位']);exit;
  2093. }else{
  2094. echo json_encode(['success'=>false,'msg'=>'此条信息已允许验证库位']);exit;
  2095. }
  2096. }
  2097. }else{
  2098. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2099. }
  2100. }
  2101. private function _ckexcel($arg_array){
  2102. $id = $arg_array[0];
  2103. $info = $this->bhccwl->read($id);
  2104. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  2105. //生成excel
  2106. $filename = $info['bh_no']."备货生产单.xls";
  2107. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  2108. <head>
  2109. <!--[if gte mso 9]><xml>
  2110. <x:ExcelWorkbook>
  2111. <x:ExcelWorksheets>
  2112. <x:ExcelWorksheet>
  2113. <x:Name>EXCEL</x:Name>
  2114. <x:WorksheetOptions>
  2115. <x:Print>
  2116. <x:ValidPrinterInfo />
  2117. </x:Print>
  2118. </x:WorksheetOptions>
  2119. </x:ExcelWorksheet>
  2120. </x:ExcelWorksheets>
  2121. </x:ExcelWorkbook>
  2122. </xml>
  2123. <![endif]-->
  2124. </head><body>";
  2125. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  2126. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td></tr>";
  2127. foreach ($list as $key=>$value)
  2128. {
  2129. $str .= "<tr>";
  2130. $str .= "<td>". $value['bh_no']. "</td>";
  2131. $str .= "<td>". $value['title']. "</td>";
  2132. $str .= "<td>". $value['jm']. "</td>";
  2133. $str .= "<td>". $value['ck_num']. "</td>";
  2134. $str .= "</tr>";
  2135. }
  2136. $str .= "</table></body></html>";
  2137. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  2138. header( "Content-type: application/octet-stream" );
  2139. header( "Content-Disposition: attachment; filename=".$filename );
  2140. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  2141. header( "Pragma: no-cache" );
  2142. header( "Expires: 0" );
  2143. exit($str);
  2144. }
  2145. private function _bhcxsave(){
  2146. if($this->input->method() === 'post'){
  2147. $id = $this->input->post('id',true);
  2148. $cxr = $this->input->post('cxr',true);
  2149. $remark = $this->input->post('remark',true);
  2150. $num = $this->input->post('num',true);
  2151. $info = $this->bhsq->read($id);
  2152. if(empty($info)){
  2153. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  2154. }
  2155. if($info['sq_num'] < $num){
  2156. echo json_encode(['success'=>false,'msg'=>'变动后申请数不能大于申请数量']);exit;
  2157. }
  2158. if($info['sq_num'] == $num){
  2159. echo json_encode(['success'=>false,'msg'=>'变动后申请数等于申请数量???']);exit;
  2160. }
  2161. $this->db->trans_begin();
  2162. $this->db->insert('bhsccx',[
  2163. 'bh_no'=>$info['bh_no'],
  2164. 'u9sc_no'=>$info['u9sc_no'],
  2165. 'status'=>1,
  2166. 'cxr'=>trim($cxr),
  2167. 'zh'=>$info['title'],
  2168. 'jm'=>$info['jm'],
  2169. 'shop_id'=>$info['shop_id'],
  2170. 'sq_id'=>$info['id'],
  2171. 'before_num'=>$info['sq_num'],
  2172. 'after_num'=>$num,
  2173. 'remark'=>$remark,
  2174. 'add_time'=>time(),
  2175. 'update_time'=>time()
  2176. ]);
  2177. $this->bhsq->save(['is_cx'=>1],$id);
  2178. if ($this->db->trans_status() === TRUE) {
  2179. $this->db->trans_commit();
  2180. } else {
  2181. $this->db->trans_rollback();
  2182. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  2183. exit;
  2184. }
  2185. echo json_encode(['success'=>true,'msg'=>'保存成功']);exit;
  2186. }else{
  2187. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2188. }
  2189. }
  2190. private function _bhcxlist(){
  2191. if($this->input->method() === 'post'){
  2192. $page = $this->input->post('page',true);
  2193. $perpage = $this->input->post('perpage',true);
  2194. $vip_id = $this->input->post('vip_id',true);
  2195. $shop_id = $this->input->post('shop_id',true);
  2196. $cxr = $this->input->post('cxr',true);
  2197. $cxr = trim($cxr);
  2198. $status = $this->input->post('status',true);
  2199. $shop_ids = $this->input->post('shop_ids',true);
  2200. $ktime = $this->input->post('ktime',true);
  2201. $jtime = $this->input->post('jtime',true);
  2202. $ktime = strtotime($ktime);
  2203. $jtime = strtotime($jtime);
  2204. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  2205. if(!empty($cxr)){
  2206. $where .= " and cxr = '".$cxr."' ";
  2207. }
  2208. if($shop_id > -1){
  2209. $where .= " and shop_id = ".$shop_id." ";
  2210. }else{
  2211. if($vip_id == 1){
  2212. }else{
  2213. $where .= " and shop_id in (".$shop_ids.") ";
  2214. }
  2215. }
  2216. if($status > -1){
  2217. $where .= " and status = ".$status." ";
  2218. }
  2219. //数据排序
  2220. $order_str = "id desc";
  2221. if(empty($page))
  2222. {
  2223. $start = 0;
  2224. $perpage = 1;
  2225. }
  2226. else
  2227. {
  2228. $start = ($page - 1)*$perpage;
  2229. }
  2230. $list = $this->bhsccx->find_all($where,"id,shop_id,bh_no,u9sc_no,zh,status,cxr,after_num,before_num,add_time",$order_str,$start,$perpage);
  2231. if(empty($list)){
  2232. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  2233. echo json_encode($rows);exit;
  2234. }
  2235. $shop_list = $this->shop->find_all("1=1","id,shopname");
  2236. $shop_list = array_column($shop_list,'shopname','id');
  2237. $status_list = $this->bhsccx->getCxStatus();
  2238. foreach($list as $k=>$v){
  2239. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  2240. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  2241. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  2242. if($v['status'] == 0){
  2243. $list[$k]['after_num'] = $v['after_num'];
  2244. $list[$k]['cxr'] = $v['cxr'];
  2245. $list[$k]['u9sc_no'] = "<a href='javascript:void(0)'class='window' data-h='/beihuogl/bhcxedit/".$v['id']."' data-t='修改' >".$v['u9sc_no']."</a>";
  2246. }
  2247. $str = "<div style='text-align:center;'>";
  2248. if($v['status'] == 1){
  2249. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-status='0' onclick='cxaction(this)'>撤回</a>";
  2250. }
  2251. if($v['status'] == 0){
  2252. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-status='1' onclick='cxaction(this)'>发布</a>";
  2253. }
  2254. // if(!empty($v['u9sc_no'])){
  2255. // $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-title='".$v['title']."' data-id='".$v['id']."' data-u9sc_no='".$v['u9sc_no']."' data-bh_no='".$v['bh_no']."' onclick='cx_bhsq(this)'>生产撤销</a>";
  2256. // }
  2257. $str .= "</div>";
  2258. $list[$k]['update_time'] = $str;
  2259. unset($list[$k]['before_num']);
  2260. }
  2261. $total = $this->bhsccx->find_count($where);
  2262. $pagenum = ceil($total/$perpage);
  2263. $over = $total-($start+$perpage);
  2264. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  2265. echo json_encode($rows);exit;
  2266. }else{
  2267. $user = $this->user->get_api($_SESSION['api']);
  2268. $usersp = explode('|',trim($user['shop'],'|'));
  2269. $this->data['usersp'] = implode(",",$usersp);
  2270. $vip_id = 0;
  2271. if(in_array($user['id'],[10,28])){
  2272. $vip_id = 1;
  2273. }
  2274. $this->data['vip_id'] = $vip_id;
  2275. $this->data['status_list'] = $this->bhsccx->getCxStatus();
  2276. $this->_Template('beihuogl_bhcxlist',$this->data);
  2277. }
  2278. }
  2279. private function _bhcxedit($arg_array){
  2280. if($this->input->method() === 'post'){
  2281. $id = $this->input->post('id',true);
  2282. $cxr = $this->input->post('cxr',true);
  2283. $remark = $this->input->post('remark',true);
  2284. $after_num = $this->input->post('after_num',true);
  2285. $info = $this->bhsccx->read($id);
  2286. if(empty($info)){
  2287. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  2288. }
  2289. if($after_num > $info['before_num']){
  2290. echo json_encode(['success'=>false,'msg'=>'要生产数量不能大于之前的申报数量']);exit;
  2291. }
  2292. $this->bhsccx->save(['cxr' => $cxr, 'remark' => $remark, 'after_num' => $after_num], $id);
  2293. echo json_encode(['success'=>true,'msg'=>'操作成功']);exit;
  2294. }else{
  2295. $id = $arg_array[0];
  2296. $info = $this->bhsccx->read($id);
  2297. $this->data['info'] = $info;
  2298. $this->_Template('beihuogl_bhcxedit',$this->data);
  2299. }
  2300. }
  2301. private function _updatestatus(){
  2302. if($this->input->method() === 'post'){
  2303. $id = $this->input->post('id',true);
  2304. $status = $this->input->post('status',true);
  2305. $info = $this->bhsccx->read($id);
  2306. $status = (int)$status;
  2307. if(empty($info)){
  2308. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  2309. }
  2310. $update_data = [
  2311. 'status' => $status,
  2312. ];
  2313. $update_data['update_time'] = time();
  2314. if($status == 0 || $status == 2){
  2315. if($info['status'] != 1){
  2316. echo json_encode(['success'=>false,'msg'=>'当前状态不符合修改状态']);exit;
  2317. }
  2318. if($status == 2){
  2319. $update_data['hd_time'] = time();
  2320. }
  2321. }
  2322. if($status == 1){
  2323. if($info['status'] != 0){
  2324. echo json_encode(['success'=>false,'msg'=>'当前状态不符合修改状态']);exit;
  2325. }
  2326. }
  2327. if($this->bhsccx->save($update_data,$id)){
  2328. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  2329. }else{
  2330. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  2331. exit;
  2332. }
  2333. }else{
  2334. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2335. }
  2336. }
  2337. private function _bhcxshlist(){
  2338. if($this->input->method() === 'post'){
  2339. $page = $this->input->post('page',true);
  2340. $perpage = $this->input->post('perpage',true);
  2341. $cxr = $this->input->post('cxr',true);
  2342. $cxr = trim($cxr);
  2343. $status = $this->input->post('status',true);
  2344. $ktime = $this->input->post('ktime',true);
  2345. $jtime = $this->input->post('jtime',true);
  2346. $ktime = strtotime($ktime);
  2347. $jtime = strtotime($jtime);
  2348. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  2349. $where .= " and status > 0 ";
  2350. if(!empty($cxr)){
  2351. $where .= " and cxr = '".$cxr."' ";
  2352. }
  2353. if(!empty($status)){
  2354. $where .= " and status = ".$status." ";
  2355. }else{
  2356. $where .= " and status > 0 ";
  2357. }
  2358. //数据排序
  2359. $order_str = "id desc";
  2360. if(empty($page))
  2361. {
  2362. $start = 0;
  2363. $perpage = 1;
  2364. }
  2365. else
  2366. {
  2367. $start = ($page - 1)*$perpage;
  2368. }
  2369. $list = $this->bhsccx->find_all($where,"id,shop_id,bh_no,u9sc_no,jm,remark,status,cxr,after_num,before_num,add_time",$order_str,$start,$perpage);
  2370. if(empty($list)){
  2371. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  2372. echo json_encode($rows);exit;
  2373. }
  2374. $shop_list = $this->shop->find_all("1=1","id,shopname");
  2375. $shop_list = array_column($shop_list,'shopname','id');
  2376. $status_list = $this->bhsccx->getCxStatus();
  2377. foreach($list as $k=>$v){
  2378. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  2379. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  2380. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  2381. $change_num = $v['before_num'] - $v['after_num'];
  2382. if($v['status'] == 0){
  2383. $list[$k]['after_num'] = $v['after_num'];
  2384. $list[$k]['cxr'] = $v['cxr'];
  2385. $list[$k]['u9sc_no'] = "<a href='javascript:void(0)'class='window' data-h='/beihuogl/bhcxedit/".$v['id']."' data-t='修改' >".$v['u9sc_no']."</a>";
  2386. }
  2387. $str = "<div style='text-align:center;'>";
  2388. if($v['status'] == 1){
  2389. $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' data-status='2' onclick='cxaction(this)'>审核</a>";
  2390. }
  2391. // if(!empty($v['u9sc_no'])){
  2392. // $str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #9400D3;padding:4px 10px;border-radius:5px;font-size:15px' data-title='".$v['title']."' data-id='".$v['id']."' data-u9sc_no='".$v['u9sc_no']."' data-bh_no='".$v['bh_no']."' onclick='cx_bhsq(this)'>生产撤销</a>";
  2393. // }
  2394. $str .= "</div>";
  2395. $list[$k]['update_time'] = $str;
  2396. $list[$k]['before_num'] = $change_num;
  2397. //unset($list[$k]['before_num']);
  2398. }
  2399. $total = $this->bhsccx->find_count($where);
  2400. $pagenum = ceil($total/$perpage);
  2401. $over = $total-($start+$perpage);
  2402. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  2403. echo json_encode($rows);exit;
  2404. }else{
  2405. $this->data['status_list'] = $this->bhsccx->getCxStatus();
  2406. $this->_Template('beihuogl_bhcxshlist',$this->data);
  2407. }
  2408. }
  2409. private function _bhcxlistexcel(){
  2410. if($this->input->method() === 'post'){
  2411. exit("状态不正确");
  2412. }else{
  2413. $ktime = $this->input->get('ktime',true);
  2414. $jtime = $this->input->get('jtime',true);
  2415. $ktime = strtotime($ktime);
  2416. $jtime = strtotime($jtime);
  2417. $status = $this->input->get('status',true);
  2418. $cxr = $this->input->get('cxr',true);
  2419. $cxr = trim($cxr);
  2420. $shop_id = $this->input->get('shop_id',true);
  2421. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  2422. if(!empty($cxr)){
  2423. $where .= " and cxr like '%".$cxr."%' ";
  2424. }
  2425. if($status >= 0 ){
  2426. $where .= " and status = ".$status." ";
  2427. }
  2428. if($shop_id >= 0){
  2429. $where .= " and shop_id = ".$shop_id." ";
  2430. }
  2431. $list = $this->bhsccx->find_all($where);
  2432. if(!empty($list)){
  2433. $shop_list= $this->shop->find_all("1=1","id,shopname");
  2434. $shop_list = array_column($shop_list,'shopname','id');
  2435. foreach($list as $k=>$v){
  2436. $list[$k]['add_time'] = date("Y-m-d H:i",$v['add_time']);
  2437. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  2438. $list[$k]['hd_time'] = empty($v['hd_time'])?'':date("Y-m-d H:i",$v['hd_time']);
  2439. }
  2440. }
  2441. //生成excel
  2442. $filename = date("Ymd")."-撤销备货申请单.xls";
  2443. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  2444. <head>
  2445. <!--[if gte mso 9]><xml>
  2446. <x:ExcelWorkbook>
  2447. <x:ExcelWorksheets>
  2448. <x:ExcelWorksheet>
  2449. <x:Name>EXCEL</x:Name>
  2450. <x:WorksheetOptions>
  2451. <x:Print>
  2452. <x:ValidPrinterInfo />
  2453. </x:Print>
  2454. </x:WorksheetOptions>
  2455. </x:ExcelWorksheet>
  2456. </x:ExcelWorksheets>
  2457. </x:ExcelWorkbook>
  2458. </xml>
  2459. <![endif]-->
  2460. </head><body>";
  2461. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  2462. $str .= "<tr><td>店铺</td><td>备货单号</td><td>u9生产单号</td><td>中文品名</td><td>u9料号</td><td>撤后生产数量</td><td>撤销人</td><td>申请撤销时间</td><td>备注</td><td>审核时间</td></tr>";
  2463. foreach ($list as $key=>$value)
  2464. {
  2465. $str .= "<tr>";
  2466. $str .= "<td>". $value['shop_id']. "</td>";
  2467. $str .= "<td>". $value['bh_no']. "</td>";
  2468. $str .= "<td>". $value['u9sc_no']. "</td>";
  2469. $str .= "<td>". $value['zh']. "</td>";
  2470. $str .= "<td>". $value['jm']. "</td>";
  2471. $str .= "<td>". $value['after_num']. "</td>";
  2472. $str .= "<td>". $value['cxr']. "</td>";
  2473. $str .= "<td>". $value['add_time']. "</td>";
  2474. $str .= "<td>". $value['remark']. "</td>";
  2475. $str .= "<td>". $value['hd_time']. "</td>";
  2476. $str .= "</tr>";
  2477. }
  2478. $str .= "</table></body></html>";
  2479. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  2480. header( "Content-type: application/octet-stream" );
  2481. header( "Content-Disposition: attachment; filename=".$filename );
  2482. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  2483. header( "Pragma: no-cache" );
  2484. header( "Expires: 0" );
  2485. exit($str);
  2486. }
  2487. }
  2488. //未录入料品导出
  2489. private function _wlrlpdc(){
  2490. if($this->input->method() === 'post'){
  2491. $dcd_no = $this->input->post('dcd_no');
  2492. $where = "dcd_no = '".$dcd_no."' and (title = '' or title is Null)";
  2493. $this->db->where($where);
  2494. $query = $this->db->get('bhdcd');
  2495. $list = $query->result_array();
  2496. if(empty($list)){
  2497. echo json_encode(['success'=>false,'msg'=>'未录入料品导出失败']);exit;
  2498. }
  2499. $final_list = [];
  2500. foreach($list as $v){
  2501. $final_list[] = [
  2502. '调出单'=>$v['dcd_no'],
  2503. '中文品名'=>$v['zh'],
  2504. '用友料号'=>$v['jm'],
  2505. '备货单号'=>$v['bh_no']
  2506. ];
  2507. }
  2508. echo json_encode(['success'=>true,'msg'=>"导入成功",'data'=>$final_list]);exit;
  2509. }else{
  2510. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2511. }
  2512. }
  2513. }