Beihuogl.php 115 KB

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