Beihuogl.php 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  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. }
  17. //定义方法的调用规则 获取URI第二段值
  18. public function _remap($arg,$arg_array)
  19. {
  20. if(!isset($_SESSION['api'])){
  21. header('Location: /');exit;
  22. }
  23. if($arg == 'dyapply')//
  24. {
  25. $this->_dyapply();
  26. }
  27. elseif($arg == 'dyapplyadd')//
  28. {
  29. $this->_dyapplyadd();
  30. }
  31. elseif($arg == 'dyapplyedit')//
  32. {
  33. $this->_dyapplyedit($arg_array);
  34. }
  35. elseif($arg == 'dyapplygxzt')//
  36. {
  37. $this->_dyapplygxzt();
  38. }
  39. elseif($arg == 'dyapplyexcel'){
  40. $this->_dyapplyexcel();
  41. }
  42. elseif($arg == 'ccwlshlist'){
  43. $this->_ccwlshlist();
  44. }
  45. elseif($arg == 'ccwlbhindex'){
  46. $this->_ccwlbhindex();
  47. }elseif($arg == 'dyapplysave'){
  48. $this->_dyapplysave();
  49. }elseif($arg == 'ccwlbhmake'){
  50. $this->_ccwlbhmake();
  51. }elseif($arg == 'ccwlbhedit'){
  52. $this->_ccwlbhedit($arg_array);
  53. }elseif($arg == 'ccwleditxzbh'){
  54. $this->_ccwleditxzbh();
  55. }elseif($arg == 'ccwlbhsavexzbh'){
  56. $this->_ccwlbhsavexzbh();
  57. }elseif($arg == 'ccwldelitem'){
  58. $this->_ccwldelitem();
  59. }elseif($arg == 'ccwlbhsave'){
  60. $this->_ccwlbhsave();
  61. }elseif($arg == 'ckbhindex'){
  62. $this->_ckbhindex();
  63. }elseif($arg == 'ckbhedit'){
  64. $this->_ckbhedit($arg_array);
  65. }elseif($arg == 'makeu9scd'){
  66. $this->_makeu9scd($arg_array);
  67. }elseif($arg == 'showckbh'){
  68. $this->_showckbh($arg_array);
  69. }elseif($arg == 'ddscscd'){
  70. $this->_ddscscd();
  71. }elseif($arg == 'ckdcd'){
  72. $this->_ckdcd();
  73. }elseif($arg == 'ckbherprk'){
  74. $this->_ckbherprk($arg_array);
  75. }elseif($arg == 'bhdcdsave'){
  76. $this->_bhdcdsave();
  77. }elseif($arg == 'u9scdexcel')
  78. {
  79. $this->_u9scdexcel($arg_array);
  80. }elseif($arg == 'ccwlskucheck'){
  81. $this->_ccwlskucheck();
  82. }elseif($arg == 'printlabel'){
  83. $this->_printlabel();
  84. }elseif($arg == 'deldyapply'){
  85. $this->_deldyapply();
  86. }elseif($arg == 'dcdjzrk'){
  87. $this->_dcdjzrk();
  88. }elseif($arg == 'dyapplyyjsh'){
  89. $this->_dyapplyyjsh();
  90. }elseif($arg == 'ccwlbhdownload'){
  91. $this->_ccwlbhdownload();
  92. }elseif($arg == 'ckexcel'){
  93. $this->_ckexcel($arg_array);
  94. }elseif($arg == 'checkdcdsku'){
  95. $this->_checkdcdsku($arg_array);
  96. }
  97. else
  98. {
  99. $this->_index();
  100. }
  101. }
  102. private function _index(){
  103. exit('No direct script access allowed 1');
  104. }
  105. //备货申请单的列表
  106. private function _dyapply(){
  107. if($this->input->method() === 'post'){
  108. $vip_id = $this->input->post('vip_id',true);
  109. $page = $this->input->post('page',true);
  110. $perpage = $this->input->post('perpage',true);
  111. $sqr = $this->input->post('sqr',true);
  112. $sqr = trim($sqr);
  113. $sq_status = $this->input->post('sq_status',true);
  114. $shop_id = $this->input->post('shop_id',true);
  115. $plat_id = $this->input->post('plat_id',true);
  116. $shop_ids = $this->input->post('shop_ids',true);
  117. $ktime = $this->input->post('ktime',true);
  118. $jtime = $this->input->post('jtime',true);
  119. $ktime = strtotime($ktime);
  120. $jtime = strtotime($jtime);
  121. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  122. if(!empty($sqr)){
  123. $where .= " and sqr = '".$sqr."' ";
  124. }
  125. if($shop_id > -1){
  126. $where .= " and shop_id = ".$shop_id." ";
  127. }else{
  128. if($vip_id == 1){
  129. }else{
  130. $where .= " and shop_id in (".$shop_ids.") ";
  131. }
  132. }
  133. if($sq_status > -1){
  134. $where .= " and sq_status = ".$sq_status." ";
  135. }
  136. if($plat_id > -1){
  137. $where .= " and plat_id = ".$plat_id." ";
  138. }
  139. //数据排序
  140. $order_str = "id desc";
  141. if(empty($page))
  142. {
  143. $start = 0;
  144. $perpage = 1;
  145. }
  146. else
  147. {
  148. $start = ($page - 1)*$perpage;
  149. }
  150. $list = $this->bhsq->find_all($where,"id,shop_id,plat_id,title,sku,sqr,sq_num,sq_status,add_time,update_time",$order_str,$start,$perpage);
  151. if(empty($list)){
  152. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  153. echo json_encode($rows);exit;
  154. }
  155. $shop_list = $this->shop->find_all("1=1","id,shopname");
  156. $shop_list = array_column($shop_list,'shopname','id');
  157. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  158. $plat_list = array_column($plat_list,'title','id');
  159. $status_list = $this->bhsq->getSqStatus();
  160. foreach($list as $k=>$v){
  161. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  162. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  163. $list[$k]['sq_status'] = isset($status_list[$v['sq_status']])?$status_list[$v['sq_status']]:"";
  164. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  165. $str = "";
  166. if($v['sq_status'] == 1 || $v['sq_status'] == 3){
  167. $str .= "<div style='text-align:center;'>";
  168. $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>";
  169. $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>";
  170. $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>";
  171. $str .= "</div>";
  172. }
  173. if($v['sq_status'] == 0){
  174. $str .= "<div style='text-align:center;'>";
  175. $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>";
  176. $str .= "</div>";
  177. }
  178. $list[$k]['update_time'] = $str;
  179. }
  180. $total = $this->bhsq->find_count($where);
  181. $pagenum = ceil($total/$perpage);
  182. $over = $total-($start+$perpage);
  183. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  184. echo json_encode($rows);exit;
  185. }else{
  186. $user = $this->user->get_api($_SESSION['api']);
  187. $usersp = explode('|',trim($user['shop'],'|'));
  188. $this->data['usersp'] = implode(",",$usersp);
  189. $vip_id = 0;
  190. if(in_array($user['id'],[10,28])){
  191. $vip_id = 1;
  192. }
  193. $status_list = $this->bhsq->getSqStatus();
  194. $this->data['status_list'] = $status_list;
  195. $this->data['vip_id'] = $vip_id;
  196. $this->_Template('beihuogl_dyapply',$this->data);
  197. }
  198. }
  199. //备货申请单的添加
  200. private function _dyapplyadd(){
  201. if($this->input->method() === 'post'){
  202. $data = $this->input->post();
  203. $time = strtotime(date("Y-m-d"),time());
  204. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  205. if(empty($info)){
  206. $num = 1;
  207. }else{
  208. $arr = explode('-',$info['sb_no']);
  209. $num = (int)$arr[2]+1;
  210. }
  211. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  212. $sb_no = "SQ-".date("ymd")."-".$num;
  213. $insert_arr = [];
  214. $time = time();
  215. foreach($data['title'] as $k=>$v){
  216. $insert_arr[] = [
  217. 'sb_no'=>$sb_no,
  218. 'sku'=>$data['sku'][$k],
  219. 'title'=>$data['title'][$k],
  220. 'shop_id'=>$data['shop_id'],
  221. 'plat_id'=>$data['plat_id'],
  222. 'sqr'=>$data['sqr'],
  223. 'sq_num'=>$data['sq_num'][$k],
  224. 'ccwl_num'=>$data['sq_num'][$k],
  225. 'ck_num'=>$data['sq_num'][$k],
  226. 'sq_status'=>1,
  227. 'remark'=>$data['remark'],
  228. 'add_time'=>$time,
  229. 'real_time'=>$time,
  230. 'update_time'=>$time,
  231. ];
  232. }
  233. $r =$this->db->insert_batch('bhsq',$insert_arr);
  234. if($r){
  235. echo json_encode(['code'=>1,'msg'=>'添加成功']);
  236. }else{
  237. echo json_encode(['code'=>-1,'msg'=>'添加失败']);
  238. }
  239. exit;
  240. }else{
  241. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  242. $this->data['plat_list'] = $plat_list;
  243. $this->_Template('beihuogl_dyapplyadd',$this->data);
  244. }
  245. }
  246. //备货申请单的 修改
  247. private function _dyapplyedit($arg_array){
  248. if($this->input->method() === 'post'){
  249. $data = $this->input->post();
  250. $id = $data['id'];
  251. $update_arr = [
  252. 'shop_id'=>$data['shop_id'],
  253. 'plat_id'=>$data['plat_id'],
  254. 'sqr'=>$data['sqr'],
  255. 'sq_num'=>$data['sq_num'],
  256. 'ccwl_num'=>$data['sq_num'],
  257. 'ck_num'=>$data['sq_num'],
  258. 'sku'=>$data['sku'],
  259. 'remark'=>$data['remark'],
  260. ];
  261. $r = $this->bhsq->save($update_arr,$id);
  262. if($r){
  263. echo json_encode(['msg'=>'添加成功','success'=>true]);
  264. }else{
  265. echo json_encode(['msg'=>'添加失败','success'=>false]);
  266. }
  267. exit;
  268. }else{
  269. $id = $arg_array[0];
  270. $info = $this->bhsq->find("id = ".$id);
  271. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  272. $this->data['plat_list'] = $plat_list;
  273. $this->data['info'] = $info;
  274. $this->_Template('beihuogl_dyapplyedit',$this->data);
  275. }
  276. }
  277. //备货申请单的 状态申请 如 发布 或者取消
  278. private function _dyapplygxzt(){
  279. if($this->input->method() === 'post'){
  280. $data = $this->input->post();
  281. $id = (int)$data['id'];
  282. $type = (int)$data['status'];
  283. $update_arr = [];
  284. $update_arr['sq_status'] = $type;
  285. if($type == 2){
  286. $update_arr['public_time'] = time();
  287. }
  288. if($type == 3){
  289. $update_arr['ccwl_status'] = 0;
  290. $update_arr['ck_status'] = 0;
  291. $update_arr['features'] = '';
  292. $update_arr['jm'] = '';
  293. $update_arr['public_time'] = 0;
  294. $update_arr['bh_no'] = '';
  295. $update_arr['u9sc_no'] = '';
  296. }
  297. $r = $this->bhsq->save($update_arr,$id);
  298. if($r){
  299. echo json_encode(['msg'=>'修改成功','success'=>true]);
  300. }else{
  301. echo json_encode(['msg'=>'修改失败','success'=>false]);
  302. }
  303. exit;
  304. }else{
  305. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  306. }
  307. }
  308. private function _deldyapply(){
  309. if($this->input->method() === 'post'){
  310. $data = $this->input->post();
  311. $id = $data['id'];
  312. $info = $this->bhsq->read($id);
  313. if($info['sq_status'] != 0){
  314. echo json_encode(['msg'=>'此条记录不符合删除条件','success'=>false]);
  315. exit;
  316. }
  317. $r = $this->bhsq->remove($id);
  318. if($r){
  319. echo json_encode(['msg'=>'删除成功','success'=>true]);
  320. }else{
  321. echo json_encode(['msg'=>'删除失败','success'=>false]);
  322. }
  323. exit;
  324. }else{
  325. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  326. }
  327. }
  328. //备货申请单的
  329. private function _dyapplysave(){
  330. if($this->input->method() === 'post'){
  331. $data = $this->input->post();
  332. $id = (int)$data['id'];
  333. $val = $this->input->post('val',true);
  334. $column = $data['column'];
  335. if($column == 'ccwl_num'){
  336. $update_arr = [
  337. 'ccwl_num'=>(int)$val,
  338. 'ck_num'=>(int)$val,
  339. ];
  340. }elseif($column == 'sku'){
  341. $update_arr = [
  342. 'sku'=>$val,
  343. ];
  344. }elseif($column == 'ck_num'){
  345. $update_arr = [
  346. 'ck_num'=>(int)$val,
  347. ];
  348. }elseif($column == 'drck'){
  349. $update_arr = [
  350. 'drck'=>(int)$val,
  351. ];
  352. }else{
  353. echo json_encode(['msg'=>'修改信息不合规','success'=>false]);
  354. exit;
  355. }
  356. $r = $this->bhsq->save($update_arr,$id);
  357. if($r){
  358. echo json_encode(['msg'=>'修改成功','success'=>true]);
  359. }else{
  360. echo json_encode(['msg'=>'修改失败','success'=>false]);
  361. }
  362. exit;
  363. }else{
  364. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  365. }
  366. }
  367. private function _dyapplyexcel(){
  368. if($this->input->method() === 'post'){
  369. $data = $this->input->post('list',true);
  370. if(empty($data)){
  371. $json_data = $this->input->raw_input_stream;
  372. $tmp_data = json_decode($json_data,true);
  373. $data = $tmp_data['list'];
  374. if(empty($data)){
  375. echo json_encode(['success'=>false,'msg'=>'未获取要保存的数据']);
  376. exit;
  377. }
  378. }
  379. $shop_list = $this->shop->find_all("1=1","id,shortname,type");
  380. $shop_list = array_column($shop_list,null,'shortname');
  381. $time = strtotime(date("Y-m-d"),time());
  382. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  383. if(empty($info)){
  384. $num = 1;
  385. }else{
  386. $arr = explode('-',$info['sb_no']);
  387. $num = (int)$arr[2]+1;
  388. }
  389. $time = time();
  390. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  391. $sb_no = "SQ-".date("ymd")."-".$num;
  392. $insert_arr = [];
  393. $error_list= [];
  394. foreach($data as $k=>$v){
  395. $shopshortname = trim($v[4]);
  396. if($shopshortname == '无'){
  397. $shop_info = [
  398. 'id'=>0,
  399. 'type'=>0,
  400. ];
  401. }else{
  402. $shop_info = isset($shop_list[$shopshortname])?$shop_list[$shopshortname]:[];
  403. if(empty($shop_info)){
  404. $error_list[] = [
  405. 'msg'=>"第".($k+1).'行店铺不存在,请核对表格信息'.$shopshortname,
  406. ];
  407. continue;
  408. }
  409. }
  410. $num = (int)$v[3];
  411. if(empty($num)){
  412. $error_list[] = [
  413. 'msg'=>"第".($k+1).'行数量不能为空,请核对表格信息',
  414. ];
  415. continue;
  416. }
  417. $tmp_time = trim($v[0]);
  418. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tmp_time)) {
  419. $add_time = strtotime($tmp_time);
  420. }else{
  421. $error_list[] = [
  422. 'msg'=>"第".($k+1).'行日期格式不正确,请核对表格信息',
  423. ];
  424. continue;
  425. }
  426. if(empty($v[5])){
  427. $error_list[] = [
  428. 'msg'=>"第".($k+1).'行申请人信息不能为空,请核对表格信息',
  429. ];
  430. continue;
  431. }
  432. if(empty($v[1])){
  433. $error_list[] = [
  434. 'msg'=>"第".($k+1).'行产品信息不能为空,请核对表格信息',
  435. ];
  436. continue;
  437. }
  438. $insert_arr[] = [
  439. 'sb_no'=>$sb_no,
  440. 'sku'=>trim($v[2]),
  441. 'title'=>trim($v[1]),
  442. 'shop_id'=>$shop_info['id'],
  443. 'plat_id'=>$shop_info['type'],
  444. 'sqr'=>trim($v[5]),
  445. 'sq_num'=>$num,
  446. 'ccwl_num'=>$num,
  447. 'ck_num'=>$num,
  448. 'sq_status'=>1,
  449. 'remark'=>$v[6],
  450. 'add_time'=>$add_time,
  451. 'real_time'=>$time,
  452. 'update_time'=>$time,
  453. ];
  454. }
  455. $r =$this->db->insert_batch('bhsq',$insert_arr);
  456. if($r){
  457. if(empty($error_list)){
  458. echo json_encode(['success'=>true,'msg'=>'添加成功']);
  459. }else{
  460. echo json_encode(['success'=>true,'msg'=>'添加成功','error_list'=>$error_list]);
  461. }
  462. }else{
  463. echo json_encode(['success'=>false,'msg'=>'添加失败','error_list'=>$error_list]);
  464. }
  465. exit;
  466. }else{
  467. echo json_encode(['success'=>true,'msg'=>'请求失败']);
  468. exit;
  469. }
  470. }
  471. //仓储物流部的备货申请单的列表
  472. private function _ccwlshlist(){
  473. if($this->input->method() === 'post'){
  474. $vip_id = $this->input->post('vip_id',true);
  475. $page = $this->input->post('page',true);
  476. $perpage = $this->input->post('perpage',true);
  477. $sqr = $this->input->post('sqr',true);
  478. $sqr = trim($sqr);
  479. $shop_id = $this->input->post('shop_id',true);
  480. $plat_id = $this->input->post('plat_id',true);
  481. $shop_ids = $this->input->post('shop_ids',true);
  482. $ktime = $this->input->post('ktime',true);
  483. $jtime = $this->input->post('jtime',true);
  484. $ktime = strtotime($ktime);
  485. $jtime = strtotime($jtime);
  486. $where = "sq_status = 2 and ccwl_status = 0 ";
  487. $where .= " and add_time >= ".$ktime." and add_time < ".$jtime." ";
  488. if(!empty($sqr)){
  489. $where .= " and sqr = '".$sqr."' ";
  490. }
  491. if(!empty($shop_id)){
  492. $where .= " and shop_id = ".$shop_id." ";
  493. }else{
  494. if($vip_id == 1){
  495. }else{
  496. $where .= " and shop_id in (".$shop_ids.") ";
  497. }
  498. }
  499. if(!empty($plat_id)){
  500. $where .= " and plat_id = ".$plat_id." ";
  501. }
  502. //数据排序
  503. $order_str = "id desc";
  504. if(empty($page))
  505. {
  506. $start = 0;
  507. $perpage = 1;
  508. }
  509. else
  510. {
  511. $start = ($page - 1)*$perpage;
  512. }
  513. $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);
  514. if(empty($list)){
  515. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  516. echo json_encode($rows);exit;
  517. }
  518. $shop_list = $this->shop->find_all("1=1","id,shopname");
  519. $shop_list = array_column($shop_list,'shopname','id');
  520. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  521. $plat_list = array_column($plat_list,'title','id');
  522. foreach($list as $k=>$v){
  523. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无";
  524. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无";
  525. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  526. if($v['erp_check'] == 1){
  527. $list[$k]['sku'] = "<a style='color:red' href='javascript:void(0)' onclick='addnewgoods'>".$v['sku']."</a> <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  528. }else{
  529. $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  530. }
  531. $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>";
  532. $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>";
  533. unset($list[$k]['erp_check']);
  534. }
  535. $total = $this->bhsq->find_count($where);
  536. $pagenum = ceil($total/$perpage);
  537. $over = $total-($start+$perpage);
  538. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  539. echo json_encode($rows);exit;
  540. }else{
  541. $user = $this->user->get_api($_SESSION['api']);
  542. $usersp = explode('|',trim($user['shop'],'|'));
  543. $this->data['usersp'] = implode(",",$usersp);
  544. $vip_id = 0;
  545. if(in_array($user['id'],[10,28])){
  546. $vip_id = 1;
  547. }
  548. $this->data['vip_id'] = $vip_id;
  549. $this->_Template('beihuogl_ccwlshlist',$this->data);
  550. }
  551. }
  552. //一键校验选中SKU
  553. private function _ccwlskucheck(){
  554. if($this->input->method() === 'post'){
  555. $data = $this->input->post();
  556. if(empty($data['arr_id'])){
  557. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  558. exit;
  559. }
  560. $list = $this->bhsq->find_all('id in ('.implode(',',$data['arr_id']).')');
  561. $error_list = [];
  562. $success_ids = [];
  563. $errors_ids = [];
  564. foreach($list as $k=>$v){
  565. if(empty($v['sku'])){
  566. $error_list[] = [
  567. 'msg'=>$v['value'].'请录入SKU',
  568. ];
  569. $errors_ids[] = $v['id'];
  570. continue;
  571. }
  572. $num = $this->goods->find_count("sku = '".$v['sku']."'");
  573. if(!empty($num)){
  574. $success_ids[] = $v['id'];
  575. continue;
  576. }
  577. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  578. if(empty($whlabel_info)){
  579. $error_list[] = [
  580. 'msg'=>$v['sku'].'未在进销存浏览那找到对应信息',
  581. ];
  582. $errors_ids[] = $v['id'];
  583. }
  584. }
  585. if(!empty($error_list)){
  586. $this->db->where_in('id', $errors_ids);
  587. $this->db->update('bhsq', ['erp_check'=>1]);
  588. }
  589. if(!empty($success_ids)){
  590. $this->db->where_in('id', $success_ids);
  591. $this->db->update('bhsq', ['erp_check'=>0]);
  592. }
  593. if(empty($error_list)){
  594. echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
  595. exit;
  596. }else{
  597. echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
  598. exit;
  599. }
  600. }else{
  601. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  602. exit;
  603. }
  604. }
  605. private function _ccwlbhdownload(){
  606. if($this->input->method() === 'get'){
  607. $query = $this->input->get(null,true);
  608. if(empty($query['excel'])){
  609. exit("不符合下载要求");
  610. }
  611. if($query['excel'] != 'erp'){
  612. exit("不符合下载要求");
  613. }
  614. $ids = $this->input->get('ids',true);
  615. if(empty($ids)){
  616. exit("请选择要下载的备货单");
  617. }
  618. $arr_id = [];
  619. if(stripos($ids,'|') !== false){
  620. $arr_id = explode('|', $ids);
  621. }else{
  622. $arr_id[] = $ids;
  623. }
  624. if(empty($arr_id)){
  625. exit("请选择要下载的备货单-1");
  626. }
  627. $list = $this->bhccwl->find_all('id in ('.implode(',',$arr_id).')');
  628. $batch_nos = array_column($list,'bh_no');
  629. $batch_no_str = '';
  630. foreach($batch_nos as $k=>$v){
  631. $batch_no_str .= "'".$v."',";
  632. }
  633. $batch_no_str = trim($batch_no_str,',');
  634. $bh_list = $this->bhsq->find_all("bh_no in (".$batch_no_str.")");
  635. if(empty($bh_list)){
  636. exit("备货单料品信息为空");
  637. }
  638. $shop_list = $this->shop->find_all("1=1","id,shopname");
  639. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  640. $shop_list = array_column($shop_list,'shopname','id');
  641. $plat_list = array_column($plat_list,'title','id');
  642. $final_list= [];
  643. foreach($bh_list as $k=>$v){
  644. $final_list[] = [
  645. 'bh_no'=>$v['bh_no'],
  646. 'shop'=>isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"无",
  647. 'plat'=>isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"无",
  648. 'zh'=>$v['title'],
  649. 'jm'=>$v['jm'],
  650. 'sqr'=>$v['sqr'],
  651. 'sq_num'=>$v['sq_num'],
  652. 'public_time'=>date("Y-m-d",$v['public_time']),
  653. 'remark'=>$v['remark'],
  654. ];
  655. }
  656. $filename = "备货生产单.xls";
  657. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  658. <head>
  659. <!--[if gte mso 9]><xml>
  660. <x:ExcelWorkbook>
  661. <x:ExcelWorksheets>
  662. <x:ExcelWorksheet>
  663. <x:Name>EXCEL</x:Name>
  664. <x:WorksheetOptions>
  665. <x:Print>
  666. <x:ValidPrinterInfo />
  667. </x:Print>
  668. </x:WorksheetOptions>
  669. </x:ExcelWorksheet>
  670. </x:ExcelWorksheets>
  671. </x:ExcelWorkbook>
  672. </xml>
  673. <![endif]-->
  674. </head><body>";
  675. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  676. $str .= "<tr><td>备货单号</td><td>店铺</td><td>平台</td><td>中文名称</td><td>u9料号</td><td>申请人</td><td>申请数量<td>申请时间</td><td>备注</td></tr>";
  677. foreach ($final_list as $key=>$value)
  678. {
  679. $str .= "<tr>";
  680. $str .= "<td>". $value['bh_no']. "</td>";
  681. $str .= "<td>". $value['shop']. "</td>";
  682. $str .= "<td>". $value['plat']. "</td>";
  683. $str .= "<td>". $value['zh']. "</td>";
  684. $str .= "<td>". $value['jm']. "</td>";
  685. $str .= "<td>". $value['sqr']. "</td>";
  686. $str .= "<td>". $value['sq_num']. "</td>";
  687. $str .= "<td>". $value['public_time']. "</td>";
  688. $str .= "<td>". $value['remark']. "</td>";
  689. $str .= "</tr>";
  690. }
  691. $str .= "</table></body></html>";
  692. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  693. header( "Content-type: application/octet-stream" );
  694. header( "Content-Disposition: attachment; filename=".$filename );
  695. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  696. header( "Pragma: no-cache" );
  697. header( "Expires: 0" );
  698. exit($str);
  699. }
  700. }
  701. //仓储物流合成备货单
  702. private function _ccwlbhmake(){
  703. if($this->input->method() === 'post'){
  704. $data = $this->input->post();
  705. if(empty($data['arr_id'])){
  706. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  707. exit;
  708. }
  709. $bh_no = $data['bh_no'];
  710. $select_id = $data['arr_id'];
  711. if(empty($select_id)){
  712. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  713. exit;
  714. }
  715. if(empty($bh_no)){
  716. $tmp_time = strtotime(date("Y-m-d"),time());
  717. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  718. $num = $num+1;
  719. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  720. $bh_no = "BH-".date("ymd")."-".$num;
  721. }else{
  722. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  723. if(!empty($info)){
  724. echo json_encode(['success'=>false,'msg'=>'生成的备货单编号已经存在']);
  725. exit;
  726. }
  727. }
  728. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  729. foreach($list as $k=>$v){
  730. if(empty($v['sku'])){
  731. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  732. exit;
  733. }
  734. }
  735. $classid = $this->logic_u9tools->getClass();
  736. $typeclass = $this->logic_u9tools->getTypeClass();
  737. foreach($list as $k=>$v){
  738. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  739. if(empty($whlabel_info)){
  740. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  741. if(empty($whlabel_info)){
  742. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  743. exit;
  744. }
  745. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  746. $this->bhsq->save([
  747. 'jm'=>$r['jm'],
  748. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  749. 'features'=>$whlabel_info['features'],
  750. ],$v['id']);
  751. }else{
  752. $this->bhsq->save([
  753. 'jm'=>$whlabel_info['jm'],
  754. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  755. 'features'=>$whlabel_info['features'],
  756. ],$v['id']);
  757. }
  758. }
  759. $this->db->trans_start();
  760. $this->db->where_in('id',$select_id);
  761. $this->db->update('bhsq',[
  762. 'bh_no'=>$bh_no,
  763. 'sq_status'=>4,
  764. 'ccwl_status'=>1,
  765. ]);
  766. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  767. $this->db->where_in('id',$select_id);
  768. $query = $this->db->get('bhsq');
  769. $result = $query->row();
  770. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  771. $time = time();
  772. $this->bhccwl->insert([
  773. 'bh_no'=>$bh_no,
  774. 'status'=>0,
  775. 'num'=>$total_ccwl_num,
  776. 'create_time'=>$time,
  777. 'update_time'=>$time,
  778. ]);
  779. if($this->db->trans_status() === FALSE){
  780. $this->db->trans_rollback();
  781. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  782. exit;
  783. }else{
  784. $this->db->trans_commit();
  785. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  786. exit;
  787. }
  788. }else{
  789. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  790. exit;
  791. }
  792. }
  793. private function getU9Drck($features){
  794. if(stripos($features,'-126-') !== false)
  795. {
  796. $drck = '12003';//进入发条库
  797. }
  798. else if(stripos($features,'-127-') !== false)
  799. {
  800. $drck = '12004';//进入发块库
  801. }
  802. else
  803. {
  804. $drck = '12006';//其它进入完成库
  805. }
  806. return $drck;
  807. }
  808. //仓储物流部的备货单列表
  809. private function _ccwlbhindex(){
  810. if($this->input->method() === 'post'){
  811. $page = $this->input->post('page',true);
  812. $perpage = $this->input->post('perpage',true);
  813. $bh_no = $this->input->post('bh_no',true);
  814. $status = $this->input->post('status',true);
  815. $ktime = $this->input->post('ktime',true);
  816. $jtime = $this->input->post('jtime',true);
  817. $ktime = strtotime($ktime);
  818. $jtime = strtotime($jtime);
  819. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  820. if(!empty($bh_no)){
  821. $where .= " and bh_no = '".$bh_no."' ";
  822. }
  823. if($status > -1){
  824. $where .= " and status = ".$status." ";
  825. }
  826. //数据排序
  827. $order_str = "id desc";
  828. if(empty($page))
  829. {
  830. $start = 0;
  831. $perpage = 1;
  832. }
  833. else
  834. {
  835. $start = ($page - 1)*$perpage;
  836. }
  837. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
  838. if(empty($list)){
  839. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  840. echo json_encode($rows);exit;
  841. }
  842. $status_list = $this->bhccwl->getStatus();
  843. foreach($list as $k=>$v){
  844. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  845. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  846. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  847. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  848. $str = "";
  849. if($v['status'] == 0){
  850. $str .= "<div style='text-align:center;'>";
  851. $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>";
  852. $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>";
  853. $str .= "</div>";
  854. }
  855. $list[$k]['update_time'] = $str;
  856. }
  857. $total = $this->bhccwl->find_count($where);
  858. $pagenum = ceil($total/$perpage);
  859. $over = $total-($start+$perpage);
  860. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  861. echo json_encode($rows);exit;
  862. }else{
  863. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  864. }
  865. }
  866. //仓储物流部备货 在编辑页面添加数据
  867. private function _ccwlbhsavexzbh(){
  868. if($this->input->method() === 'post'){
  869. $data = $this->input->post();
  870. $select_id = $data['select_id'];
  871. $id = $data['id'];
  872. $bh_no = $data['bh_no'];
  873. if(empty($select_id)){
  874. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  875. exit;
  876. }
  877. $info = $this->bhccwl->read($id);
  878. if(empty($info)){
  879. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  880. exit;
  881. }
  882. if($info['bh_no'] != $bh_no){
  883. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  884. exit;
  885. }
  886. $bh_no = $info['bh_no'];
  887. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  888. foreach($list as $k=>$v){
  889. if(empty($v['sku'])){
  890. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  891. exit;
  892. }
  893. if(!empty($v['bh_no'])){
  894. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  895. exit;
  896. }
  897. }
  898. $classid = $this->logic_u9tools->getClass();
  899. $typeclass = $this->logic_u9tools->getTypeClass();
  900. foreach($list as $k=>$v){
  901. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  902. if(empty($whlabel_info)){
  903. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  904. if(empty($whlabel_info)){
  905. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  906. exit;
  907. }
  908. if(empty($v['jm'])){
  909. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  910. $this->bhsq->save([
  911. 'jm'=>$r['jm'],
  912. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  913. 'features'=>$whlabel_info['features'],
  914. ],$v['id']);
  915. }
  916. $list[$k]['jm'] = $r['jm'];
  917. }else{
  918. $this->bhsq->save([
  919. 'jm'=>$whlabel_info['jm'],
  920. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  921. 'features'=>$whlabel_info['features'],
  922. ],$v['id']);
  923. $list[$k]['jm'] = $whlabel_info['jm'];
  924. }
  925. }
  926. $status_list = $this->bhccwl->getStatus();
  927. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  928. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  929. $plat_list = array_column($plat_list,'title','id');
  930. $shop_list = $this->shop->find_all("1=1","id,shopname");
  931. $shop_list = array_column($shop_list,'shopname','id');
  932. foreach($list as $k=>$v){
  933. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  934. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  935. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  936. $list[$k]['bh_no'] = $info['bh_no'];
  937. }
  938. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  939. }else{
  940. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  941. exit;
  942. }
  943. }
  944. private function _ccwlbhedit($arg_array){
  945. if($this->input->method() === 'post'){
  946. $select_id = $this->input->post('arr_id',true);
  947. if(empty($select_id)){
  948. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  949. exit;
  950. }
  951. $id = $this->input->post('id',true);
  952. $info = $this->bhccwl->read($id);
  953. $bh_no = $info['bh_no'];
  954. $this->db->where_in('id',$select_id);
  955. $this->db->update('bhsq',[
  956. 'bh_no'=>$bh_no,
  957. 'sq_status'=>4,
  958. 'ccwl_status'=>1,
  959. ]);
  960. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  961. $this->db->where_in('id',$select_id);
  962. $query = $this->db->get('bhsq');
  963. $result = $query->row();
  964. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  965. $time = time();
  966. $this->bhccwl->save([
  967. 'num'=>$total_ccwl_num,
  968. 'update_time'=>$time,
  969. ],$info['id']);
  970. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  971. }else{
  972. $id = $arg_array[0];
  973. $info = $this->bhccwl->find("id = ".$id);
  974. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  975. $status_list = $this->bhccwl->getStatus();
  976. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  977. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  978. $plat_list = array_column($plat_list,'title','id');
  979. $shop_list = $this->shop->find_all("1=1","id,shopname");
  980. $shop_list = array_column($shop_list,'shopname','id');
  981. foreach($list as $k=>$v){
  982. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  983. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  984. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  985. }
  986. // $this->data['info'] = $info;
  987. $this->data['list'] = $list;
  988. $this->data['info'] = $info;
  989. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  990. }
  991. }
  992. private function _ccwldelitem(){
  993. if($this->input->method() === 'post'){
  994. $data = $this->input->post();
  995. $id = $data['id'];
  996. $bh_no = $data['bh_no'];
  997. $info = $this->bhsq->read($id);
  998. $ccwl_num = $info['ccwl_num'];
  999. if(empty($info)){
  1000. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1001. }
  1002. if(empty($info['bh_no'])){
  1003. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  1004. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1005. }else{
  1006. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1007. }
  1008. }
  1009. if($info['bh_no'] != $bh_no){
  1010. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1011. }
  1012. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  1013. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  1014. $this->db->trans_start();
  1015. $this->bhccwl->save([
  1016. 'num'=>$ccwl_info['num'],
  1017. ],$ccwl_info['id']);
  1018. $this->bhsq->save([
  1019. 'sq_status'=>2,
  1020. 'ccwl_status'=>0,
  1021. 'bh_no'=>''
  1022. ],$id);
  1023. if($this->db->trans_status() === FALSE){
  1024. $this->db->trans_rollback();
  1025. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  1026. }else{
  1027. $this->db->trans_commit();
  1028. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  1029. }
  1030. }else{
  1031. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1032. }
  1033. }
  1034. private function _ccwleditxzbh(){
  1035. if($this->input->method() === 'post'){
  1036. $data = $this->input->post();
  1037. //超过三月没审核的 就不展示了
  1038. $time = time() - 60*24*3600;
  1039. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  1040. if(!empty($data['sqr'])){
  1041. $where .= " and sqr = '".$data['sqr']."' ";
  1042. }
  1043. if(!empty($data['shop_id'])){
  1044. $where .= " and shop_id = ".$data['shop_id']." ";
  1045. }
  1046. if(!empty($data['plat_id'])){
  1047. $where .= " and plat_id = ".$data['plat_id']." ";
  1048. }
  1049. if(!empty($data['sku'])){
  1050. $where .= " and sku = '".$data['sku']."' ";
  1051. }
  1052. $order_str = "id desc";
  1053. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  1054. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1055. $shop_list = array_column($shop_list,'shopname','id');
  1056. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1057. $plat_list = array_column($plat_list,'title','id');
  1058. foreach($list as $k=>$v){
  1059. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1060. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  1061. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  1062. }
  1063. if(empty($list)){
  1064. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  1065. }else{
  1066. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  1067. }
  1068. }else{
  1069. $data = $this->input->get();
  1070. $this->data['id'] = $data['id'];
  1071. $this->data['bh_no'] = $data['bh_no'];
  1072. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  1073. $this->data['plat_list'] = $plat_list;
  1074. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  1075. }
  1076. }
  1077. private function _ccwlbhsave(){
  1078. if($this->input->method() === 'post'){
  1079. $data = $this->input->post();
  1080. $id = $data['id'];
  1081. $val = $data['val'];
  1082. $column = $data['column'];
  1083. $update_arr = [];
  1084. if($column == 'status'){
  1085. $update_arr = [
  1086. 'status'=>(int)$val,
  1087. 'update_time'=>time(),
  1088. 'public_time'=>time(),
  1089. ];
  1090. }else{
  1091. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1092. }
  1093. $r = $this->bhccwl->save($update_arr,$id);
  1094. if($r){
  1095. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  1096. }else{
  1097. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  1098. }
  1099. }else{
  1100. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  1101. }
  1102. }
  1103. //仓库的备货单列表
  1104. private function _ckbhindex(){
  1105. if($this->input->method() === 'post'){
  1106. $page = $this->input->post('page',true);
  1107. $perpage = $this->input->post('perpage',true);
  1108. $bh_no = $this->input->post('bh_no',true);
  1109. $status = $this->input->post('status',true);
  1110. $ktime = $this->input->post('ktime',true);
  1111. $jtime = $this->input->post('jtime',true);
  1112. $ktime = strtotime($ktime);
  1113. $jtime = strtotime($jtime);
  1114. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1115. if(!empty($bh_no)){
  1116. $where .= " and bh_no = '".$bh_no."' ";
  1117. }
  1118. if($status > -1){
  1119. $where .= " and status = ".$status." ";
  1120. }
  1121. //数据排序
  1122. $order_str = "id desc";
  1123. if(empty($page))
  1124. {
  1125. $start = 0;
  1126. $perpage = 1;
  1127. }
  1128. else
  1129. {
  1130. $start = ($page - 1)*$perpage;
  1131. }
  1132. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1133. if(empty($list)){
  1134. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1135. echo json_encode($rows);exit;
  1136. }
  1137. $status_list = $this->bhccwl->getCkStatus();
  1138. foreach($list as $k=>$v){
  1139. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1140. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1141. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1142. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1143. $str = "";
  1144. if($v['ck_status'] == 0){
  1145. $str .= "<div style='text-align:center;'>";
  1146. $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>";
  1147. $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>";
  1148. $str .= "</div>";
  1149. }
  1150. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1151. $str .= "<div style='text-align:center;'>";
  1152. $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>";
  1153. $str .= "</div>";
  1154. }
  1155. if($v['ck_status'] > 2){
  1156. $str .= "<div style='text-align:center;'>";
  1157. $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>";
  1158. $str .= "</div>";
  1159. }
  1160. $list[$k]['update_time'] = $str;
  1161. }
  1162. $total = $this->bhccwl->find_count($where);
  1163. $pagenum = ceil($total/$perpage);
  1164. $over = $total-($start+$perpage);
  1165. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1166. echo json_encode($rows);exit;
  1167. }else{
  1168. $this->_Template('beihuogl_ckbhindex',$this->data);
  1169. }
  1170. }
  1171. private function _ckbhedit($arg_array){
  1172. if($this->input->method() === 'post'){
  1173. $id = $this->input->post('id',true);
  1174. $bh_no = $this->input->post('bh_no',true);
  1175. $info = $this->bhccwl->read($id);
  1176. if(empty($info)){
  1177. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1178. }
  1179. if($info['ck_status'] == 0 && $info['status'] == 1){
  1180. }else{
  1181. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1182. }
  1183. if($info['bh_no'] != $bh_no){
  1184. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1185. }
  1186. $num = 0;
  1187. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1188. foreach($list as $k=>$v){
  1189. $num += $v['ck_num'];
  1190. }
  1191. $r = $this->bhccwl->save([
  1192. 'ck_status'=>1,
  1193. 'ck_num'=>$num,
  1194. 'update_time'=>time(),
  1195. 'ckpublic_time'=>time(),
  1196. ],$id);
  1197. if($r){
  1198. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1199. }else{
  1200. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1201. }
  1202. }else{
  1203. $id = $arg_array[0];
  1204. $info = $this->bhccwl->find("id = ".$id);
  1205. $status_list = $this->bhccwl->getCkStatus();
  1206. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1207. $drck_list = $this->bhccwl->getDrck();
  1208. $this->data['drck_list'] = $drck_list;
  1209. $this->data['drck_json'] = json_encode($drck_list);
  1210. $this->data['info'] = $info;
  1211. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1212. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1213. $shop_list = array_column($shop_list,'shopname','id');
  1214. foreach($list as $k=>$v){
  1215. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1216. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1217. }
  1218. $this->data['list'] = $list;
  1219. $this->_Template('beihuogl_ckbhedit',$this->data);
  1220. }
  1221. }
  1222. private function _makeu9scd($arg_array){
  1223. if($this->input->method() === 'post'){
  1224. $data = $this->input->post(null,true);
  1225. $info = $this->bhccwl->read($data['id']);
  1226. if(empty($info)){
  1227. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1228. }
  1229. if($info['ck_status'] == 1 && $info['status'] == 1){
  1230. }else{
  1231. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1232. exit;
  1233. }
  1234. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1235. $params = [
  1236. 'org_code'=>"120",//组织代码 龙盈工厂
  1237. 'djhlx'=>'2000',//单号类型 备货生产单
  1238. 'scbm_code'=>"12008",//龙盈生产部门
  1239. "time"=>time(),
  1240. 'owner_org_code'=>"120",
  1241. 'title'=>$info['bh_no'],
  1242. 'shipremarks'=>$info['bh_no'],
  1243. ];
  1244. $final_list = [];
  1245. foreach($list as $k=>$v){
  1246. $final_list[] =[
  1247. 'do_id'=>$v['id'],
  1248. 'drck'=>$v['drck'],
  1249. 'jm'=>$v['jm'],
  1250. 'sl'=>$v['ck_num'],
  1251. ];
  1252. }
  1253. $params['list'] = $final_list;
  1254. $token = $this->settingtest->get_yytoken_120();
  1255. $res = $this->apiyyv1->scdCreate($params,$token);
  1256. if(empty($res[0]['Data'])){
  1257. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1258. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1259. }
  1260. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1261. $r_s_list = $res[0]['Data'];
  1262. foreach($list as $k=>$v){
  1263. $list[$k]['u9_data'] = $r_s_list[$k];
  1264. }
  1265. //m_isSucess
  1266. $flag_status = 0;//判断是否有创建失败的
  1267. $u9sc_status = 0;//判断是否有创建成功的
  1268. foreach($list as $k=>$v){
  1269. if($v['u9_data']['m_isSucess']== 1){
  1270. $u9sc_status += 1;
  1271. $this->bhsq->save([
  1272. 'is_u9sc'=>1,
  1273. 'u9sc_no'=>$v['u9_data']['m_code'],
  1274. ],$v['id']);
  1275. }else{
  1276. $flag_status += 0;
  1277. $this->bhsq->save([
  1278. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1279. ],$v['id']);
  1280. }
  1281. }
  1282. $len = count($list);
  1283. //都创建失败了 就直接gg
  1284. if($u9sc_status == 0){
  1285. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1286. }
  1287. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1288. $this->bhccwl->save([
  1289. 'ck_status'=>2,
  1290. ],$info['id']);
  1291. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1292. }
  1293. if($u9sc_status == $len){
  1294. $this->bhccwl->save([
  1295. 'ck_status'=>3,
  1296. ],$info['id']);
  1297. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1298. }
  1299. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1300. }else{
  1301. $id = $arg_array[0];
  1302. $info = $this->bhccwl->read($id);
  1303. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1304. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1305. $shop_list = array_column($shop_list,'shopname','id');
  1306. $drck_list = $this->bhccwl->getDrck();
  1307. $status_list = $this->bhccwl->getCkStatus();
  1308. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1309. foreach($list as $k=>$v){
  1310. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1311. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1312. }
  1313. $this->data['list'] = $list;
  1314. $this->data['info'] = $info;
  1315. $this->_Template('beihuogl_makeu9scd',$this->data);
  1316. }
  1317. }
  1318. private function _ddscscd(){
  1319. if($this->input->method() === 'post'){
  1320. $id = $this->input->post('id',true);
  1321. $bh_no = $this->input->post('bh_no',true);
  1322. $bhsq_info = $this->bhsq->read($id);
  1323. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1324. if(empty($bhccwl_info)){
  1325. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1326. }
  1327. // if($bhccwl_info['ck_status'] != 1){
  1328. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1329. // exit;
  1330. // }
  1331. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1332. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1333. exit;
  1334. }
  1335. if(!empty($bhsq_info['u9sc_no'])){
  1336. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1337. exit;
  1338. }
  1339. $params = [
  1340. 'org_code'=>"120",//组织代码 龙盈工厂
  1341. 'djhlx'=>'2000',//单号类型 备货生产单
  1342. 'scbm_code'=>"12008",//龙盈生产部门
  1343. "time"=>time(),
  1344. 'owner_org_code'=>"120",
  1345. 'title'=>$bhccwl_info['bh_no'],
  1346. 'shipremarks'=>$bhccwl_info['bh_no'],
  1347. ];
  1348. $list[] = [
  1349. 'do_id'=>$bhsq_info['id'],
  1350. 'drck'=>$bhsq_info['drck'],
  1351. 'jm'=>$bhsq_info['jm'],
  1352. 'sl'=>$bhsq_info['ck_num'],
  1353. ];
  1354. $params['list'] = $list;
  1355. $token = $this->settingtest->get_yytoken_120();
  1356. $res = $this->apiyyv1->scdCreate($params,$token);
  1357. if(empty($res[0]['Data'])){
  1358. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1359. }
  1360. if($res[0]['Data'][0]['m_isSucess']== 1){
  1361. $this->bhsq->save([
  1362. 'is_u9sc'=>1,
  1363. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1364. ],$bhsq_info['id']);
  1365. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1366. if(empty($tmp_list)){
  1367. $tmp_status = 3;
  1368. }else{
  1369. $tmp_status = 2;
  1370. }
  1371. $this->bhccwl->save([
  1372. 'ck_status'=>$tmp_status,
  1373. ],$bhccwl_info['id']);
  1374. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1375. }else{
  1376. $this->bhsq->save([
  1377. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1378. ],$bhsq_info['id']);
  1379. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1380. }
  1381. }else{
  1382. exit('No direct script access allowed');
  1383. }
  1384. }
  1385. private function _showckbh($arg_array){
  1386. if($this->input->method() === 'post'){
  1387. exit('No direct script access allowed');
  1388. }
  1389. $id = $arg_array[0];
  1390. $drck_list = $this->bhccwl->getDrck();
  1391. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1392. $shop_list = array_column($shop_list,'shopname','id');
  1393. $info = $this->bhccwl->read($id);
  1394. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1395. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1396. foreach($list as $k=>$v){
  1397. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1398. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1399. }
  1400. $this->data['info'] = $info;
  1401. $this->data['list'] = $list;
  1402. $this->data['list_dcd'] = $list_dcd;
  1403. $this->_Template('beihuogl_showckbh',$this->data);
  1404. }
  1405. //仓库录入调出单
  1406. private function _ckdcd(){
  1407. if($this->input->method() === 'post'){
  1408. $lrdcd = $this->input->post('lrdcd',true);
  1409. if(empty($lrdcd)){
  1410. //列表展示
  1411. $page = $this->input->post('page',true);
  1412. $perpage = $this->input->post('perpage',true);
  1413. $bh_no = $this->input->post('bh_no',true);
  1414. $dcd_no = $this->input->post('dcd_no',true);
  1415. $status = $this->input->post('status',true);
  1416. $ktime = $this->input->post('ktime',true);
  1417. $jtime = $this->input->post('jtime',true);
  1418. $ktime = strtotime($ktime);
  1419. $jtime = strtotime($jtime);
  1420. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1421. if(!empty($bh_no)){
  1422. $where .= " and bh_no = '".$bh_no."' ";
  1423. }
  1424. if($status > -1){
  1425. $where .= " and status = ".$status." ";
  1426. }
  1427. if(!empty($dcd_no)){
  1428. $where .= " and dcd_no = '".$dcd_no."' ";
  1429. }
  1430. //数据排序
  1431. $order_str = "id desc";
  1432. if(empty($page))
  1433. {
  1434. $start = 0;
  1435. $perpage = 1;
  1436. }
  1437. else
  1438. {
  1439. $start = ($page - 1)*$perpage;
  1440. }
  1441. $list = $this->bhdcd->find_all($where,"id,bh_no,dcd_no,drd_no,status,jm,num,kw,create_time,rk_time,is_rk",$order_str,$start,$perpage);
  1442. if(empty($list)){
  1443. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1444. echo json_encode($rows);exit;
  1445. }
  1446. $status_list = $this->bhdcd->getStatus();
  1447. foreach($list as $k=>$v){
  1448. $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>";
  1449. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1450. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1451. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1452. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1453. $str = "";
  1454. if($v['is_rk'] == 0){
  1455. $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='dcdjzrk(this)' data-id='".$v['id']."' data-num='".$v['num']."'>禁止入库</a>";
  1456. }
  1457. if(!empty($v['rk_time'])){
  1458. $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>";
  1459. }
  1460. $list[$k]['rk_time'] = $str;
  1461. unset($list[$k]['is_rk']);
  1462. }
  1463. $total = $this->bhdcd->find_count($where);
  1464. $pagenum = ceil($total/$perpage);
  1465. $over = $total-($start+$perpage);
  1466. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1467. echo json_encode($rows);exit;
  1468. }else{
  1469. if(empty($lrdcd)){
  1470. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1471. }
  1472. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1473. if(!empty($num)){
  1474. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1475. }
  1476. //查询录入执行的调出单
  1477. $token = $this->settingtest->get_yytoken_120();
  1478. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1479. if(empty($res[0]['Data'])){
  1480. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1481. }
  1482. $time = time();
  1483. $final_list = [];
  1484. foreach($res[0]['Data'] as $k=>$v){
  1485. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1486. $tmp_sku = '';
  1487. $tmp_title = '';
  1488. $tmp_features = '';
  1489. $tmp_number='';
  1490. if(!empty($good_info)){
  1491. $tmp_sku = $good_info['sku'];
  1492. $tmp_title = $good_info['title'];
  1493. $tmp_features = $good_info['features'];
  1494. $tmp_number = str_replace("-","", $good_info['features']);
  1495. }
  1496. $final_list[] = [
  1497. 'sku'=>$tmp_sku,
  1498. 'dcd_no'=>$v['docno'],
  1499. 'jm'=>$v['iteminfo_itemcode'],
  1500. 'zh'=>$v['iteminfo_itemname'],
  1501. 'num'=>$v['costuomqty'],
  1502. 'real_num'=>$v['costuomqty'],
  1503. 'bh_no'=>$v['erp_no'],
  1504. 'create_time'=>$time,
  1505. 'title'=>$tmp_title,
  1506. 'features'=>$tmp_features,
  1507. 'number'=>$tmp_number,
  1508. ];
  1509. }
  1510. $r =$this->db->insert_batch('bhdcd',$final_list);
  1511. if($r){
  1512. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1513. }else{
  1514. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1515. }
  1516. exit;
  1517. }
  1518. }else{
  1519. $status_list = $this->bhdcd->getStatus();
  1520. $this->data['status_list'] = $status_list;
  1521. $this->_Template('beihuogl_ckdcd',$this->data);
  1522. }
  1523. }
  1524. private function _checkdcdsku($arg_array){
  1525. $dcd_no = $arg_array[0];
  1526. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' ");
  1527. echo "<pre>";
  1528. foreach($list as $k=>$v){
  1529. if(empty($v['sku'])){
  1530. $goods_info = $this->goods->find("jm = '".$v['jm']."' ");
  1531. if(!empty($goods_info)){
  1532. $update_arr = [
  1533. 'sku'=>$goods_info['sku'],
  1534. 'title'=>$goods_info['title'],
  1535. 'number'=>trim(str_replace("-","",$goods_info['features'])),
  1536. 'features'=>$goods_info['features'],
  1537. ];
  1538. var_dump($update_arr);
  1539. // $this->bhdcd->save([
  1540. // ],$v['id']);
  1541. }else{
  1542. var_dump($v['jm'].'的sku不存在');
  1543. }
  1544. }
  1545. }
  1546. }
  1547. private function _ckbherprk($arg_array){
  1548. if($this->input->method() === 'post'){
  1549. $data = $this->input->post(null,true);
  1550. $dcd_no = $data['dcd_no'];
  1551. $drd_no = $data['drd_no'];
  1552. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1553. $whlabel_arr = [];
  1554. $time = time();
  1555. $err_list= [];
  1556. foreach($list as $k=>$v){
  1557. if(empty($v['sku'])){
  1558. $err_list[] = $v['jm']."不存在";
  1559. continue;
  1560. }
  1561. for($i=0;$i<$v['num'];$i++){
  1562. $whlabel_arr[] = [
  1563. 'sku'=>$v['sku'],
  1564. 'number'=>$v['number'],
  1565. 'features'=>$v['features'],
  1566. 'title'=>$v['title'],
  1567. 'zh'=>$v['zh'],
  1568. 'warehouse'=>'13',
  1569. 'enter'=>$time,
  1570. 'state'=>0,
  1571. 'retreatwarehouse'=>'13',
  1572. 'time'=>$time,
  1573. 'details'=>$v['kw'],
  1574. 'bs'=>1,
  1575. 'rktype'=>9,
  1576. ];
  1577. }
  1578. }
  1579. if(!empty($err_list)){
  1580. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1581. }
  1582. $this->db->trans_start();
  1583. $this->db->insert_batch('whlabel',$whlabel_arr);
  1584. $this->db->where('dcd_no',$dcd_no);
  1585. //$this->db->where('drd_no',$drd_no);
  1586. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1587. if($this->db->trans_status() === FALSE){
  1588. $this->db->trans_rollback();
  1589. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1590. }else{
  1591. $this->db->trans_commit();
  1592. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1593. }
  1594. }else{
  1595. $dcd_no = $arg_array[0];
  1596. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1597. $jm_list = array_column($list,'jm');
  1598. $status_list = $this->bhdcd->getStatus();
  1599. $in_where = "( ";
  1600. foreach($jm_list as $k=>$v){
  1601. $in_where .= "'".$v."',";
  1602. }
  1603. $in_where = rtrim($in_where,",");
  1604. $in_where .= " )";
  1605. foreach($list as $k=>$v){
  1606. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1607. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1608. if(!empty($v['kw'])){
  1609. $list[$k]['kw'] = $v['kw'];
  1610. }else{
  1611. if(!empty($list[$k]['sku'])){
  1612. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1613. if(!empty($whlabel_info)){
  1614. if(!empty($whlabel_info['details'])){
  1615. $list[$k]['kw'] = $whlabel_info['details'];
  1616. $this->bhdcd->save([
  1617. 'kw'=>$whlabel_info['details'],
  1618. ],$v['id']);
  1619. }else{
  1620. $list[$k]['kw'] = "";
  1621. }
  1622. }else{
  1623. $list[$k]['kw'] = "";
  1624. }
  1625. }else{
  1626. $list[$k]['kw'] = "";
  1627. }
  1628. }
  1629. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1630. }
  1631. $this->data['list'] = $list;
  1632. $this->_Template('beihuogl_ckbherprk',$this->data);
  1633. }
  1634. }
  1635. private function _bhdcdsave(){
  1636. if($this->input->method() === 'post'){
  1637. $id = $this->input->post('id',true);
  1638. $val = $this->input->post('val',true);
  1639. $column = $this->input->post('column',true);
  1640. $info = $this->bhdcd->read($id);
  1641. $update_arr = [];
  1642. if($column == 'real_num'){
  1643. if($val > $info['num']){
  1644. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1645. }
  1646. $update_arr = [
  1647. 'real_num'=>(int)$val,
  1648. ];
  1649. }elseif($column == 'kw'){
  1650. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1651. if(!empty($winfo)){
  1652. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1653. if(empty($winfo)){
  1654. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1655. }
  1656. }
  1657. $update_arr = [
  1658. 'kw'=>trim($val),
  1659. ];
  1660. }else{
  1661. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1662. }
  1663. $r = $this->bhdcd->save($update_arr,$id);
  1664. if($r){
  1665. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1666. }else{
  1667. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1668. }
  1669. }else{
  1670. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1671. }
  1672. }
  1673. private function _u9scdexcel($arg_array){
  1674. $id = $arg_array[0];
  1675. $info = $this->bhccwl->read($id);
  1676. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1677. //生成excel
  1678. $filename = $info['bh_no']."备货生产单.xls";
  1679. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1680. <head>
  1681. <!--[if gte mso 9]><xml>
  1682. <x:ExcelWorkbook>
  1683. <x:ExcelWorksheets>
  1684. <x:ExcelWorksheet>
  1685. <x:Name>EXCEL</x:Name>
  1686. <x:WorksheetOptions>
  1687. <x:Print>
  1688. <x:ValidPrinterInfo />
  1689. </x:Print>
  1690. </x:WorksheetOptions>
  1691. </x:ExcelWorksheet>
  1692. </x:ExcelWorksheets>
  1693. </x:ExcelWorkbook>
  1694. </xml>
  1695. <![endif]-->
  1696. </head><body>";
  1697. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1698. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td></tr>";
  1699. foreach ($list as $key=>$value)
  1700. {
  1701. $str .= "<tr>";
  1702. $str .= "<td>". $value['bh_no']. "</td>";
  1703. $str .= "<td>". $value['title']. "</td>";
  1704. $str .= "<td>". $value['jm']. "</td>";
  1705. $str .= "<td>". $value['ck_num']. "</td>";
  1706. $str .= "<td>". $value['u9sc_no']. "</td>";
  1707. $str .= "</tr>";
  1708. }
  1709. $str .= "</table></body></html>";
  1710. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1711. header( "Content-type: application/octet-stream" );
  1712. header( "Content-Disposition: attachment; filename=".$filename );
  1713. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1714. header( "Pragma: no-cache" );
  1715. header( "Expires: 0" );
  1716. exit($str);
  1717. }
  1718. //打印标签
  1719. private function _printlabel(){
  1720. if($this->input->method() === 'post'){
  1721. $id = $this->input->post('id',true);
  1722. $xbqnum = $this->input->post('num',true);
  1723. $info = $this->bhdcd->read($id);
  1724. if(empty($info)){
  1725. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1726. }
  1727. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1728. $featurespp = explode('-', trim($featurespp, '-'));
  1729. if (isset($featurespp[5])) {
  1730. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1731. } else {
  1732. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1733. }
  1734. $label = '';
  1735. $cpid = $this->whlabellabel->find_count();
  1736. $cpid = $cpid + 1;
  1737. $time = time();
  1738. $label = time().rand(10,99);
  1739. $label = substr($label,1);
  1740. $insert_arr = [
  1741. 'purchase'=>1,
  1742. 'shop'=>'',
  1743. 'sku'=>$info['sku'],
  1744. 'number'=>$info['number'],
  1745. 'features'=>$info['features'],
  1746. 'featurespp'=>$tmp_featurespp,
  1747. 'title'=>$info['title'],
  1748. 'label'=>$label,
  1749. 'warehouse'=>13,
  1750. 'time'=>$time,
  1751. 'details'=>$info['kw'],
  1752. 'cpid'=>$cpid,
  1753. 'jm'=>$info['jm'],
  1754. 'cpbz'=>''
  1755. ];
  1756. $this->db->trans_begin();
  1757. $this->whlabellabel->insert($insert_arr);
  1758. if ($this->db->trans_status() === TRUE) {
  1759. $this->db->trans_commit();
  1760. } else {
  1761. $this->db->trans_rollback();
  1762. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  1763. exit;
  1764. }
  1765. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  1766. $details = ' <b style="font-size: 18px;">'."许昌仓</b> ".$details;
  1767. $purchase = "龙盈工厂";
  1768. 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));
  1769. exit; //特殊仓目前不需要仓库选项
  1770. }else{
  1771. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1772. }
  1773. }
  1774. private function _dcdjzrk(){
  1775. if($this->input->method() === 'post'){
  1776. $id = $this->input->post('id',true);
  1777. $info = $this->bhdcd->read($id);
  1778. if($info['is_rk'] == 0){
  1779. $this->bhdcd->save(['is_rk'=>1],$id);
  1780. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1781. }else{
  1782. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1783. }
  1784. }else{
  1785. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1786. }
  1787. }
  1788. private function _dyapplyyjsh(){
  1789. if($this->input->method() === 'post'){
  1790. $arr_id = $this->input->post('arr_id',true);
  1791. $this->db->where_in('id',$arr_id);
  1792. $this->db->where('sq_status',1);
  1793. $this->db->update('bhsq',['sq_status'=>2]);
  1794. echo json_encode(['success'=>true,'msg'=>'审核通过']);exit;
  1795. }else{
  1796. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1797. }
  1798. }
  1799. private function _ckexcel($arg_array){
  1800. $id = $arg_array[0];
  1801. $info = $this->bhccwl->read($id);
  1802. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1803. //生成excel
  1804. $filename = $info['bh_no']."备货生产单.xls";
  1805. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1806. <head>
  1807. <!--[if gte mso 9]><xml>
  1808. <x:ExcelWorkbook>
  1809. <x:ExcelWorksheets>
  1810. <x:ExcelWorksheet>
  1811. <x:Name>EXCEL</x:Name>
  1812. <x:WorksheetOptions>
  1813. <x:Print>
  1814. <x:ValidPrinterInfo />
  1815. </x:Print>
  1816. </x:WorksheetOptions>
  1817. </x:ExcelWorksheet>
  1818. </x:ExcelWorksheets>
  1819. </x:ExcelWorkbook>
  1820. </xml>
  1821. <![endif]-->
  1822. </head><body>";
  1823. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1824. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td></tr>";
  1825. foreach ($list as $key=>$value)
  1826. {
  1827. $str .= "<tr>";
  1828. $str .= "<td>". $value['bh_no']. "</td>";
  1829. $str .= "<td>". $value['title']. "</td>";
  1830. $str .= "<td>". $value['jm']. "</td>";
  1831. $str .= "<td>". $value['ck_num']. "</td>";
  1832. $str .= "</tr>";
  1833. }
  1834. $str .= "</table></body></html>";
  1835. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1836. header( "Content-type: application/octet-stream" );
  1837. header( "Content-Disposition: attachment; filename=".$filename );
  1838. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1839. header( "Pragma: no-cache" );
  1840. header( "Expires: 0" );
  1841. exit($str);
  1842. }
  1843. }