Beihuogl.php 111 KB

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