Beihuogl.php 112 KB

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