Beihuogl.php 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  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,erp_check",$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. if($v['erp_check'] == 1){
  513. $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>";
  514. }else{
  515. $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  516. }
  517. $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>";
  518. $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>";
  519. unset($list[$k]['erp_check']);
  520. }
  521. $total = $this->bhsq->find_count($where);
  522. $pagenum = ceil($total/$perpage);
  523. $over = $total-($start+$perpage);
  524. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  525. echo json_encode($rows);exit;
  526. }else{
  527. $user = $this->user->get_api($_SESSION['api']);
  528. $usersp = explode('|',trim($user['shop'],'|'));
  529. $this->data['usersp'] = implode(",",$usersp);
  530. $vip_id = 0;
  531. if(in_array($user['id'],[10,28])){
  532. $vip_id = 1;
  533. }
  534. $this->data['vip_id'] = $vip_id;
  535. $this->_Template('beihuogl_ccwlshlist',$this->data);
  536. }
  537. }
  538. //一键校验选中SKU
  539. private function _ccwlskucheck(){
  540. if($this->input->method() === 'post'){
  541. $data = $this->input->post();
  542. if(empty($data['arr_id'])){
  543. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  544. exit;
  545. }
  546. $list = $this->bhsq->find_all('id in ('.implode(',',$data['arr_id']).')');
  547. $error_list = [];
  548. $success_ids = [];
  549. $errors_ids = [];
  550. foreach($list as $k=>$v){
  551. if(empty($v['sku'])){
  552. $error_list[] = [
  553. 'msg'=>$v['value'].'请录入SKU',
  554. ];
  555. $errors_ids[] = $v['id'];
  556. continue;
  557. }
  558. $num = $this->goods->find_count("sku = '".$v['sku']."'");
  559. if(!empty($num)){
  560. $success_ids[] = $v['id'];
  561. continue;
  562. }
  563. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  564. if(empty($whlabel_info)){
  565. $error_list[] = [
  566. 'msg'=>$v['sku'].'未在进销存浏览那找到对应信息',
  567. ];
  568. $errors_ids[] = $v['id'];
  569. }
  570. }
  571. $this->db->where_in('id', $errors_ids);
  572. $this->db->update('bhsq', ['erp_check'=>1]);
  573. $this->db->where_in('id', $success_ids);
  574. $this->db->update('bhsq', ['erp_check'=>0]);
  575. if(empty($error_list)){
  576. echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
  577. exit;
  578. }else{
  579. echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
  580. exit;
  581. }
  582. }else{
  583. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  584. exit;
  585. }
  586. }
  587. //仓储物流合成备货单
  588. private function _ccwlbhmake(){
  589. if($this->input->method() === 'post'){
  590. $data = $this->input->post();
  591. if(empty($data['arr_id'])){
  592. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  593. exit;
  594. }
  595. $bh_no = $data['bh_no'];
  596. $select_id = $data['arr_id'];
  597. if(empty($select_id)){
  598. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  599. exit;
  600. }
  601. if(empty($bh_no)){
  602. $tmp_time = strtotime(date("Y-m-d"),time());
  603. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  604. $num = $num+1;
  605. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  606. $bh_no = "BH-".date("ymd")."-".$num;
  607. }else{
  608. $info = $this->bhccwl->find("bh_no = '".$bh_no."'");
  609. if(!empty($info)){
  610. echo json_encode(['success'=>false,'msg'=>'生成的备货单编号已经存在']);
  611. exit;
  612. }
  613. }
  614. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  615. foreach($list as $k=>$v){
  616. if(empty($v['sku'])){
  617. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  618. exit;
  619. }
  620. }
  621. $classid = $this->logic_u9tools->getClass();
  622. $typeclass = $this->logic_u9tools->getTypeClass();
  623. foreach($list as $k=>$v){
  624. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  625. if(empty($whlabel_info)){
  626. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  627. if(empty($whlabel_info)){
  628. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  629. exit;
  630. }
  631. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  632. $this->bhsq->save([
  633. 'jm'=>$r['jm'],
  634. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  635. 'features'=>$whlabel_info['features'],
  636. ],$v['id']);
  637. }else{
  638. $this->bhsq->save([
  639. 'jm'=>$whlabel_info['jm'],
  640. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  641. 'features'=>$whlabel_info['features'],
  642. ],$v['id']);
  643. }
  644. }
  645. $this->db->trans_start();
  646. $this->db->where_in('id',$select_id);
  647. $this->db->update('bhsq',[
  648. 'bh_no'=>$bh_no,
  649. 'sq_status'=>4,
  650. 'ccwl_status'=>1,
  651. ]);
  652. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  653. $this->db->where_in('id',$select_id);
  654. $query = $this->db->get('bhsq');
  655. $result = $query->row();
  656. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  657. $time = time();
  658. $this->bhccwl->insert([
  659. 'bh_no'=>$bh_no,
  660. 'status'=>0,
  661. 'num'=>$total_ccwl_num,
  662. 'create_time'=>$time,
  663. 'update_time'=>$time,
  664. ]);
  665. if($this->db->trans_status() === FALSE){
  666. $this->db->trans_rollback();
  667. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  668. exit;
  669. }else{
  670. $this->db->trans_commit();
  671. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  672. exit;
  673. }
  674. }else{
  675. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  676. exit;
  677. }
  678. }
  679. private function getU9Drck($features){
  680. if(stripos($features,'-126-') !== false)
  681. {
  682. $drck = '12003';//进入发条库
  683. }
  684. else if(stripos($features,'-127-') !== false)
  685. {
  686. $drck = '12004';//进入发块库
  687. }
  688. else
  689. {
  690. $drck = '12006';//其它进入完成库
  691. }
  692. return $drck;
  693. }
  694. //仓储物流部的备货单列表
  695. private function _ccwlbhindex(){
  696. if($this->input->method() === 'post'){
  697. $page = $this->input->post('page',true);
  698. $perpage = $this->input->post('perpage',true);
  699. $bh_no = $this->input->post('bh_no',true);
  700. $status = $this->input->post('status',true);
  701. $ktime = $this->input->post('ktime',true);
  702. $jtime = $this->input->post('jtime',true);
  703. $ktime = strtotime($ktime);
  704. $jtime = strtotime($jtime);
  705. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  706. if(!empty($bh_no)){
  707. $where .= " and bh_no = '".$bh_no."' ";
  708. }
  709. if($status > -1){
  710. $where .= " and status = ".$status." ";
  711. }
  712. //数据排序
  713. $order_str = "id desc";
  714. if(empty($page))
  715. {
  716. $start = 0;
  717. $perpage = 1;
  718. }
  719. else
  720. {
  721. $start = ($page - 1)*$perpage;
  722. }
  723. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
  724. if(empty($list)){
  725. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  726. echo json_encode($rows);exit;
  727. }
  728. $status_list = $this->bhccwl->getStatus();
  729. foreach($list as $k=>$v){
  730. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  731. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  732. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  733. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  734. $str = "";
  735. if($v['status'] == 0){
  736. $str .= "<div style='text-align:center;'>";
  737. $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>";
  738. $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>";
  739. $str .= "</div>";
  740. }
  741. $list[$k]['update_time'] = $str;
  742. }
  743. $total = $this->bhccwl->find_count($where);
  744. $pagenum = ceil($total/$perpage);
  745. $over = $total-($start+$perpage);
  746. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  747. echo json_encode($rows);exit;
  748. }else{
  749. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  750. }
  751. }
  752. //仓储物流部备货 在编辑页面添加数据
  753. private function _ccwlbhsavexzbh(){
  754. if($this->input->method() === 'post'){
  755. $data = $this->input->post();
  756. $select_id = $data['select_id'];
  757. $id = $data['id'];
  758. $bh_no = $data['bh_no'];
  759. if(empty($select_id)){
  760. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  761. exit;
  762. }
  763. $info = $this->bhccwl->read($id);
  764. if(empty($info)){
  765. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  766. exit;
  767. }
  768. if($info['bh_no'] != $bh_no){
  769. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  770. exit;
  771. }
  772. $bh_no = $info['bh_no'];
  773. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  774. foreach($list as $k=>$v){
  775. if(empty($v['sku'])){
  776. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  777. exit;
  778. }
  779. if(!empty($v['bh_no'])){
  780. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  781. exit;
  782. }
  783. }
  784. $classid = $this->logic_u9tools->getClass();
  785. $typeclass = $this->logic_u9tools->getTypeClass();
  786. foreach($list as $k=>$v){
  787. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  788. if(empty($whlabel_info)){
  789. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  790. if(empty($whlabel_info)){
  791. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  792. exit;
  793. }
  794. if(empty($v['jm'])){
  795. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  796. $this->bhsq->save([
  797. 'jm'=>$r['jm'],
  798. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  799. 'features'=>$whlabel_info['features'],
  800. ],$v['id']);
  801. }
  802. $list[$k]['jm'] = $r['jm'];
  803. }else{
  804. $this->bhsq->save([
  805. 'jm'=>$whlabel_info['jm'],
  806. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  807. 'features'=>$whlabel_info['features'],
  808. ],$v['id']);
  809. $list[$k]['jm'] = $whlabel_info['jm'];
  810. }
  811. }
  812. $status_list = $this->bhccwl->getStatus();
  813. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  814. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  815. $plat_list = array_column($plat_list,'title','id');
  816. $shop_list = $this->shop->find_all("1=1","id,shopname");
  817. $shop_list = array_column($shop_list,'shopname','id');
  818. foreach($list as $k=>$v){
  819. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  820. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  821. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  822. $list[$k]['bh_no'] = $info['bh_no'];
  823. }
  824. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  825. }else{
  826. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  827. exit;
  828. }
  829. }
  830. private function _ccwlbhedit($arg_array){
  831. if($this->input->method() === 'post'){
  832. $select_id = $this->input->post('arr_id',true);
  833. if(empty($select_id)){
  834. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  835. exit;
  836. }
  837. $id = $this->input->post('id',true);
  838. $info = $this->bhccwl->read($id);
  839. $bh_no = $info['bh_no'];
  840. $this->db->where_in('id',$select_id);
  841. $this->db->update('bhsq',[
  842. 'bh_no'=>$bh_no,
  843. 'sq_status'=>4,
  844. 'ccwl_status'=>1,
  845. ]);
  846. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  847. $this->db->where_in('id',$select_id);
  848. $query = $this->db->get('bhsq');
  849. $result = $query->row();
  850. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  851. $time = time();
  852. $this->bhccwl->save([
  853. 'num'=>$total_ccwl_num,
  854. 'update_time'=>$time,
  855. ],$info['id']);
  856. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  857. }else{
  858. $id = $arg_array[0];
  859. $info = $this->bhccwl->find("id = ".$id);
  860. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  861. $status_list = $this->bhccwl->getStatus();
  862. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  863. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  864. $plat_list = array_column($plat_list,'title','id');
  865. $shop_list = $this->shop->find_all("1=1","id,shopname");
  866. $shop_list = array_column($shop_list,'shopname','id');
  867. foreach($list as $k=>$v){
  868. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  869. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  870. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  871. }
  872. // $this->data['info'] = $info;
  873. $this->data['list'] = $list;
  874. $this->data['info'] = $info;
  875. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  876. }
  877. }
  878. private function _ccwldelitem(){
  879. if($this->input->method() === 'post'){
  880. $data = $this->input->post();
  881. $id = $data['id'];
  882. $bh_no = $data['bh_no'];
  883. $info = $this->bhsq->read($id);
  884. $ccwl_num = $info['ccwl_num'];
  885. if(empty($info)){
  886. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  887. }
  888. if(empty($info['bh_no'])){
  889. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  890. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  891. }else{
  892. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  893. }
  894. }
  895. if($info['bh_no'] != $bh_no){
  896. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  897. }
  898. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  899. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  900. $this->db->trans_start();
  901. $this->bhccwl->save([
  902. 'num'=>$ccwl_info['num'],
  903. ],$ccwl_info['id']);
  904. $this->bhsq->save([
  905. 'sq_status'=>2,
  906. 'ccwl_status'=>0,
  907. 'bh_no'=>''
  908. ],$id);
  909. if($this->db->trans_status() === FALSE){
  910. $this->db->trans_rollback();
  911. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  912. }else{
  913. $this->db->trans_commit();
  914. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  915. }
  916. }else{
  917. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  918. }
  919. }
  920. private function _ccwleditxzbh(){
  921. if($this->input->method() === 'post'){
  922. $data = $this->input->post();
  923. //超过三月没审核的 就不展示了
  924. $time = time() - 60*24*3600;
  925. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  926. if(!empty($data['sqr'])){
  927. $where .= " and sqr = '".$data['sqr']."' ";
  928. }
  929. if(!empty($data['shop_id'])){
  930. $where .= " and shop_id = ".$data['shop_id']." ";
  931. }
  932. if(!empty($data['plat_id'])){
  933. $where .= " and plat_id = ".$data['plat_id']." ";
  934. }
  935. if(!empty($data['sku'])){
  936. $where .= " and sku = '".$data['sku']."' ";
  937. }
  938. $order_str = "id desc";
  939. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  940. $shop_list = $this->shop->find_all("1=1","id,shopname");
  941. $shop_list = array_column($shop_list,'shopname','id');
  942. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  943. $plat_list = array_column($plat_list,'title','id');
  944. foreach($list as $k=>$v){
  945. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  946. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  947. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  948. }
  949. if(empty($list)){
  950. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  951. }else{
  952. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  953. }
  954. }else{
  955. $data = $this->input->get();
  956. $this->data['id'] = $data['id'];
  957. $this->data['bh_no'] = $data['bh_no'];
  958. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  959. $this->data['plat_list'] = $plat_list;
  960. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  961. }
  962. }
  963. private function _ccwlbhsave(){
  964. if($this->input->method() === 'post'){
  965. $data = $this->input->post();
  966. $id = $data['id'];
  967. $val = $data['val'];
  968. $column = $data['column'];
  969. $update_arr = [];
  970. if($column == 'status'){
  971. $update_arr = [
  972. 'status'=>(int)$val,
  973. 'update_time'=>time(),
  974. 'public_time'=>time(),
  975. ];
  976. }else{
  977. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  978. }
  979. $r = $this->bhccwl->save($update_arr,$id);
  980. if($r){
  981. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  982. }else{
  983. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  984. }
  985. }else{
  986. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  987. }
  988. }
  989. //仓库的备货单列表
  990. private function _ckbhindex(){
  991. if($this->input->method() === 'post'){
  992. $page = $this->input->post('page',true);
  993. $perpage = $this->input->post('perpage',true);
  994. $bh_no = $this->input->post('bh_no',true);
  995. $status = $this->input->post('status',true);
  996. $ktime = $this->input->post('ktime',true);
  997. $jtime = $this->input->post('jtime',true);
  998. $ktime = strtotime($ktime);
  999. $jtime = strtotime($jtime);
  1000. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  1001. if(!empty($bh_no)){
  1002. $where .= " and bh_no = '".$bh_no."' ";
  1003. }
  1004. if($status > -1){
  1005. $where .= " and status = ".$status." ";
  1006. }
  1007. //数据排序
  1008. $order_str = "id desc";
  1009. if(empty($page))
  1010. {
  1011. $start = 0;
  1012. $perpage = 1;
  1013. }
  1014. else
  1015. {
  1016. $start = ($page - 1)*$perpage;
  1017. }
  1018. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  1019. if(empty($list)){
  1020. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1021. echo json_encode($rows);exit;
  1022. }
  1023. $status_list = $this->bhccwl->getCkStatus();
  1024. foreach($list as $k=>$v){
  1025. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  1026. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  1027. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  1028. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  1029. $str = "";
  1030. if($v['ck_status'] == 0){
  1031. $str .= "<div style='text-align:center;'>";
  1032. $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>";
  1033. // $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>";
  1034. $str .= "</div>";
  1035. }
  1036. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  1037. $str .= "<div style='text-align:center;'>";
  1038. $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>";
  1039. $str .= "</div>";
  1040. }
  1041. if($v['ck_status'] > 2){
  1042. $str .= "<div style='text-align:center;'>";
  1043. $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>";
  1044. $str .= "</div>";
  1045. }
  1046. $list[$k]['update_time'] = $str;
  1047. }
  1048. $total = $this->bhccwl->find_count($where);
  1049. $pagenum = ceil($total/$perpage);
  1050. $over = $total-($start+$perpage);
  1051. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1052. echo json_encode($rows);exit;
  1053. }else{
  1054. $this->_Template('beihuogl_ckbhindex',$this->data);
  1055. }
  1056. }
  1057. private function _ckbhedit($arg_array){
  1058. if($this->input->method() === 'post'){
  1059. $id = $this->input->post('id',true);
  1060. $bh_no = $this->input->post('bh_no',true);
  1061. $info = $this->bhccwl->read($id);
  1062. if(empty($info)){
  1063. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1064. }
  1065. if($info['ck_status'] == 0 && $info['status'] == 1){
  1066. }else{
  1067. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  1068. }
  1069. if($info['bh_no'] != $bh_no){
  1070. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  1071. }
  1072. $num = 0;
  1073. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1074. foreach($list as $k=>$v){
  1075. $num += $v['ck_num'];
  1076. }
  1077. $r = $this->bhccwl->save([
  1078. 'ck_status'=>1,
  1079. 'ck_num'=>$num,
  1080. 'update_time'=>time(),
  1081. 'ckpublic_time'=>time(),
  1082. ],$id);
  1083. if($r){
  1084. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  1085. }else{
  1086. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  1087. }
  1088. }else{
  1089. $id = $arg_array[0];
  1090. $info = $this->bhccwl->find("id = ".$id);
  1091. $status_list = $this->bhccwl->getCkStatus();
  1092. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1093. $drck_list = $this->bhccwl->getDrck();
  1094. $this->data['drck_list'] = $drck_list;
  1095. $this->data['drck_json'] = json_encode($drck_list);
  1096. $this->data['info'] = $info;
  1097. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  1098. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1099. $shop_list = array_column($shop_list,'shopname','id');
  1100. foreach($list as $k=>$v){
  1101. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1102. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1103. }
  1104. $this->data['list'] = $list;
  1105. $this->_Template('beihuogl_ckbhedit',$this->data);
  1106. }
  1107. }
  1108. private function _makeu9scd($arg_array){
  1109. if($this->input->method() === 'post'){
  1110. $data = $this->input->post(null,true);
  1111. $info = $this->bhccwl->read($data['id']);
  1112. if(empty($info)){
  1113. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1114. }
  1115. if($info['ck_status'] == 1 && $info['status'] == 1){
  1116. }else{
  1117. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1118. exit;
  1119. }
  1120. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  1121. $params = [
  1122. 'org_code'=>"120",//组织代码 龙盈工厂
  1123. 'djhlx'=>'2000',//单号类型 备货生产单
  1124. 'scbm_code'=>"12008",//龙盈生产部门
  1125. "time"=>time(),
  1126. 'owner_org_code'=>"120",
  1127. 'title'=>$info['bh_no'],
  1128. 'shipremarks'=>$info['bh_no'],
  1129. ];
  1130. $final_list = [];
  1131. foreach($list as $k=>$v){
  1132. $final_list[] =[
  1133. 'do_id'=>$v['id'],
  1134. 'drck'=>$v['drck'],
  1135. 'jm'=>$v['jm'],
  1136. 'sl'=>$v['ck_num'],
  1137. ];
  1138. }
  1139. $params['list'] = $final_list;
  1140. $token = $this->settingtest->get_yytoken_120();
  1141. $res = $this->apiyyv1->scdCreate($params,$token);
  1142. if(empty($res[0]['Data'])){
  1143. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1144. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1145. }
  1146. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1147. $r_s_list = $res[0]['Data'];
  1148. foreach($list as $k=>$v){
  1149. $list[$k]['u9_data'] = $r_s_list[$k];
  1150. }
  1151. //m_isSucess
  1152. $flag_status = 0;//判断是否有创建失败的
  1153. $u9sc_status = 0;//判断是否有创建成功的
  1154. foreach($list as $k=>$v){
  1155. if($v['u9_data']['m_isSucess']== 1){
  1156. $u9sc_status += 1;
  1157. $this->bhsq->save([
  1158. 'is_u9sc'=>1,
  1159. 'u9sc_no'=>$v['u9_data']['m_code'],
  1160. ],$v['id']);
  1161. }else{
  1162. $flag_status += 0;
  1163. $this->bhsq->save([
  1164. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1165. ],$v['id']);
  1166. }
  1167. }
  1168. $len = count($list);
  1169. //都创建失败了 就直接gg
  1170. if($u9sc_status == 0){
  1171. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1172. }
  1173. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1174. $this->bhccwl->save([
  1175. 'ck_status'=>2,
  1176. ],$info['id']);
  1177. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1178. }
  1179. if($u9sc_status == $len){
  1180. $this->bhccwl->save([
  1181. 'ck_status'=>3,
  1182. ],$info['id']);
  1183. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1184. }
  1185. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1186. }else{
  1187. $id = $arg_array[0];
  1188. $info = $this->bhccwl->read($id);
  1189. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1190. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1191. $shop_list = array_column($shop_list,'shopname','id');
  1192. $drck_list = $this->bhccwl->getDrck();
  1193. $status_list = $this->bhccwl->getCkStatus();
  1194. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1195. foreach($list as $k=>$v){
  1196. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1197. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1198. }
  1199. $this->data['list'] = $list;
  1200. $this->data['info'] = $info;
  1201. $this->_Template('beihuogl_makeu9scd',$this->data);
  1202. }
  1203. }
  1204. private function _ddscscd(){
  1205. if($this->input->method() === 'post'){
  1206. $id = $this->input->post('id',true);
  1207. $bh_no = $this->input->post('bh_no',true);
  1208. $bhsq_info = $this->bhsq->read($id);
  1209. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1210. if(empty($bhccwl_info)){
  1211. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1212. }
  1213. // if($bhccwl_info['ck_status'] != 1){
  1214. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1215. // exit;
  1216. // }
  1217. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1218. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1219. exit;
  1220. }
  1221. if(!empty($bhsq_info['u9sc_no'])){
  1222. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1223. exit;
  1224. }
  1225. $params = [
  1226. 'org_code'=>"120",//组织代码 龙盈工厂
  1227. 'djhlx'=>'2000',//单号类型 备货生产单
  1228. 'scbm_code'=>"12008",//龙盈生产部门
  1229. "time"=>time(),
  1230. 'owner_org_code'=>"120",
  1231. 'title'=>$bhccwl_info['bh_no'],
  1232. 'shipremarks'=>$bhccwl_info['bh_no'],
  1233. ];
  1234. $list[] = [
  1235. 'do_id'=>$bhsq_info['id'],
  1236. 'drck'=>$bhsq_info['drck'],
  1237. 'jm'=>$bhsq_info['jm'],
  1238. 'sl'=>$bhsq_info['ck_num'],
  1239. ];
  1240. $params['list'] = $list;
  1241. $token = $this->settingtest->get_yytoken_120();
  1242. $res = $this->apiyyv1->scdCreate($params,$token);
  1243. if(empty($res[0]['Data'])){
  1244. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1245. }
  1246. if($res[0]['Data'][0]['m_isSucess']== 1){
  1247. $this->bhsq->save([
  1248. 'is_u9sc'=>1,
  1249. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1250. ],$bhsq_info['id']);
  1251. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1252. if(empty($tmp_list)){
  1253. $tmp_status = 3;
  1254. }else{
  1255. $tmp_status = 2;
  1256. }
  1257. $this->bhccwl->save([
  1258. 'ck_status'=>$tmp_status,
  1259. ],$bhccwl_info['id']);
  1260. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1261. }else{
  1262. $this->bhsq->save([
  1263. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1264. ],$bhsq_info['id']);
  1265. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1266. }
  1267. }else{
  1268. exit('No direct script access allowed');
  1269. }
  1270. }
  1271. private function _showckbh($arg_array){
  1272. if($this->input->method() === 'post'){
  1273. exit('No direct script access allowed');
  1274. }
  1275. $id = $arg_array[0];
  1276. $drck_list = $this->bhccwl->getDrck();
  1277. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1278. $shop_list = array_column($shop_list,'shopname','id');
  1279. $info = $this->bhccwl->read($id);
  1280. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1281. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1282. foreach($list as $k=>$v){
  1283. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1284. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1285. }
  1286. $this->data['info'] = $info;
  1287. $this->data['list'] = $list;
  1288. $this->data['list_dcd'] = $list_dcd;
  1289. $this->_Template('beihuogl_showckbh',$this->data);
  1290. }
  1291. //仓库录入调出单
  1292. private function _ckdcd(){
  1293. if($this->input->method() === 'post'){
  1294. $lrdcd = $this->input->post('lrdcd',true);
  1295. if(empty($lrdcd)){
  1296. //列表展示
  1297. $page = $this->input->post('page',true);
  1298. $perpage = $this->input->post('perpage',true);
  1299. $bh_no = $this->input->post('bh_no',true);
  1300. $dcd_no = $this->input->post('dcd_no',true);
  1301. $status = $this->input->post('status',true);
  1302. $ktime = $this->input->post('ktime',true);
  1303. $jtime = $this->input->post('jtime',true);
  1304. $ktime = strtotime($ktime);
  1305. $jtime = strtotime($jtime);
  1306. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1307. if(!empty($bh_no)){
  1308. $where .= " and bh_no = '".$bh_no."' ";
  1309. }
  1310. if($status > -1){
  1311. $where .= " and status = ".$status." ";
  1312. }
  1313. if(!empty($dcd_no)){
  1314. $where .= " and dcd_no = '".$dcd_no."' ";
  1315. }
  1316. //数据排序
  1317. $order_str = "id desc";
  1318. if(empty($page))
  1319. {
  1320. $start = 0;
  1321. $perpage = 1;
  1322. }
  1323. else
  1324. {
  1325. $start = ($page - 1)*$perpage;
  1326. }
  1327. $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);
  1328. if(empty($list)){
  1329. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1330. echo json_encode($rows);exit;
  1331. }
  1332. $status_list = $this->bhdcd->getStatus();
  1333. foreach($list as $k=>$v){
  1334. $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>";
  1335. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1336. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1337. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1338. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d",$v['create_time']);
  1339. $str = "";
  1340. if($v['is_rk'] == 0){
  1341. $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>";
  1342. }
  1343. if(!empty($v['rk_time'])){
  1344. $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>";
  1345. }
  1346. $list[$k]['rk_time'] = $str;
  1347. unset($list[$k]['is_rk']);
  1348. }
  1349. $total = $this->bhdcd->find_count($where);
  1350. $pagenum = ceil($total/$perpage);
  1351. $over = $total-($start+$perpage);
  1352. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1353. echo json_encode($rows);exit;
  1354. }else{
  1355. if(empty($lrdcd)){
  1356. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1357. }
  1358. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1359. if(!empty($num)){
  1360. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1361. }
  1362. //查询录入执行的调出单
  1363. $token = $this->settingtest->get_yytoken_120();
  1364. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1365. if(empty($res[0]['Data'])){
  1366. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1367. }
  1368. $time = time();
  1369. $final_list = [];
  1370. foreach($res[0]['Data'] as $k=>$v){
  1371. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1372. $tmp_sku = '';
  1373. $tmp_title = '';
  1374. $tmp_features = '';
  1375. $tmp_number='';
  1376. if(!empty($good_info)){
  1377. $tmp_sku = $good_info['sku'];
  1378. $tmp_title = $good_info['title'];
  1379. $tmp_features = $good_info['features'];
  1380. $tmp_number = str_replace("-","", $good_info['features']);
  1381. }
  1382. $final_list[] = [
  1383. 'sku'=>$tmp_sku,
  1384. 'dcd_no'=>$v['docno'],
  1385. 'jm'=>$v['iteminfo_itemcode'],
  1386. 'zh'=>$v['iteminfo_itemname'],
  1387. 'num'=>$v['costuomqty'],
  1388. 'real_num'=>$v['costuomqty'],
  1389. 'bh_no'=>$v['erp_no'],
  1390. 'create_time'=>$time,
  1391. 'title'=>$tmp_title,
  1392. 'features'=>$tmp_features,
  1393. 'number'=>$tmp_number,
  1394. ];
  1395. }
  1396. $r =$this->db->insert_batch('bhdcd',$final_list);
  1397. if($r){
  1398. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1399. }else{
  1400. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1401. }
  1402. exit;
  1403. }
  1404. }else{
  1405. $status_list = $this->bhdcd->getStatus();
  1406. $this->data['status_list'] = $status_list;
  1407. $this->_Template('beihuogl_ckdcd',$this->data);
  1408. }
  1409. }
  1410. private function _ckbherprk($arg_array){
  1411. if($this->input->method() === 'post'){
  1412. $data = $this->input->post(null,true);
  1413. $dcd_no = $data['dcd_no'];
  1414. $drd_no = $data['drd_no'];
  1415. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and is_rk = 0");
  1416. $whlabel_arr = [];
  1417. $time = time();
  1418. $err_list= [];
  1419. foreach($list as $k=>$v){
  1420. if(empty($v['sku'])){
  1421. $err_list[] = $v['jm']."不存在";
  1422. continue;
  1423. }
  1424. for($i=0;$i<$v['num'];$i++){
  1425. $whlabel_arr[] = [
  1426. 'sku'=>$v['sku'],
  1427. 'number'=>$v['number'],
  1428. 'features'=>$v['features'],
  1429. 'title'=>$v['title'],
  1430. 'zh'=>$v['zh'],
  1431. 'warehouse'=>'13',
  1432. 'enter'=>$time,
  1433. 'state'=>0,
  1434. 'retreatwarehouse'=>'13',
  1435. 'time'=>$time,
  1436. 'details'=>$v['kw'],
  1437. 'bs'=>1,
  1438. 'rktype'=>9,
  1439. ];
  1440. }
  1441. }
  1442. if(!empty($err_list)){
  1443. echo json_encode(['success'=>false,'msg'=>implode('<br/>', $err_list)]);exit;
  1444. }
  1445. $this->db->trans_start();
  1446. $this->db->insert_batch('whlabel',$whlabel_arr);
  1447. $this->db->where('dcd_no',$dcd_no);
  1448. //$this->db->where('drd_no',$drd_no);
  1449. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time,'is_rk'=>1]);
  1450. if($this->db->trans_status() === FALSE){
  1451. $this->db->trans_rollback();
  1452. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1453. }else{
  1454. $this->db->trans_commit();
  1455. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1456. }
  1457. }else{
  1458. $dcd_no = $arg_array[0];
  1459. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1460. $jm_list = array_column($list,'jm');
  1461. $status_list = $this->bhdcd->getStatus();
  1462. $in_where = "( ";
  1463. foreach($jm_list as $k=>$v){
  1464. $in_where .= "'".$v."',";
  1465. }
  1466. $in_where = rtrim($in_where,",");
  1467. $in_where .= " )";
  1468. foreach($list as $k=>$v){
  1469. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1470. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1471. if(!empty($v['kw'])){
  1472. $list[$k]['kw'] = $v['kw'];
  1473. }else{
  1474. if(!empty($list[$k]['sku'])){
  1475. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1476. if(!empty($whlabel_info)){
  1477. if(!empty($whlabel_info['details'])){
  1478. $list[$k]['kw'] = $whlabel_info['details'];
  1479. $this->bhdcd->save([
  1480. 'kw'=>$whlabel_info['details'],
  1481. ],$v['id']);
  1482. }else{
  1483. $list[$k]['kw'] = "";
  1484. }
  1485. }else{
  1486. $list[$k]['kw'] = "";
  1487. }
  1488. }else{
  1489. $list[$k]['kw'] = "";
  1490. }
  1491. }
  1492. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1493. }
  1494. $this->data['list'] = $list;
  1495. $this->_Template('beihuogl_ckbherprk',$this->data);
  1496. }
  1497. }
  1498. private function _bhdcdsave(){
  1499. if($this->input->method() === 'post'){
  1500. $id = $this->input->post('id',true);
  1501. $val = $this->input->post('val',true);
  1502. $column = $this->input->post('column',true);
  1503. $info = $this->bhdcd->read($id);
  1504. $update_arr = [];
  1505. if($column == 'real_num'){
  1506. if($val > $info['num']){
  1507. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1508. }
  1509. $update_arr = [
  1510. 'real_num'=>(int)$val,
  1511. ];
  1512. }elseif($column == 'kw'){
  1513. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1514. if(!empty($winfo)){
  1515. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1516. if(empty($winfo)){
  1517. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1518. }
  1519. }
  1520. $update_arr = [
  1521. 'kw'=>trim($val),
  1522. ];
  1523. }else{
  1524. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1525. }
  1526. $r = $this->bhdcd->save($update_arr,$id);
  1527. if($r){
  1528. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1529. }else{
  1530. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1531. }
  1532. }else{
  1533. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1534. }
  1535. }
  1536. private function _u9scdexcel($arg_array){
  1537. $id = $arg_array[0];
  1538. $info = $this->bhccwl->read($id);
  1539. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1540. //生成excel
  1541. $filename = $info['bh_no']."备货生产单.xls";
  1542. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1543. <head>
  1544. <!--[if gte mso 9]><xml>
  1545. <x:ExcelWorkbook>
  1546. <x:ExcelWorksheets>
  1547. <x:ExcelWorksheet>
  1548. <x:Name>EXCEL</x:Name>
  1549. <x:WorksheetOptions>
  1550. <x:Print>
  1551. <x:ValidPrinterInfo />
  1552. </x:Print>
  1553. </x:WorksheetOptions>
  1554. </x:ExcelWorksheet>
  1555. </x:ExcelWorksheets>
  1556. </x:ExcelWorkbook>
  1557. </xml>
  1558. <![endif]-->
  1559. </head><body>";
  1560. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1561. $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td></tr>";
  1562. foreach ($list as $key=>$value)
  1563. {
  1564. $str .= "<tr>";
  1565. $str .= "<td>". $value['bh_no']. "</td>";
  1566. $str .= "<td>". $value['title']. "</td>";
  1567. $str .= "<td>". $value['jm']. "</td>";
  1568. $str .= "<td>". $value['ck_num']. "</td>";
  1569. $str .= "<td>". $value['u9sc_no']. "</td>";
  1570. $str .= "</tr>";
  1571. }
  1572. $str .= "</table></body></html>";
  1573. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1574. header( "Content-type: application/octet-stream" );
  1575. header( "Content-Disposition: attachment; filename=".$filename );
  1576. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1577. header( "Pragma: no-cache" );
  1578. header( "Expires: 0" );
  1579. exit($str);
  1580. }
  1581. //打印标签
  1582. private function _printlabel(){
  1583. if($this->input->method() === 'post'){
  1584. $id = $this->input->post('id',true);
  1585. $xbqnum = $this->input->post('num',true);
  1586. $info = $this->bhdcd->read($id);
  1587. if(empty($info)){
  1588. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1589. }
  1590. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $info['features']);
  1591. $featurespp = explode('-', trim($featurespp, '-'));
  1592. if (isset($featurespp[5])) {
  1593. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  1594. } else {
  1595. $tmp_featurespp = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  1596. }
  1597. $label = '';
  1598. $cpid = $this->whlabellabel->find_count();
  1599. $cpid = $cpid + 1;
  1600. $time = time();
  1601. $label = time().rand(10,99);
  1602. $label = substr($label,1);
  1603. $insert_arr = [
  1604. 'purchase'=>1,
  1605. 'shop'=>'',
  1606. 'sku'=>$info['sku'],
  1607. 'number'=>$info['number'],
  1608. 'features'=>$info['features'],
  1609. 'featurespp'=>$tmp_featurespp,
  1610. 'title'=>$info['title'],
  1611. 'label'=>$label,
  1612. 'warehouse'=>13,
  1613. 'time'=>$time,
  1614. 'details'=>$info['kw'],
  1615. 'cpid'=>$cpid,
  1616. 'jm'=>$info['jm'],
  1617. 'cpbz'=>''
  1618. ];
  1619. $this->db->trans_begin();
  1620. $this->whlabellabel->insert($insert_arr);
  1621. if ($this->db->trans_status() === TRUE) {
  1622. $this->db->trans_commit();
  1623. } else {
  1624. $this->db->trans_rollback();
  1625. echo json_encode(array('msg' => '错误,请重试!', 'success' => false));
  1626. exit;
  1627. }
  1628. $details = '位置:(' . $info['kw'] . ') <font style="font-size: 18px;">' . $cpid . '</font>' ;
  1629. $details = ' <b style="font-size: 18px;">'."许昌仓</b> ".$details;
  1630. $purchase = "龙盈工厂";
  1631. 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));
  1632. exit; //特殊仓目前不需要仓库选项
  1633. }else{
  1634. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1635. }
  1636. }
  1637. private function _dcdjzrk(){
  1638. if($this->input->method() === 'post'){
  1639. $id = $this->input->post('id',true);
  1640. $info = $this->bhdcd->read($id);
  1641. if($info['is_rk'] == 0){
  1642. $this->bhdcd->save(['is_rk'=>1],$id);
  1643. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1644. }else{
  1645. echo json_encode(['success'=>true,'msg'=>'此条信息已禁止入库']);exit;
  1646. }
  1647. }else{
  1648. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1649. }
  1650. }
  1651. }