Beihuogl.php 79 KB

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