Beihuogl.php 107 KB

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