Beihuogl.php 125 KB

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