Beihuogl.php 72 KB

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