Beihuogl.php 124 KB

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