Beihuogl.php 125 KB

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