Beihuogl.php 124 KB

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