Beihuogl.php 80 KB

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