Beihuogl.php 74 KB

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