Beihuogl.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  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. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. if(!isset($_SESSION['api'])){
  20. header('Location: /');exit;
  21. }
  22. if($arg == 'dyapply')//
  23. {
  24. $this->_dyapply();
  25. }
  26. elseif($arg == 'dyapplyadd')//
  27. {
  28. $this->_dyapplyadd();
  29. }
  30. elseif($arg == 'dyapplyedit')//
  31. {
  32. $this->_dyapplyedit($arg_array);
  33. }
  34. elseif($arg == 'dyapplygxzt')//
  35. {
  36. $this->_dyapplygxzt();
  37. }
  38. elseif($arg == 'dyapplyexcel'){
  39. $this->_dyapplyexcel();
  40. }
  41. elseif($arg == 'ccwlshlist'){
  42. $this->_ccwlshlist();
  43. }
  44. elseif($arg == 'ccwlbhindex'){
  45. $this->_ccwlbhindex();
  46. }elseif($arg == 'dyapplysave'){
  47. $this->_dyapplysave();
  48. }elseif($arg == 'ccwlbhmake'){
  49. $this->_ccwlbhmake();
  50. }elseif($arg == 'ccwlbhedit'){
  51. $this->_ccwlbhedit($arg_array);
  52. }elseif($arg == 'ccwleditxzbh'){
  53. $this->_ccwleditxzbh();
  54. }elseif($arg == 'ccwlbhsavexzbh'){
  55. $this->_ccwlbhsavexzbh();
  56. }elseif($arg == 'ccwldelitem'){
  57. $this->_ccwldelitem();
  58. }elseif($arg == 'ccwlbhsave'){
  59. $this->_ccwlbhsave();
  60. }elseif($arg == 'ckbhindex'){
  61. $this->_ckbhindex();
  62. }elseif($arg == 'ckbhedit'){
  63. $this->_ckbhedit($arg_array);
  64. }elseif($arg == 'makeu9scd'){
  65. $this->_makeu9scd($arg_array);
  66. }elseif($arg == 'showckbh'){
  67. $this->_showckbh($arg_array);
  68. }elseif($arg == 'ddscscd'){
  69. $this->_ddscscd();
  70. }elseif($arg == 'ckdcd'){
  71. $this->_ckdcd();
  72. }elseif($arg == 'ckbherprk'){
  73. $this->_ckbherprk($arg_array);
  74. }elseif($arg == 'bhdcdsave'){
  75. $this->_bhdcdsave();
  76. }
  77. else
  78. {
  79. $this->_index();
  80. }
  81. }
  82. private function _index(){
  83. exit('No direct script access allowed 1');
  84. }
  85. //备货申请单的列表
  86. private function _dyapply(){
  87. if($this->input->method() === 'post'){
  88. $page = $this->input->post('page',true);
  89. $perpage = $this->input->post('perpage',true);
  90. $sqr = $this->input->post('sqr',true);
  91. $sqr = trim($sqr);
  92. $shop_id = $this->input->post('shop_id',true);
  93. $plat_id = $this->input->post('plat_id',true);
  94. $shop_ids = $this->input->post('shop_ids',true);
  95. $ktime = $this->input->post('ktime',true);
  96. $jtime = $this->input->post('jtime',true);
  97. $ktime = strtotime($ktime);
  98. $jtime = strtotime($jtime);
  99. $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
  100. if(!empty($sqr)){
  101. $where .= " and sqr = ".$sqr." ";
  102. }
  103. if(!empty($shop_id)){
  104. $where .= " and shop_id = ".$shop_id." ";
  105. }else{
  106. $where .= " and shop_id in (".$shop_ids.") ";
  107. }
  108. if(!empty($plat_id)){
  109. $where .= " and plat_id = ".$plat_id." ";
  110. }
  111. //数据排序
  112. $order_str = "id desc";
  113. if(empty($page))
  114. {
  115. $start = 0;
  116. $perpage = 1;
  117. }
  118. else
  119. {
  120. $start = ($page - 1)*$perpage;
  121. }
  122. $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);
  123. if(empty($list)){
  124. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  125. echo json_encode($rows);exit;
  126. }
  127. $shop_list = $this->shop->find_all("1=1","id,shopname");
  128. $shop_list = array_column($shop_list,'shopname','id');
  129. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  130. $plat_list = array_column($plat_list,'title','id');
  131. $status_list = $this->bhsq->getSqStatus();
  132. foreach($list as $k=>$v){
  133. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  134. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  135. $list[$k]['sq_status'] = isset($status_list[$v['sq_status']])?$status_list[$v['sq_status']]:"";
  136. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  137. $str = "";
  138. if($v['sq_status'] == 1 || $v['sq_status'] == 3){
  139. $str .= "<div style='text-align:center;'>";
  140. $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>";
  141. $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>";
  142. $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>";
  143. $str .= "</div>";
  144. }
  145. $list[$k]['update_time'] = $str;
  146. }
  147. $total = $this->bhsq->find_count($where);
  148. $pagenum = ceil($total/$perpage);
  149. $over = $total-($start+$perpage);
  150. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  151. echo json_encode($rows);exit;
  152. }else{
  153. $user = $this->user->get_api($_SESSION['api']);
  154. $usersp = explode('|',trim($user['shop'],'|'));
  155. $this->data['usersp'] = implode(",",$usersp);
  156. $this->_Template('beihuogl_dyapply',$this->data);
  157. }
  158. }
  159. //备货申请单的添加
  160. private function _dyapplyadd(){
  161. if($this->input->method() === 'post'){
  162. $data = $this->input->post();
  163. $time = strtotime(date("Y-m-d"),time());
  164. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  165. if(empty($info)){
  166. $num = 1;
  167. }else{
  168. $arr = explode('-',$info['sb_no']);
  169. $num = (int)$arr[2]+1;
  170. }
  171. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  172. $sb_no = "SQ-".date("ymd")."-".$num;
  173. $insert_arr = [];
  174. $time = time();
  175. foreach($data['title'] as $k=>$v){
  176. $insert_arr[] = [
  177. 'sb_no'=>$sb_no,
  178. 'sku'=>$data['sku'][$k],
  179. 'title'=>$data['title'][$k],
  180. 'shop_id'=>$data['shop_id'],
  181. 'plat_id'=>$data['plat_id'],
  182. 'sqr'=>$data['sqr'],
  183. 'sq_num'=>$data['sq_num'][$k],
  184. 'ccwl_num'=>$data['sq_num'][$k],
  185. 'ck_num'=>$data['sq_num'][$k],
  186. 'sq_status'=>1,
  187. 'remark'=>$data['remark'],
  188. 'add_time'=>$time,
  189. 'real_time'=>$time,
  190. 'update_time'=>$time,
  191. ];
  192. }
  193. $r =$this->db->insert_batch('bhsq',$insert_arr);
  194. if($r){
  195. echo json_encode(['code'=>1,'msg'=>'添加成功']);
  196. }else{
  197. echo json_encode(['code'=>-1,'msg'=>'添加失败']);
  198. }
  199. exit;
  200. }else{
  201. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  202. $this->data['plat_list'] = $plat_list;
  203. $this->_Template('beihuogl_dyapplyadd',$this->data);
  204. }
  205. }
  206. //备货申请单的 修改
  207. private function _dyapplyedit($arg_array){
  208. if($this->input->method() === 'post'){
  209. $data = $this->input->post();
  210. $id = $data['id'];
  211. $update_arr = [
  212. 'shop_id'=>$data['shop_id'],
  213. 'plat_id'=>$data['plat_id'],
  214. 'sqr'=>$data['sqr'],
  215. 'sq_num'=>$data['sq_num'],
  216. 'ccwl_num'=>$data['sq_num'],
  217. 'ck_num'=>$data['sq_num'],
  218. 'sku'=>$data['sku'],
  219. 'remark'=>$data['remark'],
  220. ];
  221. $r = $this->bhsq->save($update_arr,$id);
  222. if($r){
  223. echo json_encode(['msg'=>'添加成功','success'=>true]);
  224. }else{
  225. echo json_encode(['msg'=>'添加失败','success'=>false]);
  226. }
  227. exit;
  228. }else{
  229. $id = $arg_array[0];
  230. $info = $this->bhsq->find("id = ".$id);
  231. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  232. $this->data['plat_list'] = $plat_list;
  233. $this->data['info'] = $info;
  234. $this->_Template('beihuogl_dyapplyedit',$this->data);
  235. }
  236. }
  237. //备货申请单的 状态申请 如 发布 或者取消
  238. private function _dyapplygxzt(){
  239. if($this->input->method() === 'post'){
  240. $data = $this->input->post();
  241. $id = (int)$data['id'];
  242. $type = (int)$data['status'];
  243. $update_arr = [];
  244. $update_arr['sq_status'] = $type;
  245. if($type == 2){
  246. $update_arr['public_time'] = time();
  247. }
  248. $r = $this->bhsq->save($update_arr,$id);
  249. if($r){
  250. echo json_encode(['msg'=>'修改成功','success'=>true]);
  251. }else{
  252. echo json_encode(['msg'=>'修改失败','success'=>false]);
  253. }
  254. exit;
  255. }else{
  256. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  257. }
  258. }
  259. //备货申请单的
  260. private function _dyapplysave(){
  261. if($this->input->method() === 'post'){
  262. $data = $this->input->post();
  263. $id = (int)$data['id'];
  264. $val = $this->input->post('val',true);
  265. $column = $data['column'];
  266. if($column == 'ccwl_num'){
  267. $update_arr = [
  268. 'ccwl_num'=>(int)$val,
  269. 'ck_num'=>(int)$val,
  270. ];
  271. }elseif($column == 'sku'){
  272. $update_arr = [
  273. 'sku'=>$val,
  274. ];
  275. }elseif($column == 'ck_num'){
  276. $update_arr = [
  277. 'ck_num'=>(int)$val,
  278. ];
  279. }elseif($column == 'drck'){
  280. $update_arr = [
  281. 'drck'=>(int)$val,
  282. ];
  283. }else{
  284. echo json_encode(['msg'=>'修改信息不合规','success'=>false]);
  285. exit;
  286. }
  287. $r = $this->bhsq->save($update_arr,$id);
  288. if($r){
  289. echo json_encode(['msg'=>'修改成功','success'=>true]);
  290. }else{
  291. echo json_encode(['msg'=>'修改失败','success'=>false]);
  292. }
  293. exit;
  294. }else{
  295. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  296. }
  297. }
  298. private function _dyapplyexcel(){
  299. if($this->input->method() === 'post'){
  300. $data = $this->input->post('list',true);
  301. if(empty($data)){
  302. $json_data = $this->input->raw_input_stream;
  303. $tmp_data = json_decode($json_data,true);
  304. $data = $tmp_data['list'];
  305. if(empty($data)){
  306. echo json_encode(['success'=>false,'msg'=>'未获取要保存的数据']);
  307. exit;
  308. }
  309. }
  310. $shop_list = $this->shop->find_all("1=1","id,shortname,type");
  311. $shop_list = array_column($shop_list,null,'shortname');
  312. $time = strtotime(date("Y-m-d"),time());
  313. $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
  314. if(empty($info)){
  315. $num = 1;
  316. }else{
  317. $arr = explode('-',$info['sb_no']);
  318. $num = (int)$arr[2]+1;
  319. }
  320. $time = time();
  321. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  322. $sb_no = "SQ-".date("ymd")."-".$num;
  323. $insert_arr = [];
  324. $error_list= [];
  325. foreach($data as $k=>$v){
  326. $shopshortname = trim($v[4]);
  327. $shop_info = isset($shop_list[$shopshortname])?$shop_list[$shopshortname]:[];
  328. if(empty($shop_info)){
  329. $error_list[] = [
  330. 'msg'=>"第".($k+1).'行店铺不存在,请核对表格信息'.$shopshortname,
  331. ];
  332. continue;
  333. }
  334. $num = (int)$v[3];
  335. if(empty($num)){
  336. $error_list[] = [
  337. 'msg'=>"第".($k+1).'行数量不能为空,请核对表格信息',
  338. ];
  339. continue;
  340. }
  341. $tmp_time = trim($v[0]);
  342. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tmp_time)) {
  343. $add_time = strtotime($tmp_time);
  344. }else{
  345. $error_list[] = [
  346. 'msg'=>"第".($k+1).'行日期格式不正确,请核对表格信息',
  347. ];
  348. continue;
  349. }
  350. if(empty($v[5])){
  351. $error_list[] = [
  352. 'msg'=>"第".($k+1).'行申请人信息不能为空,请核对表格信息',
  353. ];
  354. continue;
  355. }
  356. if(empty($v[1])){
  357. $error_list[] = [
  358. 'msg'=>"第".($k+1).'行产品信息不能为空,请核对表格信息',
  359. ];
  360. continue;
  361. }
  362. $insert_arr[] = [
  363. 'sb_no'=>$sb_no,
  364. 'sku'=>trim($v[2]),
  365. 'title'=>trim($v[1]),
  366. 'shop_id'=>$shop_info['id'],
  367. 'plat_id'=>$shop_info['type'],
  368. 'sqr'=>trim($v[5]),
  369. 'sq_num'=>$num,
  370. 'ccwl_num'=>$num,
  371. 'ck_num'=>$num,
  372. 'sq_status'=>1,
  373. 'remark'=>$v[6],
  374. 'add_time'=>$add_time,
  375. 'real_time'=>$time,
  376. 'update_time'=>$time,
  377. ];
  378. }
  379. $r =$this->db->insert_batch('bhsq',$insert_arr);
  380. if($r){
  381. echo json_encode(['success'=>true,'msg'=>'添加成功','error_list'=>$error_list]);
  382. }else{
  383. echo json_encode(['success'=>false,'msg'=>'添加失败','error_list'=>$error_list]);
  384. }
  385. exit;
  386. }else{
  387. echo json_encode(['success'=>true,'msg'=>'请求失败']);
  388. exit;
  389. }
  390. }
  391. //仓储物流部的备货申请单的列表
  392. private function _ccwlshlist(){
  393. if($this->input->method() === 'post'){
  394. $page = $this->input->post('page',true);
  395. $perpage = $this->input->post('perpage',true);
  396. $sqr = $this->input->post('sqr',true);
  397. $sqr = trim($sqr);
  398. $shop_id = $this->input->post('shop_id',true);
  399. $plat_id = $this->input->post('plat_id',true);
  400. $shop_ids = $this->input->post('shop_ids',true);
  401. $ktime = $this->input->post('ktime',true);
  402. $jtime = $this->input->post('jtime',true);
  403. $ktime = strtotime($ktime);
  404. $jtime = strtotime($jtime);
  405. $where = "sq_status = 2 and ccwl_status = 0 ";
  406. $where .= " and add_time >= ".$ktime." and add_time < ".$jtime." ";
  407. if(!empty($sqr)){
  408. $where .= " and sqr = ".$sqr." ";
  409. }
  410. if(!empty($shop_id)){
  411. $where .= " and shop_id = ".$shop_id." ";
  412. }else{
  413. $where .= " and shop_id in (".$shop_ids.") ";
  414. }
  415. if(!empty($plat_id)){
  416. $where .= " and plat_id = ".$plat_id." ";
  417. }
  418. //数据排序
  419. $order_str = "id desc";
  420. if(empty($page))
  421. {
  422. $start = 0;
  423. $perpage = 1;
  424. }
  425. else
  426. {
  427. $start = ($page - 1)*$perpage;
  428. }
  429. $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);
  430. if(empty($list)){
  431. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  432. echo json_encode($rows);exit;
  433. }
  434. $shop_list = $this->shop->find_all("1=1","id,shopname");
  435. $shop_list = array_column($shop_list,'shopname','id');
  436. $plat_list = $this->typeclass->find_all("classid = 32","id,title");
  437. $plat_list = array_column($plat_list,'title','id');
  438. foreach($list as $k=>$v){
  439. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  440. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  441. $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
  442. $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
  443. $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>";
  444. $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>";
  445. }
  446. $total = $this->bhsq->find_count($where);
  447. $pagenum = ceil($total/$perpage);
  448. $over = $total-($start+$perpage);
  449. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  450. echo json_encode($rows);exit;
  451. }else{
  452. $user = $this->user->get_api($_SESSION['api']);
  453. $usersp = explode('|',trim($user['shop'],'|'));
  454. $this->data['usersp'] = implode(",",$usersp);
  455. $this->_Template('beihuogl_ccwlshlist',$this->data);
  456. }
  457. }
  458. //仓储物流合成备货单
  459. private function _ccwlbhmake(){
  460. if($this->input->method() === 'post'){
  461. $data = $this->input->post();
  462. $bh_no = $data['bh_no'];
  463. $select_id = $data['arr_id'];
  464. if(empty($select_id)){
  465. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  466. exit;
  467. }
  468. if(empty($bh_no)){
  469. $tmp_time = strtotime(date("Y-m-d"),time());
  470. $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
  471. $num = $num+1;
  472. $num = str_pad($num, 3, '0', STR_PAD_LEFT);
  473. $bh_no = "BH-".date("ymd")."-".$num;
  474. }
  475. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
  476. foreach($list as $k=>$v){
  477. if(empty($v['sku'])){
  478. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  479. exit;
  480. }
  481. }
  482. $classid = $this->logic_u9tools->getClass();
  483. $typeclass = $this->logic_u9tools->getTypeClass();
  484. foreach($list as $k=>$v){
  485. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  486. if(empty($whlabel_info)){
  487. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  488. if(empty($whlabel_info)){
  489. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  490. exit;
  491. }
  492. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  493. $this->bhsq->save([
  494. 'jm'=>$r['jm'],
  495. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  496. 'features'=>$whlabel_info['features'],
  497. ],$v['id']);
  498. }else{
  499. $this->bhsq->save([
  500. 'jm'=>$whlabel_info['jm'],
  501. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  502. 'features'=>$whlabel_info['features'],
  503. ],$v['id']);
  504. }
  505. }
  506. $this->db->trans_start();
  507. $this->db->where_in('id',$select_id);
  508. $this->db->update('bhsq',[
  509. 'bh_no'=>$bh_no,
  510. 'sq_status'=>4,
  511. 'ccwl_status'=>1,
  512. ]);
  513. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  514. $this->db->where_in('id',$select_id);
  515. $query = $this->db->get('bhsq');
  516. $result = $query->row();
  517. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  518. $time = time();
  519. $this->bhccwl->insert([
  520. 'bh_no'=>$bh_no,
  521. 'status'=>0,
  522. 'num'=>$total_ccwl_num,
  523. 'create_time'=>$time,
  524. 'update_time'=>$time,
  525. ]);
  526. if($this->db->trans_status() === FALSE){
  527. $this->db->trans_rollback();
  528. echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
  529. exit;
  530. }else{
  531. $this->db->trans_commit();
  532. echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
  533. exit;
  534. }
  535. }else{
  536. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  537. exit;
  538. }
  539. }
  540. private function getU9Drck($features){
  541. if(stripos($features,'-126-') !== false)
  542. {
  543. $drck = '12003';//进入发条库
  544. }
  545. else if(stripos($features,'-127-') !== false)
  546. {
  547. $drck = '12004';//进入发块库
  548. }
  549. else
  550. {
  551. $drck = '12006';//其它进入完成库
  552. }
  553. return $drck;
  554. }
  555. //仓储物流部的备货单列表
  556. private function _ccwlbhindex(){
  557. if($this->input->method() === 'post'){
  558. $page = $this->input->post('page',true);
  559. $perpage = $this->input->post('perpage',true);
  560. $bh_no = $this->input->post('bh_no',true);
  561. $status = $this->input->post('status',true);
  562. $ktime = $this->input->post('ktime',true);
  563. $jtime = $this->input->post('jtime',true);
  564. $ktime = strtotime($ktime);
  565. $jtime = strtotime($jtime);
  566. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  567. if(!empty($bh_no)){
  568. $where .= " and bh_no = '".$bh_no."' ";
  569. }
  570. if($status > -1){
  571. $where .= " and status = ".$status." ";
  572. }
  573. //数据排序
  574. $order_str = "id desc";
  575. if(empty($page))
  576. {
  577. $start = 0;
  578. $perpage = 1;
  579. }
  580. else
  581. {
  582. $start = ($page - 1)*$perpage;
  583. }
  584. $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
  585. if(empty($list)){
  586. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  587. echo json_encode($rows);exit;
  588. }
  589. $status_list = $this->bhccwl->getStatus();
  590. foreach($list as $k=>$v){
  591. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  592. $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
  593. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  594. $str = "";
  595. if($v['status'] == 0){
  596. $str .= "<div style='text-align:center;'>";
  597. $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>";
  598. $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>";
  599. $str .= "</div>";
  600. }
  601. $list[$k]['update_time'] = $str;
  602. }
  603. $total = $this->bhccwl->find_count($where);
  604. $pagenum = ceil($total/$perpage);
  605. $over = $total-($start+$perpage);
  606. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  607. echo json_encode($rows);exit;
  608. }else{
  609. $this->_Template('beihuogl_ccwlbhindex',$this->data);
  610. }
  611. }
  612. //仓储物流部备货 在编辑页面添加数据
  613. private function _ccwlbhsavexzbh(){
  614. if($this->input->method() === 'post'){
  615. $data = $this->input->post();
  616. $select_id = $data['select_id'];
  617. $id = $data['id'];
  618. $bh_no = $data['bh_no'];
  619. if(empty($select_id)){
  620. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  621. exit;
  622. }
  623. $info = $this->bhccwl->read($id);
  624. if(empty($info)){
  625. echo json_encode(['success'=>false,'msg'=>'数据不存在']);
  626. exit;
  627. }
  628. if($info['bh_no'] != $bh_no){
  629. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
  630. exit;
  631. }
  632. $bh_no = $info['bh_no'];
  633. $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
  634. foreach($list as $k=>$v){
  635. if(empty($v['sku'])){
  636. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
  637. exit;
  638. }
  639. if(!empty($v['bh_no'])){
  640. echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
  641. exit;
  642. }
  643. }
  644. $classid = $this->logic_u9tools->getClass();
  645. $typeclass = $this->logic_u9tools->getTypeClass();
  646. foreach($list as $k=>$v){
  647. $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
  648. if(empty($whlabel_info)){
  649. $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
  650. if(empty($whlabel_info)){
  651. echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
  652. exit;
  653. }
  654. if(empty($v['jm'])){
  655. $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
  656. $this->bhsq->save([
  657. 'jm'=>$r['jm'],
  658. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  659. 'features'=>$whlabel_info['features'],
  660. ],$v['id']);
  661. }
  662. $list[$k]['jm'] = $r['jm'];
  663. }else{
  664. $this->bhsq->save([
  665. 'jm'=>$whlabel_info['jm'],
  666. 'drck'=>$this->getU9Drck($whlabel_info['features']),
  667. 'features'=>$whlabel_info['features'],
  668. ],$v['id']);
  669. $list[$k]['jm'] = $whlabel_info['jm'];
  670. }
  671. }
  672. $status_list = $this->bhccwl->getStatus();
  673. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  674. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  675. $plat_list = array_column($plat_list,'title','id');
  676. $shop_list = $this->shop->find_all("1=1","id,shopname");
  677. $shop_list = array_column($shop_list,'shopname','id');
  678. foreach($list as $k=>$v){
  679. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  680. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  681. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  682. $list[$k]['bh_no'] = $info['bh_no'];
  683. }
  684. echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
  685. }else{
  686. echo json_encode(['success'=>false,'msg'=>'请求失败']);
  687. exit;
  688. }
  689. }
  690. private function _ccwlbhedit($arg_array){
  691. if($this->input->method() === 'post'){
  692. $select_id = $this->input->post('arr_id',true);
  693. if(empty($select_id)){
  694. echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
  695. exit;
  696. }
  697. $id = $this->input->post('id',true);
  698. $info = $this->bhccwl->read($id);
  699. $bh_no = $info['bh_no'];
  700. $this->db->where_in('id',$select_id);
  701. $this->db->update('bhsq',[
  702. 'bh_no'=>$bh_no,
  703. 'sq_status'=>4,
  704. 'ccwl_status'=>1,
  705. ]);
  706. $this->db->select('SUM(ccwl_num) as total_ccwl_num');
  707. $this->db->where_in('id',$select_id);
  708. $query = $this->db->get('bhsq');
  709. $result = $query->row();
  710. $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
  711. $time = time();
  712. $this->bhccwl->save([
  713. 'num'=>$total_ccwl_num,
  714. 'update_time'=>$time,
  715. ],$info['id']);
  716. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  717. }else{
  718. $id = $arg_array[0];
  719. $info = $this->bhccwl->find("id = ".$id);
  720. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
  721. $status_list = $this->bhccwl->getStatus();
  722. $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
  723. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  724. $plat_list = array_column($plat_list,'title','id');
  725. $shop_list = $this->shop->find_all("1=1","id,shopname");
  726. $shop_list = array_column($shop_list,'shopname','id');
  727. foreach($list as $k=>$v){
  728. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  729. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  730. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  731. }
  732. // $this->data['info'] = $info;
  733. $this->data['list'] = $list;
  734. $this->data['info'] = $info;
  735. $this->_Template('beihuogl_ccwlbhedit',$this->data);
  736. }
  737. }
  738. private function _ccwldelitem(){
  739. if($this->input->method() === 'post'){
  740. $data = $this->input->post();
  741. $id = $data['id'];
  742. $bh_no = $data['bh_no'];
  743. $info = $this->bhsq->read($id);
  744. $ccwl_num = $info['ccwl_num'];
  745. if(empty($info)){
  746. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  747. }
  748. if(empty($info['bh_no'])){
  749. if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
  750. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  751. }else{
  752. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  753. }
  754. }
  755. if($info['bh_no'] != $bh_no){
  756. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  757. }
  758. $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
  759. $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
  760. $this->db->trans_start();
  761. $this->bhccwl->save([
  762. 'num'=>$ccwl_info['num'],
  763. ],$ccwl_info['id']);
  764. $this->bhsq->save([
  765. 'sq_status'=>2,
  766. 'ccwl_status'=>0,
  767. 'bh_no'=>''
  768. ],$id);
  769. if($this->db->trans_status() === FALSE){
  770. $this->db->trans_rollback();
  771. echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
  772. }else{
  773. $this->db->trans_commit();
  774. echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
  775. }
  776. }else{
  777. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  778. }
  779. }
  780. private function _ccwleditxzbh(){
  781. if($this->input->method() === 'post'){
  782. $data = $this->input->post();
  783. //超过三月没审核的 就不展示了
  784. $time = time() - 60*24*3600;
  785. $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
  786. if(!empty($data['sqr'])){
  787. $where .= " and sqr = '".$data['sqr']."' ";
  788. }
  789. if(!empty($data['shop_id'])){
  790. $where .= " and shop_id = ".$data['shop_id']." ";
  791. }
  792. if(!empty($data['plat_id'])){
  793. $where .= " and plat_id = ".$data['plat_id']." ";
  794. }
  795. if(!empty($data['sku'])){
  796. $where .= " and sku = '".$data['sku']."' ";
  797. }
  798. $order_str = "id desc";
  799. $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
  800. $shop_list = $this->shop->find_all("1=1","id,shopname");
  801. $shop_list = array_column($shop_list,'shopname','id');
  802. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  803. $plat_list = array_column($plat_list,'title','id');
  804. foreach($list as $k=>$v){
  805. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  806. $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
  807. $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
  808. }
  809. if(empty($list)){
  810. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  811. }else{
  812. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  813. }
  814. }else{
  815. $data = $this->input->get();
  816. $this->data['id'] = $data['id'];
  817. $this->data['bh_no'] = $data['bh_no'];
  818. $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
  819. $this->data['plat_list'] = $plat_list;
  820. $this->_Template('beihuogl_ccwleditxzbh',$this->data);
  821. }
  822. }
  823. private function _ccwlbhsave(){
  824. if($this->input->method() === 'post'){
  825. $data = $this->input->post();
  826. $id = $data['id'];
  827. $val = $data['val'];
  828. $column = $data['column'];
  829. $update_arr = [];
  830. if($column == 'status'){
  831. $update_arr = [
  832. 'status'=>(int)$val,
  833. 'update_time'=>time(),
  834. 'public_time'=>time(),
  835. ];
  836. }else{
  837. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  838. }
  839. $r = $this->bhccwl->save($update_arr,$id);
  840. if($r){
  841. echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
  842. }else{
  843. echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
  844. }
  845. }else{
  846. echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
  847. }
  848. }
  849. //仓库的备货单列表
  850. private function _ckbhindex(){
  851. if($this->input->method() === 'post'){
  852. $page = $this->input->post('page',true);
  853. $perpage = $this->input->post('perpage',true);
  854. $bh_no = $this->input->post('bh_no',true);
  855. $status = $this->input->post('status',true);
  856. $ktime = $this->input->post('ktime',true);
  857. $jtime = $this->input->post('jtime',true);
  858. $ktime = strtotime($ktime);
  859. $jtime = strtotime($jtime);
  860. $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
  861. if(!empty($bh_no)){
  862. $where .= " and bh_no = '".$bh_no."' ";
  863. }
  864. if($status > -1){
  865. $where .= " and status = ".$status." ";
  866. }
  867. //数据排序
  868. $order_str = "id desc";
  869. if(empty($page))
  870. {
  871. $start = 0;
  872. $perpage = 1;
  873. }
  874. else
  875. {
  876. $start = ($page - 1)*$perpage;
  877. }
  878. $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
  879. if(empty($list)){
  880. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  881. echo json_encode($rows);exit;
  882. }
  883. $status_list = $this->bhccwl->getCkStatus();
  884. foreach($list as $k=>$v){
  885. $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
  886. $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
  887. $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
  888. $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
  889. $str = "";
  890. if($v['ck_status'] == 0){
  891. $str .= "<div style='text-align:center;'>";
  892. $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>";
  893. // $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>";
  894. $str .= "</div>";
  895. }
  896. if($v['ck_status'] == 1 || $v['ck_status'] == 2){
  897. $str .= "<div style='text-align:center;'>";
  898. $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>";
  899. $str .= "</div>";
  900. }
  901. $list[$k]['update_time'] = $str;
  902. }
  903. $total = $this->bhccwl->find_count($where);
  904. $pagenum = ceil($total/$perpage);
  905. $over = $total-($start+$perpage);
  906. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  907. echo json_encode($rows);exit;
  908. }else{
  909. $this->_Template('beihuogl_ckbhindex',$this->data);
  910. }
  911. }
  912. private function _ckbhedit($arg_array){
  913. if($this->input->method() === 'post'){
  914. $id = $this->input->post('id',true);
  915. $bh_no = $this->input->post('bh_no',true);
  916. $info = $this->bhccwl->read($id);
  917. if(empty($info)){
  918. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  919. }
  920. if($info['ck_status'] == 0 && $info['status'] == 1){
  921. }else{
  922. echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
  923. }
  924. if($info['bh_no'] != $bh_no){
  925. echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
  926. }
  927. $num = 0;
  928. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  929. foreach($list as $k=>$v){
  930. $num += $v['ck_num'];
  931. }
  932. $r = $this->bhccwl->save([
  933. 'ck_status'=>1,
  934. 'ck_num'=>$num,
  935. 'update_time'=>time(),
  936. 'ckpublic_time'=>time(),
  937. ],$id);
  938. if($r){
  939. echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
  940. }else{
  941. echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
  942. }
  943. }else{
  944. $id = $arg_array[0];
  945. $info = $this->bhccwl->find("id = ".$id);
  946. $status_list = $this->bhccwl->getCkStatus();
  947. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  948. $drck_list = $this->bhccwl->getDrck();
  949. $this->data['drck_list'] = $drck_list;
  950. $this->data['drck_json'] = json_encode($drck_list);
  951. $this->data['info'] = $info;
  952. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
  953. $shop_list = $this->shop->find_all("1=1","id,shopname");
  954. $shop_list = array_column($shop_list,'shopname','id');
  955. foreach($list as $k=>$v){
  956. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  957. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  958. }
  959. $this->data['list'] = $list;
  960. $this->_Template('beihuogl_ckbhedit',$this->data);
  961. }
  962. }
  963. private function _makeu9scd($arg_array){
  964. if($this->input->method() === 'post'){
  965. $data = $this->input->post(null,true);
  966. $info = $this->bhccwl->read($data['id']);
  967. if(empty($info)){
  968. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  969. }
  970. if($info['ck_status'] == 1 && $info['status'] == 1){
  971. }else{
  972. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  973. exit;
  974. }
  975. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
  976. $params = [
  977. 'org_code'=>"120",//组织代码 龙盈工厂
  978. 'djhlx'=>'2000',//单号类型 备货生产单
  979. 'scbm_code'=>"12008",//龙盈生产部门
  980. "time"=>time(),
  981. 'owner_org_code'=>"120",
  982. 'title'=>$info['bh_no'],
  983. 'shipremarks'=>$info['bh_no'],
  984. ];
  985. $final_list = [];
  986. foreach($list as $k=>$v){
  987. $final_list[] =[
  988. 'do_id'=>$v['id'],
  989. 'drck'=>$v['drck'],
  990. 'jm'=>$v['jm'],
  991. 'sl'=>$v['ck_num'],
  992. ];
  993. }
  994. $params['list'] = $final_list;
  995. $token = $this->settingtest->get_yytoken_120();
  996. $res = $this->apiyyv1->scdCreate($params,$token);
  997. if(empty($res[0]['Data'])){
  998. $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
  999. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1000. }
  1001. $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
  1002. $r_s_list = $res[0]['Data'];
  1003. foreach($list as $k=>$v){
  1004. $list[$k]['u9_data'] = $r_s_list[$k];
  1005. }
  1006. //m_isSucess
  1007. $flag_status = 0;//判断是否有创建失败的
  1008. $u9sc_status = 0;//判断是否有创建成功的
  1009. foreach($list as $k=>$v){
  1010. if($v['u9_data']['m_isSucess']== 1){
  1011. $u9sc_status += 1;
  1012. $this->bhsq->save([
  1013. 'is_u9sc'=>1,
  1014. 'u9sc_no'=>$v['u9_data']['m_code'],
  1015. ],$v['id']);
  1016. }else{
  1017. $flag_status += 0;
  1018. $this->bhsq->save([
  1019. 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
  1020. ],$v['id']);
  1021. }
  1022. }
  1023. $len = count($list);
  1024. //都创建失败了 就直接gg
  1025. if($u9sc_status == 0){
  1026. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1027. }
  1028. if(($u9sc_status < $len) && ( $flag_status< $len) ){
  1029. $this->bhccwl->save([
  1030. 'ck_status'=>2,
  1031. ],$info['id']);
  1032. echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
  1033. }
  1034. if($u9sc_status == $len){
  1035. $this->bhccwl->save([
  1036. 'ck_status'=>3,
  1037. ],$info['id']);
  1038. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1039. }
  1040. echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
  1041. }else{
  1042. $id = $arg_array[0];
  1043. $info = $this->bhccwl->read($id);
  1044. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1045. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1046. $shop_list = array_column($shop_list,'shopname','id');
  1047. $drck_list = $this->bhccwl->getDrck();
  1048. $status_list = $this->bhccwl->getCkStatus();
  1049. $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
  1050. foreach($list as $k=>$v){
  1051. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1052. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1053. }
  1054. $this->data['list'] = $list;
  1055. $this->data['info'] = $info;
  1056. $this->_Template('beihuogl_makeu9scd',$this->data);
  1057. }
  1058. }
  1059. private function _ddscscd(){
  1060. if($this->input->method() === 'post'){
  1061. $id = $this->input->post('id',true);
  1062. $bh_no = $this->input->post('bh_no',true);
  1063. $bhsq_info = $this->bhsq->read($id);
  1064. $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
  1065. if(empty($bhccwl_info)){
  1066. echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
  1067. }
  1068. // if($bhccwl_info['ck_status'] != 1){
  1069. // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1070. // exit;
  1071. // }
  1072. if(!in_array($bhccwl_info['ck_status'],[1,2])){
  1073. echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
  1074. exit;
  1075. }
  1076. if(!empty($bhsq_info['u9sc_no'])){
  1077. echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
  1078. exit;
  1079. }
  1080. $params = [
  1081. 'org_code'=>"120",//组织代码 龙盈工厂
  1082. 'djhlx'=>'2000',//单号类型 备货生产单
  1083. 'scbm_code'=>"12008",//龙盈生产部门
  1084. "time"=>time(),
  1085. 'owner_org_code'=>"120",
  1086. 'title'=>$bhccwl_info['bh_no'],
  1087. 'shipremarks'=>$bhccwl_info['bh_no'],
  1088. ];
  1089. $list[] = [
  1090. 'do_id'=>$bhsq_info['id'],
  1091. 'drck'=>$bhsq_info['drck'],
  1092. 'jm'=>$bhsq_info['jm'],
  1093. 'sl'=>$bhsq_info['ck_num'],
  1094. ];
  1095. $params['list'] = $list;
  1096. $token = $this->settingtest->get_yytoken_120();
  1097. $res = $this->apiyyv1->scdCreate($params,$token);
  1098. if(empty($res[0]['Data'])){
  1099. echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
  1100. }
  1101. if($res[0]['Data'][0]['m_isSucess']== 1){
  1102. $this->bhsq->save([
  1103. 'is_u9sc'=>1,
  1104. 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
  1105. ],$bhsq_info['id']);
  1106. $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
  1107. if(empty($tmp_list)){
  1108. $tmp_status = 3;
  1109. }else{
  1110. $tmp_status = 2;
  1111. }
  1112. $this->bhccwl->save([
  1113. 'ck_status'=>$tmp_status,
  1114. ],$bhccwl_info['id']);
  1115. echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
  1116. }else{
  1117. $this->bhsq->save([
  1118. 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
  1119. ],$bhsq_info['id']);
  1120. echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
  1121. }
  1122. }else{
  1123. exit('No direct script access allowed');
  1124. }
  1125. }
  1126. private function _showckbh($arg_array){
  1127. if($this->input->method() === 'post'){
  1128. exit('No direct script access allowed');
  1129. }
  1130. $id = $arg_array[0];
  1131. $drck_list = $this->bhccwl->getDrck();
  1132. $shop_list = $this->shop->find_all("1=1","id,shopname");
  1133. $shop_list = array_column($shop_list,'shopname','id');
  1134. $info = $this->bhccwl->read($id);
  1135. $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
  1136. $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
  1137. foreach($list as $k=>$v){
  1138. $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
  1139. $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
  1140. }
  1141. $this->data['info'] = $info;
  1142. $this->data['list'] = $list;
  1143. $this->data['list_dcd'] = $list_dcd;
  1144. $this->_Template('beihuogl_showckbh',$this->data);
  1145. }
  1146. //仓库录入调出单
  1147. private function _ckdcd(){
  1148. if($this->input->method() === 'post'){
  1149. $lrdcd = $this->input->post('lrdcd',true);
  1150. if(empty($lrdcd)){
  1151. //列表展示
  1152. $page = $this->input->post('page',true);
  1153. $perpage = $this->input->post('perpage',true);
  1154. $bh_no = $this->input->post('bh_no',true);
  1155. $dcd_no = $this->input->post('dcd_no',true);
  1156. $status = $this->input->post('status',true);
  1157. $ktime = $this->input->post('ktime',true);
  1158. $jtime = $this->input->post('jtime',true);
  1159. $ktime = strtotime($ktime);
  1160. $jtime = strtotime($jtime);
  1161. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  1162. if(!empty($bh_no)){
  1163. $where .= " and bh_no = '".$bh_no."' ";
  1164. }
  1165. if($status > -1){
  1166. $where .= " and status = ".$status." ";
  1167. }
  1168. if(!empty($dcd_no)){
  1169. $where .= " and dcd_no = '".$dcd_no."' ";
  1170. }
  1171. //数据排序
  1172. $order_str = "id desc";
  1173. if(empty($page))
  1174. {
  1175. $start = 0;
  1176. $perpage = 1;
  1177. }
  1178. else
  1179. {
  1180. $start = ($page - 1)*$perpage;
  1181. }
  1182. $list = $this->bhdcd->find_all($where,"id,bh_no,dcd_no,drd_no,status,jm,num,kw,create_time",$order_str,$start,$perpage);
  1183. if(empty($list)){
  1184. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  1185. echo json_encode($rows);exit;
  1186. }
  1187. $status_list = $this->bhdcd->getStatus();
  1188. foreach($list as $k=>$v){
  1189. $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>";
  1190. $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1191. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1192. $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
  1193. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1194. }
  1195. $total = $this->bhdcd->find_count($where);
  1196. $pagenum = ceil($total/$perpage);
  1197. $over = $total-($start+$perpage);
  1198. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1199. echo json_encode($rows);exit;
  1200. }else{
  1201. if(empty($lrdcd)){
  1202. echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
  1203. }
  1204. $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
  1205. if(!empty($num)){
  1206. echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
  1207. }
  1208. //查询录入执行的调出单
  1209. $token = $this->settingtest->get_yytoken_120();
  1210. $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
  1211. if(empty($res[0]['Data'])){
  1212. echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
  1213. }
  1214. $time = time();
  1215. $final_list = [];
  1216. foreach($res[0]['Data'] as $k=>$v){
  1217. $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
  1218. $tmp_sku = '';
  1219. $tmp_title = '';
  1220. $tmp_features = '';
  1221. $tmp_number='';
  1222. if(!empty($good_info)){
  1223. $tmp_sku = $good_info['sku'];
  1224. $tmp_title = $good_info['title'];
  1225. $tmp_features = $good_info['features'];
  1226. $tmp_number = str_replace("-","", $good_info['features']);
  1227. }
  1228. $final_list[] = [
  1229. 'sku'=>$tmp_sku,
  1230. 'dcd_no'=>$v['docno'],
  1231. 'jm'=>$v['iteminfo_itemcode'],
  1232. 'zh'=>$v['iteminfo_itemname'],
  1233. 'num'=>$v['costuomqty'],
  1234. 'real_num'=>$v['costuomqty'],
  1235. 'bh_no'=>$v['erp_no'],
  1236. 'create_time'=>$time,
  1237. 'title'=>$tmp_title,
  1238. 'features'=>$tmp_features,
  1239. 'number'=>$tmp_number,
  1240. ];
  1241. }
  1242. $r =$this->db->insert_batch('bhdcd',$final_list);
  1243. if($r){
  1244. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1245. }else{
  1246. echo json_encode(['success'=>false,'msg'=>'录入失败']);
  1247. }
  1248. exit;
  1249. }
  1250. }else{
  1251. $status_list = $this->bhdcd->getStatus();
  1252. $this->data['status_list'] = $status_list;
  1253. $this->_Template('beihuogl_ckdcd',$this->data);
  1254. }
  1255. }
  1256. private function _ckbherprk($arg_array){
  1257. if($this->input->method() === 'post'){
  1258. $data = $this->input->post(null,true);
  1259. $dcd_no = $data['dcd_no'];
  1260. $drd_no = $data['drd_no'];
  1261. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and drd_no = '".$drd_no."'");
  1262. $whlabel_arr = [];
  1263. $time = time();
  1264. foreach($list as $k=>$v){
  1265. for($i=0;$i<$v['num'];$i++){
  1266. $whlabel_arr[] = [
  1267. 'sku'=>$v['sku'],
  1268. 'number'=>$v['number'],
  1269. 'features'=>$v['features'],
  1270. 'title'=>$v['title'],
  1271. 'zh'=>$v['zh'],
  1272. 'warehouse'=>'13',
  1273. 'enter'=>$time,
  1274. 'state'=>0,
  1275. 'retreatwarehouse'=>'13',
  1276. 'time'=>$time,
  1277. 'details'=>$v['kw'],
  1278. 'bs'=>1,
  1279. 'rktype'=>9,
  1280. ];
  1281. }
  1282. }
  1283. $this->db->trans_start();
  1284. $this->db->insert_batch('whlabel',$whlabel_arr);
  1285. $this->db->where('dcd_no',$dcd_no);
  1286. $this->db->where('drd_no',$drd_no);
  1287. $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time]);
  1288. if($this->db->trans_status() === FALSE){
  1289. $this->db->trans_rollback();
  1290. echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
  1291. }else{
  1292. $this->db->trans_commit();
  1293. echo json_encode(['success'=>true,'msg'=>'录入成功']);
  1294. }
  1295. }else{
  1296. $dcd_no = $arg_array[0];
  1297. $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
  1298. $jm_list = array_column($list,'jm');
  1299. $status_list = $this->bhdcd->getStatus();
  1300. $in_where = "( ";
  1301. foreach($jm_list as $k=>$v){
  1302. $in_where .= "'".$v."',";
  1303. }
  1304. $in_where = rtrim($in_where,",");
  1305. $in_where .= " )";
  1306. foreach($list as $k=>$v){
  1307. $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
  1308. $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
  1309. if(!empty($v['kw'])){
  1310. $list[$k]['kw'] = $v['kw'];
  1311. }else{
  1312. if(!empty($list[$k]['sku'])){
  1313. $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
  1314. if(!empty($whlabel_info)){
  1315. if(!empty($whlabel_info['details'])){
  1316. $list[$k]['kw'] = $whlabel_info['details'];
  1317. $this->bhdcd->save([
  1318. 'kw'=>$whlabel_info['details'],
  1319. ],$v['id']);
  1320. }else{
  1321. $list[$k]['kw'] = "";
  1322. }
  1323. }else{
  1324. $list[$k]['kw'] = "";
  1325. }
  1326. }else{
  1327. $list[$k]['kw'] = "";
  1328. }
  1329. }
  1330. $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
  1331. }
  1332. $this->data['list'] = $list;
  1333. $this->_Template('beihuogl_ckbherprk',$this->data);
  1334. }
  1335. }
  1336. private function _bhdcdsave(){
  1337. if($this->input->method() === 'post'){
  1338. $id = $this->input->post('id',true);
  1339. $val = $this->input->post('val',true);
  1340. $column = $this->input->post('column',true);
  1341. $info = $this->bhdcd->read($id);
  1342. $update_arr = [];
  1343. if($column == 'real_num'){
  1344. if($val > $info['num']){
  1345. echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
  1346. }
  1347. $update_arr = [
  1348. 'real_num'=>(int)$val,
  1349. ];
  1350. }elseif($column == 'kw'){
  1351. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
  1352. if(!empty($winfo)){
  1353. $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
  1354. if(empty($winfo)){
  1355. echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
  1356. }
  1357. }
  1358. $update_arr = [
  1359. 'kw'=>trim($val),
  1360. ];
  1361. }else{
  1362. echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
  1363. }
  1364. $r = $this->bhdcd->save($update_arr,$id);
  1365. if($r){
  1366. echo json_encode(['success'=>true,'msg'=>'保存成功']);
  1367. }else{
  1368. echo json_encode(['success'=>false,'msg'=>'保存失败']);
  1369. }
  1370. }else{
  1371. echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
  1372. }
  1373. }
  1374. }