Beihuogl.php 115 KB

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