Beihuogl.php 124 KB

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