Beihuogl.php 111 KB

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