Beihuogl.php 124 KB

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