Beihuogl.php 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  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. $list[$k]['update_time'] = $str;
  961. unset($list[$k]['ck_status']);
  962. }
  963. $total = $this->bhccwl->find_count($where);
  964. $pagenum = ceil($total/$perpage);
  965. $over = $total-($start+$perpage);
  966. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  967. echo json_encode($rows);exit;
  968. }else{
  969. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  970. }
  971. }
  972. //仓储物流部备货 在编辑页面添加数据
  973. private function _ccwlbhsavexzbh(){
  974. if($this->input->method() === 'post'){
  975. $data = $this->input->post();
  976. $select_id = $data['select_id'];
  977. $id = $data['id'];
  978. $bh_no = $data['bh_no'];
  979. if(empty($select_id)){
  980. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  981. exit;
  982. }
  983. $info = $this->bhccwl->read($id);
  984. if(empty($info)){
  985. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  986. exit;
  987. }
  988. if($info['bh_no'] != $bh_no){
  989. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  990. exit;
  991. }
  992. $bh_no = $info['bh_no'];
  993. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  994. foreach($list as $k=>$v){
  995. if(empty($v['sku'])){
  996. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  997. exit;
  998. }
  999. if(!empty($v['bh_no'])){
  1000. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  1001. exit;
  1002. }
  1003. }
  1004. $classid = $this->logic_u9tools->getClass();
  1005. $typeclass = $this->logic_u9tools->getTypeClass();
  1006. foreach($list as $k=>$v){
  1007. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm,zh','id desc');
  1008. if(empty($whlabel_info)){
  1009. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  1010. if(empty($whlabel_info)){
  1011. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  1012. exit;
  1013. }
  1014. if(empty($v['jm'])){
  1015. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  1016. $this->bhsq->save([
  1017. 'jm'=>$r['jm'],
  1018. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  1019. 'features'=>$whlabel_info['features'],
  1020. 'erp_zh'=>$r['zh'],
  1021. ],$v['id']);
  1022. }
  1023. $list[$k]['jm'] = $r['jm'];
  1024. }else{
  1025. $this->bhsq->save([
  1026. 'jm'=>$whlabel_info['jm'],
  1027. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  1028. 'features'=>$whlabel_info['features'],
  1029. 'erp_zh'=>$whlabel_info['zh'],
  1030. ],$v['id']);
  1031. $list[$k]['jm'] = $whlabel_info['jm'];
  1032. }
  1033. }
  1034. $status_list = $this->bhccwl->getStatus();
  1035. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  1036. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1037. $plat_list = array_column($plat_list,'title','id');
  1038. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1039. $shop_list = array_column($shop_list,'shopname','id');
  1040. foreach($list as $k=>$v){
  1041. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1042. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1043. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1044. $list[$k]['bh_no'] = $info['bh_no'];
  1045. }
  1046. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  1047. }else{
  1048. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  1049. exit;
  1050. }
  1051. }
  1052. private function _ccwlbhedit($arg_array){
  1053. if($this->input->method() === 'post'){
  1054. $select_id = $this->input->post('arr_id',true);
  1055. if(empty($select_id)){
  1056. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  1057. exit;
  1058. }
  1059. $id = $this->input->post('id',true);
  1060. $info = $this->bhccwl->read($id);
  1061. $bh_no = $info['bh_no'];
  1062. $this->db->where_in('id',$select_id);
  1063. $this->db->update('bhsq',[
  1064. 'bh_no'=>$bh_no,
  1065. 'sq_status'=>4,
  1066. 'ccwl_status'=>1,
  1067. ]);
  1068. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  1069. $this->db->where_in('id',$select_id);
  1070. $query = $this->db->get('bhsq');
  1071. $result = $query->row();
  1072. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  1073. $time = time();
  1074. $this->bhccwl->save([
  1075. 'num'=>$total_ccwl_num,
  1076. 'update_time'=>$time,
  1077. ],$info['id']);
  1078. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1079. }else{
  1080. $id = $arg_array[0];
  1081. $info = $this->bhccwl->find("id = ".$id);
  1082. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  1083. $status_list = $this->bhccwl->getStatus();
  1084. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  1085. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1086. $plat_list = array_column($plat_list,'title','id');
  1087. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1088. $shop_list = array_column($shop_list,'shopname','id');
  1089. foreach($list as $k=>$v){
  1090. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1091. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1092. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1093. }
  1094. // $this->data['info'] = $info;
  1095. $this->data['list'] = $list;
  1096. $this->data['info'] = $info;
  1097. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  1098. }
  1099. }
  1100. private function _ccwldelitem(){
  1101. if($this->input->method() === 'post'){
  1102. $data = $this->input->post();
  1103. $id = $data['id'];
  1104. $bh_no = $data['bh_no'];
  1105. $info = $this->bhsq->read($id);
  1106. $ccwl_num = $info['ccwl_num'];
  1107. if(empty($info)){
  1108. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1109. }
  1110. if(empty($info['bh_no'])){
  1111. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  1112. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1113. }else{
  1114. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1115. }
  1116. }
  1117. if($info['bh_no'] != $bh_no){
  1118. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1119. }
  1120. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  1121. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  1122. $this->db->trans_start();
  1123. $this->bhccwl->save([
  1124. 'num'=>$ccwl_info['num'],
  1125. ],$ccwl_info['id']);
  1126. $this->bhsq->save([
  1127. 'sq_status'=>2,
  1128. 'ccwl_status'=>0,
  1129. 'bh_no'=>''
  1130. ],$id);
  1131. if($this->db->trans_status() === FALSE){
  1132. $this->db->trans_rollback();
  1133. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  1134. }else{
  1135. $this->db->trans_commit();
  1136. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1137. }
  1138. }else{
  1139. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1140. }
  1141. }
  1142. private function _ccwleditxzbh(){
  1143. if($this->input->method() === 'post'){
  1144. $data = $this->input->post();
  1145. //超过三月没审核的 就不展示了
  1146. $time = time() - 60*24*3600;
  1147. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  1148. if(!empty($data['sqr'])){
  1149. $where .= " and sqr = '".$data['sqr']."' ";
  1150. }
  1151. if(!empty($data['shop_id'])){
  1152. $where .= " and shop_id = ".$data['shop_id']." ";
  1153. }
  1154. if(!empty($data['plat_id'])){
  1155. $where .= " and plat_id = ".$data['plat_id']." ";
  1156. }
  1157. if(!empty($data['sku'])){
  1158. $where .= " and sku = '".$data['sku']."' ";
  1159. }
  1160. $order_str = "id desc";
  1161. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  1162. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1163. $shop_list = array_column($shop_list,'shopname','id');
  1164. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1165. $plat_list = array_column($plat_list,'title','id');
  1166. foreach($list as $k=>$v){
  1167. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1168. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1169. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1170. }
  1171. if(empty($list)){
  1172. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  1173. }else{
  1174. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  1175. }
  1176. }else{
  1177. $data = $this->input->get();
  1178. $this->data['id'] = $data['id'];
  1179. $this->data['bh_no'] = $data['bh_no'];
  1180. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1181. $this->data['plat_list'] = $plat_list;
  1182. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  1183. }
  1184. }
  1185. private function _ccwlbhsave(){
  1186. if($this->input->method() === 'post'){
  1187. $data = $this->input->post();
  1188. $id = $data['id'];
  1189. $val = $data['val'];
  1190. $column = $data['column'];
  1191. $update_arr = [];
  1192. if($column == 'status'){
  1193. $update_arr = [
  1194. 'status'=>(int)$val,
  1195. 'update_time'=>time(),
  1196. 'public_time'=>time(),
  1197. ];
  1198. if($val == 2){
  1199. $info = $this->bhccwl->read($id);
  1200. if($info['status'] == 1 && $info['ck_status'] == 0){
  1201. }else{
  1202. echo json_encode(['success'=>false,'msg'=>'状态不对,不可撤回']);exit;
  1203. }
  1204. }
  1205. }else{
  1206. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1207. }
  1208. $r = $this->bhccwl->save($update_arr,$id);
  1209. if($r){
  1210. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1211. }else{
  1212. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  1213. }
  1214. }else{
  1215. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1216. }
  1217. }
  1218. //仓库的备货单列表
  1219. private function _ckbhindex(){
  1220. if($this->input->method() === 'post'){
  1221. $page = $this->input->post('page',true);
  1222. $perpage = $this->input->post('perpage',true);
  1223. $bh_no = $this->input->post('bh_no',true);
  1224. $status = $this->input->post('status',true);
  1225. $ktime = $this->input->post('ktime',true);
  1226. $jtime = $this->input->post('jtime',true);
  1227. $ktime = strtotime($ktime);
  1228. $jtime = strtotime($jtime);
  1229. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1230. if(!empty($bh_no)){
  1231. $where .= " and bh_no = '".$bh_no."' ";
  1232. }
  1233. if($status > -1){
  1234. $where .= " and status = ".$status." ";
  1235. }
  1236. //数据排序
  1237. $order_str = "id desc";
  1238. if(empty($page))
  1239. {
  1240. $start = 0;
  1241. $perpage = 1;
  1242. }
  1243. else
  1244. {
  1245. $start = ($page - 1)*$perpage;
  1246. }
  1247. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1248. if(empty($list)){
  1249. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1250. echo json_encode($rows);exit;
  1251. }
  1252. $status_list = $this->bhccwl->getCkStatus();
  1253. foreach($list as $k=>$v){
  1254. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1255. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1256. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1257. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1258. $str = "";
  1259. if($v['ck_status'] == 0){
  1260. $str .= "<div style='text-align:center;'>";
  1261. $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>";
  1262. $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>";
  1263. $str .= "</div>";
  1264. }
  1265. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1266. $str .= "<div style='text-align:center;'>";
  1267. $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>";
  1268. $str .= "</div>";
  1269. }
  1270. if($v['ck_status'] > 2){
  1271. $str .= "<div style='text-align:center;'>";
  1272. $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>";
  1273. $str .= "</div>";
  1274. }
  1275. $list[$k]['update_time'] = $str;
  1276. }
  1277. $total = $this->bhccwl->find_count($where);
  1278. $pagenum = ceil($total/$perpage);
  1279. $over = $total-($start+$perpage);
  1280. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1281. echo json_encode($rows);exit;
  1282. }else{
  1283. $this->_Template('beihuogl_ckbhindex',$this->data);
  1284. }
  1285. }
  1286. private function _ckbhedit($arg_array){
  1287. if($this->input->method() === 'post'){
  1288. $id = $this->input->post('id',true);
  1289. $bh_no = $this->input->post('bh_no',true);
  1290. $info = $this->bhccwl->read($id);
  1291. if(empty($info)){
  1292. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1293. }
  1294. if($info['ck_status'] == 0 && $info['status'] == 1){
  1295. }else{
  1296. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1297. }
  1298. if($info['bh_no'] != $bh_no){
  1299. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1300. }
  1301. $num = 0;
  1302. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1303. foreach($list as $k=>$v){
  1304. $num += $v['ck_num'];
  1305. }
  1306. $r = $this->bhccwl->save([
  1307. 'ck_status'=>1,
  1308. 'ck_num'=>$num,
  1309. 'update_time'=>time(),
  1310. 'ckpublic_time'=>time(),
  1311. ],$id);
  1312. if($r){
  1313. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1314. }else{
  1315. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1316. }
  1317. }else{
  1318. $id = $arg_array[0];
  1319. $info = $this->bhccwl->find("id = ".$id);
  1320. $status_list = $this->bhccwl->getCkStatus();
  1321. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1322. $drck_list = $this->bhccwl->getDrck();
  1323. $this->data['drck_list'] = $drck_list;
  1324. $this->data['drck_json'] = json_encode($drck_list);
  1325. $this->data['info'] = $info;
  1326. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1327. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1328. $shop_list = array_column($shop_list,'shopname','id');
  1329. foreach($list as $k=>$v){
  1330. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1331. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1332. }
  1333. $this->data['list'] = $list;
  1334. $this->_Template('beihuogl_ckbhedit',$this->data);
  1335. }
  1336. }
  1337. private function _makeu9scd($arg_array){
  1338. if($this->input->method() === 'post'){
  1339. $data = $this->input->post(null,true);
  1340. $info = $this->bhccwl->read($data['id']);
  1341. if(empty($info)){
  1342. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1343. }
  1344. if($info['ck_status'] == 1 && $info['status'] == 1){
  1345. }else{
  1346. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1347. exit;
  1348. }
  1349. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1350. $params = [
  1351. 'org_code'=>"120",//组织代码 龙盈工厂
  1352. 'djhlx'=>'2000',//单号类型 备货生产单
  1353. 'scbm_code'=>"12008",//龙盈生产部门
  1354. "time"=>time(),
  1355. 'owner_org_code'=>"120",
  1356. 'title'=>$info['bh_no'],
  1357. 'shipremarks'=>$info['bh_no'],
  1358. ];
  1359. $final_list = [];
  1360. foreach($list as $k=>$v){
  1361. $final_list[] =[
  1362. 'do_id'=>$v['id'],
  1363. 'drck'=>$v['drck'],
  1364. 'jm'=>$v['jm'],
  1365. 'sl'=>$v['ck_num'],
  1366. ];
  1367. }
  1368. $params['list'] = $final_list;
  1369. $token = $this->settingtest->get_yytoken_120();
  1370. $res = $this->apiyyv1->scdCreate($params,$token);
  1371. if(empty($res[0]['Data'])){
  1372. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1373. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1374. }
  1375. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1376. $r_s_list = $res[0]['Data'];
  1377. foreach($list as $k=>$v){
  1378. $list[$k]['u9_data'] = $r_s_list[$k];
  1379. }
  1380. //m_isSucess
  1381. $flag_status = 0;//判断是否有创建失败的
  1382. $u9sc_status = 0;//判断是否有创建成功的
  1383. foreach($list as $k=>$v){
  1384. if($v['u9_data']['m_isSucess']== 1){
  1385. $u9sc_status += 1;
  1386. $this->bhsq->save([
  1387. 'is_u9sc'=>1,
  1388. 'u9sc_no'=>$v['u9_data']['m_code'],
  1389. ],$v['id']);
  1390. }else{
  1391. if($v['ck_num'] > 0){
  1392. $flag_status += 0;
  1393. $this->bhsq->save([
  1394. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1395. ],$v['id']);
  1396. }else{
  1397. $u9sc_status += 1;
  1398. }
  1399. }
  1400. }
  1401. $len = count($list);
  1402. //都创建失败了 就直接gg
  1403. if($u9sc_status == 0){
  1404. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1405. }
  1406. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1407. $this->bhccwl->save([
  1408. 'ck_status'=>2,
  1409. ],$info['id']);
  1410. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1411. }
  1412. if($u9sc_status == $len){
  1413. $this->bhccwl->save([
  1414. 'ck_status'=>3,
  1415. ],$info['id']);
  1416. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1417. }
  1418. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1419. }else{
  1420. $id = $arg_array[0];
  1421. $info = $this->bhccwl->read($id);
  1422. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1423. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1424. $shop_list = array_column($shop_list,'shopname','id');
  1425. $drck_list = $this->bhccwl->getDrck();
  1426. $status_list = $this->bhccwl->getCkStatus();
  1427. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1428. foreach($list as $k=>$v){
  1429. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1430. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1431. }
  1432. $this->data['list'] = $list;
  1433. $this->data['info'] = $info;
  1434. $this->_Template('beihuogl_makeu9scd',$this->data);
  1435. }
  1436. }
  1437. private function _ddscscd(){
  1438. if($this->input->method() === 'post'){
  1439. $id = $this->input->post('id',true);
  1440. $bh_no = $this->input->post('bh_no',true);
  1441. $bhsq_info = $this->bhsq->read($id);
  1442. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1443. if(empty($bhccwl_info)){
  1444. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1445. }
  1446. // if($bhccwl_info['ck_status'] != 1){
  1447. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1448. // exit;
  1449. // }
  1450. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1451. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1452. exit;
  1453. }
  1454. if(!empty($bhsq_info['u9sc_no'])){
  1455. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1456. exit;
  1457. }
  1458. $params = [
  1459. 'org_code'=>"120",//组织代码 龙盈工厂
  1460. 'djhlx'=>'2000',//单号类型 备货生产单
  1461. 'scbm_code'=>"12008",//龙盈生产部门
  1462. "time"=>time(),
  1463. 'owner_org_code'=>"120",
  1464. 'title'=>$bhccwl_info['bh_no'],
  1465. 'shipremarks'=>$bhccwl_info['bh_no'],
  1466. ];
  1467. $list[] = [
  1468. 'do_id'=>$bhsq_info['id'],
  1469. 'drck'=>$bhsq_info['drck'],
  1470. 'jm'=>$bhsq_info['jm'],
  1471. 'sl'=>$bhsq_info['ck_num'],
  1472. ];
  1473. $params['list'] = $list;
  1474. $token = $this->settingtest->get_yytoken_120();
  1475. $res = $this->apiyyv1->scdCreate($params,$token);
  1476. if(empty($res[0]['Data'])){
  1477. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1478. }
  1479. if($res[0]['Data'][0]['m_isSucess']== 1){
  1480. $this->bhsq->save([
  1481. 'is_u9sc'=>1,
  1482. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1483. ],$bhsq_info['id']);
  1484. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1485. if(empty($tmp_list)){
  1486. $tmp_status = 3;
  1487. }else{
  1488. $tmp_status = 2;
  1489. }
  1490. $this->bhccwl->save([
  1491. 'ck_status'=>$tmp_status,
  1492. ],$bhccwl_info['id']);
  1493. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1494. }else{
  1495. $this->bhsq->save([
  1496. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1497. ],$bhsq_info['id']);
  1498. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1499. }
  1500. }else{
  1501. exit('No direct script access allowed');
  1502. }
  1503. }
  1504. private function _showckbh($arg_array){
  1505. if($this->input->method() === 'post'){
  1506. exit('No direct script access allowed');
  1507. }
  1508. $id = $arg_array[0];
  1509. $drck_list = $this->bhccwl->getDrck();
  1510. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1511. $shop_list = array_column($shop_list,'shopname','id');
  1512. $info = $this->bhccwl->read($id);
  1513. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1514. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1515. foreach($list as $k=>$v){
  1516. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1517. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1518. }
  1519. $this->data['info'] = $info;
  1520. $this->data['list'] = $list;
  1521. $this->data['list_dcd'] = $list_dcd;
  1522. $this->_Template('beihuogl_showckbh',$this->data);
  1523. }
  1524. //仓库录入调出单
  1525. private function _ckdcd(){
  1526. if($this->input->method() === 'post'){
  1527. $lrdcd = $this->input->post('lrdcd',true);
  1528. if(empty($lrdcd)){
  1529. //列表展示
  1530. $page = $this->input->post('page',true);
  1531. $perpage = $this->input->post('perpage',true);
  1532. $bh_no = $this->input->post('bh_no',true);
  1533. $dcd_no = $this->input->post('dcd_no',true);
  1534. $status = $this->input->post('status',true);
  1535. $ktime = $this->input->post('ktime',true);
  1536. $jtime = $this->input->post('jtime',true);
  1537. $ktime = strtotime($ktime);
  1538. $jtime = strtotime($jtime);
  1539. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1540. if(!empty($bh_no)){
  1541. $where .= " and bh_no = '".$bh_no."' ";
  1542. }
  1543. if($status > -1){
  1544. $where .= " and status = ".$status." ";
  1545. }
  1546. if(!empty($dcd_no)){
  1547. $where .= " and dcd_no = '".$dcd_no."' ";
  1548. }
  1549. //数据排序
  1550. $order_str = "id desc";
  1551. if(empty($page))
  1552. {
  1553. $start = 0;
  1554. $perpage = 1;
  1555. }
  1556. else
  1557. {
  1558. $start = ($page - 1)*$perpage;
  1559. }
  1560. $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);
  1561. if(empty($list)){
  1562. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1563. echo json_encode($rows);exit;
  1564. }
  1565. $status_list = $this->bhdcd->getStatus();
  1566. foreach($list as $k=>$v){
  1567. $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>";
  1568. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1569. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1570. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1571. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1572. $str = "";
  1573. if(!empty($v['rk_time'])){
  1574. $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>";
  1575. }else{
  1576. if($v['is_rk'] == 0){
  1577. $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>";
  1578. }else{
  1579. $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>";
  1580. }
  1581. if(empty($v['szkw'])){
  1582. $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>";
  1583. }else{
  1584. $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>";
  1585. }
  1586. }
  1587. $list[$k]['rk_time'] = $str;
  1588. unset($list[$k]['is_rk']);
  1589. unset($list[$k]['szkw']);
  1590. }
  1591. $total = $this->bhdcd->find_count($where);
  1592. $pagenum = ceil($total/$perpage);
  1593. $over = $total-($start+$perpage);
  1594. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1595. echo json_encode($rows);exit;
  1596. }else{
  1597. if(empty($lrdcd)){
  1598. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1599. }
  1600. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1601. if(!empty($num)){
  1602. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1603. }
  1604. //查询录入执行的调出单
  1605. $token = $this->settingtest->get_yytoken_120();
  1606. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1607. if(empty($res[0]['Data'])){
  1608. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1609. }
  1610. $time = time();
  1611. $final_list = [];
  1612. foreach($res[0]['Data'] as $k=>$v){
  1613. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1614. $tmp_sku = '';
  1615. $tmp_title = '';
  1616. $tmp_features = '';
  1617. $tmp_number='';
  1618. if(!empty($good_info)){
  1619. $tmp_sku = $good_info['sku'];
  1620. $tmp_title = $good_info['title'];
  1621. $tmp_features = $good_info['features'];
  1622. $tmp_number = str_replace("-","", $good_info['features']);
  1623. }
  1624. $final_list[] = [
  1625. 'sku'=>$tmp_sku,
  1626. 'dcd_no'=>$v['docno'],
  1627. 'jm'=>$v['iteminfo_itemcode'],
  1628. 'zh'=>$v['iteminfo_itemname'],
  1629. 'num'=>$v['costuomqty'],
  1630. 'real_num'=>$v['costuomqty'],
  1631. 'bh_no'=>$v['erp_no'],
  1632. 'create_time'=>$time,
  1633. 'title'=>$tmp_title,
  1634. 'features'=>$tmp_features,
  1635. 'number'=>$tmp_number,
  1636. ];
  1637. }
  1638. $r =$this->db->insert_batch('bhdcd',$final_list);
  1639. if($r){
  1640. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1641. }else{
  1642. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1643. }
  1644. exit;
  1645. }
  1646. }else{
  1647. $status_list = $this->bhdcd->getStatus();
  1648. $this->data['status_list'] = $status_list;
  1649. $this->_Template('beihuogl_ckdcd',$this->data);
  1650. }
  1651. }
  1652. private function _checkdcdsku($arg_array){
  1653. $dcd_no = $arg_array[0];
  1654. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' ");
  1655. echo "<pre>";
  1656. foreach($list as $k=>$v){
  1657. if(empty($v['sku'])){
  1658. $goods_info = $this->goods->find("jm = '".$v['jm']."' ");
  1659. if(!empty($goods_info)){
  1660. $update_arr = [
  1661. 'sku'=>$goods_info['sku'],
  1662. 'title'=>$goods_info['title'],
  1663. 'number'=>trim(str_replace("-","",$goods_info['features'])),
  1664. 'features'=>$goods_info['features'],
  1665. ];
  1666. var_dump($update_arr);
  1667. $this->bhdcd->save($update_arr,$v['id']);
  1668. }else{
  1669. var_dump($v['jm'].'的sku不存在');
  1670. }
  1671. }
  1672. }
  1673. }
  1674. private function _ckbherprk($arg_array){
  1675. if($this->input->method() === 'post'){
  1676. $data = $this->input->post(null,true);
  1677. $dcd_no = $data['dcd_no'];
  1678. $drd_no = $data['drd_no'];
  1679. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1680. $spec_arr = $whlabel_arr = [];
  1681. $time = time();
  1682. $err_list= [];
  1683. foreach($list as $k=>$v){
  1684. if(empty($v['sku'])){
  1685. $err_list[] = $v['jm']."不存在";
  1686. continue;
  1687. }
  1688. //仓库不是特殊仓 且 设置了要校验库位
  1689. if(($v['erp_warehouse'] != 12) && empty($v['szkw'])){
  1690. $tmp_info = $this->whlabel->find("warehouse = '".$v['erp_warehouse']."' and sku = '".$v['sku']."' and details != 'DZ001' ","*","id desc");
  1691. if(!empty($tmp_info)){
  1692. if(!empty($tmp_info['details'])){
  1693. if($tmp_info['details'] != $v['kw']){
  1694. $err_list[] = $v['jm']."的库位信息";
  1695. continue;
  1696. }
  1697. }
  1698. }
  1699. }
  1700. if($v['erp_warehouse'] == '12'){
  1701. //特殊仓处理方案
  1702. for($i=0;$i<$v['num'];$i++){
  1703. $spec_arr[] = [
  1704. 'purchase'=>1,
  1705. 'sku'=>$v['sku'],
  1706. 'number'=>$v['number'],
  1707. 'features'=>$v['features'],
  1708. 'featurespp'=>'',
  1709. 'label'=>'',
  1710. 'title'=>$v['title'],
  1711. // 'zh'=>$v['zh'],
  1712. 'warehouse'=>$v['erp_warehouse'],
  1713. 'enter'=>$time,
  1714. 'state'=>0,
  1715. 'retreatwarehouse'=>$v['erp_warehouse'],
  1716. 'time'=>$time,
  1717. 'details'=>$v['kw'],
  1718. 'bs'=>1,
  1719. 'rktype'=>9,
  1720. ];
  1721. }
  1722. }else{
  1723. for($i=0;$i<$v['num'];$i++){
  1724. $whlabel_arr[] = [
  1725. 'purchase'=>1,
  1726. 'sku'=>$v['sku'],
  1727. 'number'=>$v['number'],
  1728. 'features'=>$v['features'],
  1729. 'title'=>$v['title'],
  1730. 'zh'=>$v['zh'],
  1731. 'warehouse'=>$v['erp_warehouse'],
  1732. 'enter'=>$time,
  1733. 'state'=>0,
  1734. 'retreatwarehouse'=>$v['erp_warehouse'],
  1735. 'time'=>$time,
  1736. 'details'=>$v['kw'],
  1737. 'bs'=>1,
  1738. 'rktype'=>9,
  1739. ];
  1740. }
  1741. }
  1742. }
  1743. if(!empty($err_list)){
  1744. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1745. }
  1746. $this->db->trans_start();
  1747. if(!empty($whlabel_arr)){
  1748. $this->db->insert_batch('whlabel',$whlabel_arr);
  1749. }
  1750. if(!empty($spec_arr)){
  1751. $this->db->insert_batch('specialstock',$spec_arr);
  1752. }
  1753. $this->db->where('dcd_no',$dcd_no);
  1754. //$this->db->where('drd_no',$drd_no);
  1755. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1756. if($this->db->trans_status() === FALSE){
  1757. $this->db->trans_rollback();
  1758. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1759. }else{
  1760. $this->db->trans_commit();
  1761. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1762. }
  1763. }else{
  1764. $dcd_no = $arg_array[0];
  1765. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1766. $jm_list = array_column($list,'jm');
  1767. $status_list = $this->bhdcd->getStatus();
  1768. $in_where = "( ";
  1769. foreach($jm_list as $k=>$v){
  1770. $in_where .= "'".$v."',";
  1771. }
  1772. $in_where = rtrim($in_where,",");
  1773. $in_where .= " )";
  1774. $warehouse_list = [
  1775. 12=>'特殊仓',
  1776. 13=>'许昌仓',
  1777. 16=>'定制头套仓'
  1778. ];
  1779. foreach($list as $k=>$v){
  1780. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1781. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1782. $list[$k]['warehouse_show'] = isset($warehouse_list[$v['erp_warehouse']])?$warehouse_list[$v['erp_warehouse']]:"";
  1783. if(!empty($v['kw'])){
  1784. $list[$k]['kw'] = $v['kw'];
  1785. }else{
  1786. if(!empty($list[$k]['sku'])){
  1787. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1788. if(!empty($whlabel_info)){
  1789. if(!empty($whlabel_info['details'])){
  1790. $list[$k]['kw'] = $whlabel_info['details'];
  1791. $this->bhdcd->save([
  1792. 'kw'=>$whlabel_info['details'],
  1793. ],$v['id']);
  1794. }else{
  1795. $list[$k]['kw'] = "";
  1796. }
  1797. }else{
  1798. $list[$k]['kw'] = "";
  1799. }
  1800. }else{
  1801. $list[$k]['kw'] = "";
  1802. }
  1803. }
  1804. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1805. }
  1806. $this->data['list'] = $list;
  1807. $this->_Template('beihuogl_ckbherprk',$this->data);
  1808. }
  1809. }
  1810. private function _bhdcdsave(){
  1811. if($this->input->method() === 'post'){
  1812. $id = $this->input->post('id',true);
  1813. $val = $this->input->post('val',true);
  1814. $column = $this->input->post('column',true);
  1815. $info = $this->bhdcd->read($id);
  1816. $update_arr = [];
  1817. if($column == 'real_num'){
  1818. if($val > $info['num']){
  1819. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1820. }
  1821. $update_arr = [
  1822. 'real_num'=>(int)$val,
  1823. ];
  1824. }elseif($column == 'kw'){
  1825. if($info['erp_warehouse'] == '12'){
  1826. echo json_encode(['success'=>false,'msg'=>'特殊仓不设置库位']);exit;
  1827. }else{
  1828. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1829. if(!empty($winfo)){
  1830. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1831. if(empty($winfo)){
  1832. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1833. }
  1834. }
  1835. $update_arr = [
  1836. 'kw'=>trim($val),
  1837. ];
  1838. }
  1839. }elseif($column == 'ck'){
  1840. $update_arr = [
  1841. 'erp_warehouse'=>trim($val),
  1842. ];
  1843. }else{
  1844. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1845. }
  1846. $r = $this->bhdcd->save($update_arr,$id);
  1847. if($r){
  1848. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1849. }else{
  1850. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1851. }
  1852. }else{
  1853. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1854. }
  1855. }
  1856. private function _u9scdexcel($arg_array){
  1857. $id = $arg_array[0];
  1858. $info = $this->bhccwl->read($id);
  1859. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1860. $shop_list = $this->shop->find_all("id > 0");
  1861. $shop_list = array_column($shop_list,'shopname','id');
  1862. foreach($list as $k=>$v){
  1863. $list[$k]['shop_show'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:'';
  1864. }
  1865. //生成excel
  1866. $filename = $info['bh_no']."备货生产单.xls";
  1867. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1868. <head>
  1869. <!--[if gte mso 9]><xml>
  1870. <x:ExcelWorkbook>
  1871. <x:ExcelWorksheets>
  1872. <x:ExcelWorksheet>
  1873. <x:Name>EXCEL</x:Name>
  1874. <x:WorksheetOptions>
  1875. <x:Print>
  1876. <x:ValidPrinterInfo />
  1877. </x:Print>
  1878. </x:WorksheetOptions>
  1879. </x:ExcelWorksheet>
  1880. </x:ExcelWorksheets>
  1881. </x:ExcelWorkbook>
  1882. </xml>
  1883. <![endif]-->
  1884. </head><body>";
  1885. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1886. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td><td>申请人</td><td>店铺</td><td>备注</td></tr>";
  1887. foreach ($list as $key=>$value)
  1888. {
  1889. $str .= "<tr>";
  1890. $str .= "<td>". $value['bh_no']. "</td>";
  1891. $str .= "<td>". $value['title']. "</td>";
  1892. $str .= "<td>". $value['jm']. "</td>";
  1893. $str .= "<td>". $value['ck_num']. "</td>";
  1894. $str .= "<td>". $value['u9sc_no']. "</td>";
  1895. $str .= "<td>". $value['sqr']. "</td>";
  1896. $str .= "<td>". $value['shop_show']. "</td>";
  1897. $str .= "<td>". $value['remark']. "</td>";
  1898. $str .= "</tr>";
  1899. }
  1900. $str .= "</table></body></html>";
  1901. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1902. header( "Content-type: application/octet-stream" );
  1903. header( "Content-Disposition: attachment; filename=".$filename );
  1904. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1905. header( "Pragma: no-cache" );
  1906. header( "Expires: 0" );
  1907. exit($str);
  1908. }
  1909. //打印标签
  1910. private function _printlabel(){
  1911. if($this->input->method() === 'post'){
  1912. $id = $this->input->post('id',true);
  1913. $xbqnum = $this->input->post('num',true);
  1914. $info = $this->bhdcd->read($id);
  1915. if(empty($info)){
  1916. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1917. }
  1918. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1919. $featurespp = explode('-', trim($featurespp, '-'));
  1920. if (isset($featurespp[5])) {
  1921. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1922. } else {
  1923. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1924. }
  1925. $label = '';
  1926. $cpid = $this->whlabellabel->find_count();
  1927. $cpid = $cpid + 1;
  1928. $time = time();
  1929. $label = time().rand(10,99);
  1930. $label = substr($label,1);
  1931. $insert_arr = [
  1932. 'purchase'=>1,
  1933. 'shop'=>'',
  1934. 'sku'=>$info['sku'],
  1935. 'number'=>$info['number'],
  1936. 'features'=>$info['features'],
  1937. 'featurespp'=>$tmp_featurespp,
  1938. 'title'=>$info['title'],
  1939. 'label'=>$label,
  1940. 'warehouse'=>$info['erp_warehouse'],
  1941. 'time'=>$time,
  1942. 'details'=>empty($info['kw'])?'':$info['kw'],
  1943. 'cpid'=>$cpid,
  1944. 'jm'=>$info['jm'],
  1945. 'cpbz'=>''
  1946. ];
  1947. $warehouse_info = $this->warehouse->read($info['erp_warehouse']);
  1948. if(empty($warehouse_info)){
  1949. $warehouse_name = "仓库异常";
  1950. }else{
  1951. $warehouse_name = $warehouse_info['title'];
  1952. }
  1953. $this->db->trans_begin();
  1954. $this->whlabellabel->insert($insert_arr);
  1955. if ($this->db->trans_status() === TRUE) {
  1956. $this->db->trans_commit();
  1957. } else {
  1958. $this->db->trans_rollback();
  1959. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  1960. exit;
  1961. }
  1962. if(empty($info['kw'])){
  1963. $details = '<font style="font-size: 18px;">' . $cpid . '</font>' ;
  1964. }else{
  1965. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  1966. }
  1967. $details = ' <b style="font-size: 18px;">'.$warehouse_name."</b> ".$details;
  1968. $purchase = "龙盈工厂";
  1969. 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));
  1970. exit; //特殊仓目前不需要仓库选项
  1971. }else{
  1972. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1973. }
  1974. }
  1975. private function _dcdjzrk(){
  1976. if($this->input->method() === 'post'){
  1977. $id = $this->input->post('id',true);
  1978. $type = $this->input->post('type',true);
  1979. $is_rk = 0;
  1980. if($type == 1){
  1981. $is_rk = 1;
  1982. }else{
  1983. $is_rk = 0;
  1984. }
  1985. $info = $this->bhdcd->read($id);
  1986. if($info['is_rk'] != $is_rk){
  1987. $this->bhdcd->save(['is_rk'=>$is_rk],$id);
  1988. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1989. }else{
  1990. if($type ==1){
  1991. echo json_encode(['success'=>false,'msg'=>'此条信息已禁止入库']);exit;
  1992. }else{
  1993. echo json_encode(['success'=>false,'msg'=>'此条信息已允许入库']);exit;
  1994. }
  1995. }
  1996. }else{
  1997. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1998. }
  1999. }
  2000. private function _dyapplyyjsh(){
  2001. if($this->input->method() === 'post'){
  2002. $arr_id = $this->input->post('arr_id',true);
  2003. $this->db->where_in('id',$arr_id);
  2004. $this->db->where('sq_status',1);
  2005. $this->db->update('bhsq',['sq_status'=>2]);
  2006. echo json_encode(['success'=>true,'msg'=>'审核通过']);exit;
  2007. }else{
  2008. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2009. }
  2010. }
  2011. private function _dcdkwyz(){
  2012. if($this->input->method() === 'post'){
  2013. $id = $this->input->post('id',true);
  2014. $type = $this->input->post('type',true);
  2015. $szkw = 0;
  2016. if($type == 1){
  2017. $szkw = 1;
  2018. }else{
  2019. $szkw = 0;
  2020. }
  2021. $info = $this->bhdcd->read($id);
  2022. if($info['szkw'] != $szkw){
  2023. $this->bhdcd->save(['szkw'=>$szkw],$id);
  2024. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  2025. }else{
  2026. if($type ==1){
  2027. echo json_encode(['success'=>false,'msg'=>'此条信息已禁止验证库位']);exit;
  2028. }else{
  2029. echo json_encode(['success'=>false,'msg'=>'此条信息已允许验证库位']);exit;
  2030. }
  2031. }
  2032. }else{
  2033. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  2034. }
  2035. }
  2036. private function _ckexcel($arg_array){
  2037. $id = $arg_array[0];
  2038. $info = $this->bhccwl->read($id);
  2039. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  2040. //生成excel
  2041. $filename = $info['bh_no']."备货生产单.xls";
  2042. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  2043. <head>
  2044. <!--[if gte mso 9]><xml>
  2045. <x:ExcelWorkbook>
  2046. <x:ExcelWorksheets>
  2047. <x:ExcelWorksheet>
  2048. <x:Name>EXCEL</x:Name>
  2049. <x:WorksheetOptions>
  2050. <x:Print>
  2051. <x:ValidPrinterInfo />
  2052. </x:Print>
  2053. </x:WorksheetOptions>
  2054. </x:ExcelWorksheet>
  2055. </x:ExcelWorksheets>
  2056. </x:ExcelWorkbook>
  2057. </xml>
  2058. <![endif]-->
  2059. </head><body>";
  2060. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  2061. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td></tr>";
  2062. foreach ($list as $key=>$value)
  2063. {
  2064. $str .= "<tr>";
  2065. $str .= "<td>". $value['bh_no']. "</td>";
  2066. $str .= "<td>". $value['title']. "</td>";
  2067. $str .= "<td>". $value['jm']. "</td>";
  2068. $str .= "<td>". $value['ck_num']. "</td>";
  2069. $str .= "</tr>";
  2070. }
  2071. $str .= "</table></body></html>";
  2072. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  2073. header( "Content-type: application/octet-stream" );
  2074. header( "Content-Disposition: attachment; filename=".$filename );
  2075. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  2076. header( "Pragma: no-cache" );
  2077. header( "Expires: 0" );
  2078. exit($str);
  2079. }
  2080. }