Beihuogl.php 111 KB

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