Beihuogl.php 112 KB

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