Beihuogl.php 94 KB

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