| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Beihuogl extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
- $this->load->_model('Model_bhsq','bhsq');
- $this->load->_model("Model_shop","shop");
- $this->load->_model("Model_typeclass","typeclass");
- $this->load->_model("Model_bhccwl","bhccwl");
- $this->load->_model("Model_logic_u9tools","logic_u9tools");
- $this->load->_model("Model_whlabel","whlabel");
- $this->load->_model("Model_goods","goods");
- $this->load->_model("Model_settingtest","settingtest");
- $this->load->_model("Model_bhdcd","bhdcd");
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if(!isset($_SESSION['api'])){
- header('Location: /');exit;
- }
- if($arg == 'dyapply')//
- {
- $this->_dyapply();
- }
- elseif($arg == 'dyapplyadd')//
- {
- $this->_dyapplyadd();
- }
- elseif($arg == 'dyapplyedit')//
- {
- $this->_dyapplyedit($arg_array);
- }
- elseif($arg == 'dyapplygxzt')//
- {
- $this->_dyapplygxzt();
- }
- elseif($arg == 'dyapplyexcel'){
- $this->_dyapplyexcel();
- }
- elseif($arg == 'ccwlshlist'){
- $this->_ccwlshlist();
- }
- elseif($arg == 'ccwlbhindex'){
- $this->_ccwlbhindex();
- }elseif($arg == 'dyapplysave'){
- $this->_dyapplysave();
- }elseif($arg == 'ccwlbhmake'){
- $this->_ccwlbhmake();
- }elseif($arg == 'ccwlbhedit'){
- $this->_ccwlbhedit($arg_array);
- }elseif($arg == 'ccwleditxzbh'){
- $this->_ccwleditxzbh();
- }elseif($arg == 'ccwlbhsavexzbh'){
- $this->_ccwlbhsavexzbh();
- }elseif($arg == 'ccwldelitem'){
- $this->_ccwldelitem();
- }elseif($arg == 'ccwlbhsave'){
- $this->_ccwlbhsave();
- }elseif($arg == 'ckbhindex'){
- $this->_ckbhindex();
- }elseif($arg == 'ckbhedit'){
- $this->_ckbhedit($arg_array);
- }elseif($arg == 'makeu9scd'){
- $this->_makeu9scd($arg_array);
- }elseif($arg == 'showckbh'){
- $this->_showckbh($arg_array);
- }elseif($arg == 'ddscscd'){
- $this->_ddscscd();
- }elseif($arg == 'ckdcd'){
- $this->_ckdcd();
- }elseif($arg == 'ckbherprk'){
- $this->_ckbherprk($arg_array);
- }elseif($arg == 'bhdcdsave'){
- $this->_bhdcdsave();
- }elseif($arg == 'u9scdexcel')
- {
- $this->_u9scdexcel($arg_array);
- }
- else
- {
- $this->_index();
- }
- }
-
- private function _index(){
- exit('No direct script access allowed 1');
- }
- //备货申请单的列表
- private function _dyapply(){
- if($this->input->method() === 'post'){
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $sqr = $this->input->post('sqr',true);
- $sqr = trim($sqr);
- $shop_id = $this->input->post('shop_id',true);
- $plat_id = $this->input->post('plat_id',true);
- $shop_ids = $this->input->post('shop_ids',true);
- $ktime = $this->input->post('ktime',true);
- $jtime = $this->input->post('jtime',true);
- $ktime = strtotime($ktime);
- $jtime = strtotime($jtime);
- $where = "add_time >= ".$ktime." and add_time < ".$jtime." ";
- if(!empty($sqr)){
- $where .= " and sqr = ".$sqr." ";
- }
- if(!empty($shop_id)){
- $where .= " and shop_id = ".$shop_id." ";
- }else{
- $where .= " and shop_id in (".$shop_ids.") ";
- }
- if(!empty($plat_id)){
- $where .= " and plat_id = ".$plat_id." ";
- }
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- $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);
- if(empty($list)){
- $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
- echo json_encode($rows);exit;
- }
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- $plat_list = $this->typeclass->find_all("classid = 32","id,title");
- $plat_list = array_column($plat_list,'title','id');
- $status_list = $this->bhsq->getSqStatus();
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
- $list[$k]['sq_status'] = isset($status_list[$v['sq_status']])?$status_list[$v['sq_status']]:"";
- $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
- $str = "";
- if($v['sq_status'] == 1 || $v['sq_status'] == 3){
- $str .= "<div style='text-align:center;'>";
- $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>";
- $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>";
- $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>";
- $str .= "</div>";
- }
- $list[$k]['update_time'] = $str;
- }
- $total = $this->bhsq->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
- echo json_encode($rows);exit;
-
-
- }else{
- $user = $this->user->get_api($_SESSION['api']);
- $usersp = explode('|',trim($user['shop'],'|'));
- $this->data['usersp'] = implode(",",$usersp);
- $this->_Template('beihuogl_dyapply',$this->data);
- }
- }
- //备货申请单的添加
- private function _dyapplyadd(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $time = strtotime(date("Y-m-d"),time());
- $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
- if(empty($info)){
- $num = 1;
- }else{
- $arr = explode('-',$info['sb_no']);
- $num = (int)$arr[2]+1;
- }
- $num = str_pad($num, 3, '0', STR_PAD_LEFT);
- $sb_no = "SQ-".date("ymd")."-".$num;
- $insert_arr = [];
- $time = time();
- foreach($data['title'] as $k=>$v){
- $insert_arr[] = [
- 'sb_no'=>$sb_no,
- 'sku'=>$data['sku'][$k],
- 'title'=>$data['title'][$k],
- 'shop_id'=>$data['shop_id'],
- 'plat_id'=>$data['plat_id'],
- 'sqr'=>$data['sqr'],
- 'sq_num'=>$data['sq_num'][$k],
- 'ccwl_num'=>$data['sq_num'][$k],
- 'ck_num'=>$data['sq_num'][$k],
- 'sq_status'=>1,
- 'remark'=>$data['remark'],
- 'add_time'=>$time,
- 'real_time'=>$time,
- 'update_time'=>$time,
- ];
- }
- $r =$this->db->insert_batch('bhsq',$insert_arr);
- if($r){
- echo json_encode(['code'=>1,'msg'=>'添加成功']);
- }else{
- echo json_encode(['code'=>-1,'msg'=>'添加失败']);
- }
- exit;
- }else{
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $this->data['plat_list'] = $plat_list;
- $this->_Template('beihuogl_dyapplyadd',$this->data);
- }
- }
- //备货申请单的 修改
- private function _dyapplyedit($arg_array){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $id = $data['id'];
- $update_arr = [
- 'shop_id'=>$data['shop_id'],
- 'plat_id'=>$data['plat_id'],
- 'sqr'=>$data['sqr'],
- 'sq_num'=>$data['sq_num'],
- 'ccwl_num'=>$data['sq_num'],
- 'ck_num'=>$data['sq_num'],
- 'sku'=>$data['sku'],
- 'remark'=>$data['remark'],
- ];
- $r = $this->bhsq->save($update_arr,$id);
- if($r){
- echo json_encode(['msg'=>'添加成功','success'=>true]);
- }else{
- echo json_encode(['msg'=>'添加失败','success'=>false]);
- }
- exit;
- }else{
- $id = $arg_array[0];
- $info = $this->bhsq->find("id = ".$id);
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $this->data['plat_list'] = $plat_list;
- $this->data['info'] = $info;
- $this->_Template('beihuogl_dyapplyedit',$this->data);
- }
- }
- //备货申请单的 状态申请 如 发布 或者取消
- private function _dyapplygxzt(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $id = (int)$data['id'];
- $type = (int)$data['status'];
- $update_arr = [];
- $update_arr['sq_status'] = $type;
- if($type == 2){
- $update_arr['public_time'] = time();
- }
- $r = $this->bhsq->save($update_arr,$id);
- if($r){
- echo json_encode(['msg'=>'修改成功','success'=>true]);
- }else{
- echo json_encode(['msg'=>'修改失败','success'=>false]);
- }
- exit;
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);
- }
- }
- //备货申请单的
- private function _dyapplysave(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $id = (int)$data['id'];
- $val = $this->input->post('val',true);
- $column = $data['column'];
- if($column == 'ccwl_num'){
- $update_arr = [
- 'ccwl_num'=>(int)$val,
- 'ck_num'=>(int)$val,
- ];
- }elseif($column == 'sku'){
- $update_arr = [
- 'sku'=>$val,
- ];
- }elseif($column == 'ck_num'){
- $update_arr = [
- 'ck_num'=>(int)$val,
- ];
- }elseif($column == 'drck'){
- $update_arr = [
- 'drck'=>(int)$val,
- ];
- }else{
- echo json_encode(['msg'=>'修改信息不合规','success'=>false]);
- exit;
- }
- $r = $this->bhsq->save($update_arr,$id);
- if($r){
- echo json_encode(['msg'=>'修改成功','success'=>true]);
- }else{
- echo json_encode(['msg'=>'修改失败','success'=>false]);
- }
- exit;
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);
- }
- }
- private function _dyapplyexcel(){
- if($this->input->method() === 'post'){
- $data = $this->input->post('list',true);
- if(empty($data)){
- $json_data = $this->input->raw_input_stream;
- $tmp_data = json_decode($json_data,true);
- $data = $tmp_data['list'];
- if(empty($data)){
- echo json_encode(['success'=>false,'msg'=>'未获取要保存的数据']);
- exit;
- }
-
- }
-
- $shop_list = $this->shop->find_all("1=1","id,shortname,type");
- $shop_list = array_column($shop_list,null,'shortname');
-
- $time = strtotime(date("Y-m-d"),time());
- $info = $this->bhsq->find("real_time >= ".$time,"*",'id desc');
- if(empty($info)){
- $num = 1;
- }else{
- $arr = explode('-',$info['sb_no']);
- $num = (int)$arr[2]+1;
- }
- $time = time();
- $num = str_pad($num, 3, '0', STR_PAD_LEFT);
- $sb_no = "SQ-".date("ymd")."-".$num;
- $insert_arr = [];
- $error_list= [];
- foreach($data as $k=>$v){
- $shopshortname = trim($v[4]);
- $shop_info = isset($shop_list[$shopshortname])?$shop_list[$shopshortname]:[];
- if(empty($shop_info)){
- $error_list[] = [
- 'msg'=>"第".($k+1).'行店铺不存在,请核对表格信息'.$shopshortname,
- ];
- continue;
- }
- $num = (int)$v[3];
- if(empty($num)){
- $error_list[] = [
- 'msg'=>"第".($k+1).'行数量不能为空,请核对表格信息',
- ];
- continue;
- }
- $tmp_time = trim($v[0]);
- if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $tmp_time)) {
- $add_time = strtotime($tmp_time);
- }else{
- $error_list[] = [
- 'msg'=>"第".($k+1).'行日期格式不正确,请核对表格信息',
- ];
- continue;
- }
- if(empty($v[5])){
- $error_list[] = [
- 'msg'=>"第".($k+1).'行申请人信息不能为空,请核对表格信息',
- ];
- continue;
- }
- if(empty($v[1])){
- $error_list[] = [
- 'msg'=>"第".($k+1).'行产品信息不能为空,请核对表格信息',
- ];
- continue;
- }
- $insert_arr[] = [
- 'sb_no'=>$sb_no,
- 'sku'=>trim($v[2]),
- 'title'=>trim($v[1]),
- 'shop_id'=>$shop_info['id'],
- 'plat_id'=>$shop_info['type'],
- 'sqr'=>trim($v[5]),
- 'sq_num'=>$num,
- 'ccwl_num'=>$num,
- 'ck_num'=>$num,
- 'sq_status'=>1,
- 'remark'=>$v[6],
- 'add_time'=>$add_time,
- 'real_time'=>$time,
- 'update_time'=>$time,
- ];
- }
- $r =$this->db->insert_batch('bhsq',$insert_arr);
- if($r){
- echo json_encode(['success'=>true,'msg'=>'添加成功','error_list'=>$error_list]);
- }else{
- echo json_encode(['success'=>false,'msg'=>'添加失败','error_list'=>$error_list]);
- }
- exit;
- }else{
- echo json_encode(['success'=>true,'msg'=>'请求失败']);
- exit;
- }
- }
- //仓储物流部的备货申请单的列表
- private function _ccwlshlist(){
- if($this->input->method() === 'post'){
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $sqr = $this->input->post('sqr',true);
- $sqr = trim($sqr);
- $shop_id = $this->input->post('shop_id',true);
- $plat_id = $this->input->post('plat_id',true);
- $shop_ids = $this->input->post('shop_ids',true);
- $ktime = $this->input->post('ktime',true);
- $jtime = $this->input->post('jtime',true);
- $ktime = strtotime($ktime);
- $jtime = strtotime($jtime);
- $where = "sq_status = 2 and ccwl_status = 0 ";
- $where .= " and add_time >= ".$ktime." and add_time < ".$jtime." ";
- if(!empty($sqr)){
- $where .= " and sqr = ".$sqr." ";
- }
- if(!empty($shop_id)){
- $where .= " and shop_id = ".$shop_id." ";
- }else{
- $where .= " and shop_id in (".$shop_ids.") ";
- }
- if(!empty($plat_id)){
- $where .= " and plat_id = ".$plat_id." ";
- }
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- $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);
- if(empty($list)){
- $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
- echo json_encode($rows);exit;
- }
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- $plat_list = $this->typeclass->find_all("classid = 32","id,title");
- $plat_list = array_column($plat_list,'title','id');
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
- $list[$k]['add_time'] = date("Y-m-d",$v['add_time']);
- $list[$k]['sku'] = $v['sku']." <i class='fa fa-edit' data-id='".$v['id']."' data-sku='".$v['sku']."' onclick='edit_sku(this)'></i>";
- $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>";
- $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>";
- }
- $total = $this->bhsq->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
- echo json_encode($rows);exit;
- }else{
- $user = $this->user->get_api($_SESSION['api']);
- $usersp = explode('|',trim($user['shop'],'|'));
- $this->data['usersp'] = implode(",",$usersp);
- $this->_Template('beihuogl_ccwlshlist',$this->data);
- }
- }
- //仓储物流合成备货单
- private function _ccwlbhmake(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $bh_no = $data['bh_no'];
- $select_id = $data['arr_id'];
- if(empty($select_id)){
- echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
- exit;
- }
- if(empty($bh_no)){
- $tmp_time = strtotime(date("Y-m-d"),time());
- $num = $this->bhccwl->find_count("create_time >= ".$tmp_time);
- $num = $num+1;
- $num = str_pad($num, 3, '0', STR_PAD_LEFT);
- $bh_no = "BH-".date("ymd")."-".$num;
- }
- $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).')');
- foreach($list as $k=>$v){
- if(empty($v['sku'])){
- echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
- exit;
- }
- }
- $classid = $this->logic_u9tools->getClass();
- $typeclass = $this->logic_u9tools->getTypeClass();
- foreach($list as $k=>$v){
- $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
- if(empty($whlabel_info)){
- $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
- if(empty($whlabel_info)){
- echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
- exit;
- }
-
- $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
-
- $this->bhsq->save([
- 'jm'=>$r['jm'],
- 'drck'=>$this->getU9Drck($whlabel_info['features']),
- 'features'=>$whlabel_info['features'],
- ],$v['id']);
- }else{
- $this->bhsq->save([
- 'jm'=>$whlabel_info['jm'],
- 'drck'=>$this->getU9Drck($whlabel_info['features']),
- 'features'=>$whlabel_info['features'],
- ],$v['id']);
- }
-
- }
- $this->db->trans_start();
- $this->db->where_in('id',$select_id);
- $this->db->update('bhsq',[
- 'bh_no'=>$bh_no,
- 'sq_status'=>4,
- 'ccwl_status'=>1,
- ]);
- $this->db->select('SUM(ccwl_num) as total_ccwl_num');
- $this->db->where_in('id',$select_id);
- $query = $this->db->get('bhsq');
- $result = $query->row();
- $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
- $time = time();
- $this->bhccwl->insert([
- 'bh_no'=>$bh_no,
- 'status'=>0,
- 'num'=>$total_ccwl_num,
- 'create_time'=>$time,
- 'update_time'=>$time,
- ]);
- if($this->db->trans_status() === FALSE){
- $this->db->trans_rollback();
- echo json_encode(['success'=>false,'msg'=>'生成备货单失败']);
- exit;
- }else{
- $this->db->trans_commit();
- echo json_encode(['success'=>true,'msg'=>'生成备货单成功']);
- exit;
- }
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);
- exit;
- }
- }
- private function getU9Drck($features){
- if(stripos($features,'-126-') !== false)
- {
- $drck = '12003';//进入发条库
- }
- else if(stripos($features,'-127-') !== false)
- {
- $drck = '12004';//进入发块库
- }
- else
- {
- $drck = '12006';//其它进入完成库
- }
- return $drck;
- }
- //仓储物流部的备货单列表
- private function _ccwlbhindex(){
- if($this->input->method() === 'post'){
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $bh_no = $this->input->post('bh_no',true);
- $status = $this->input->post('status',true);
- $ktime = $this->input->post('ktime',true);
- $jtime = $this->input->post('jtime',true);
- $ktime = strtotime($ktime);
- $jtime = strtotime($jtime);
- $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
- if(!empty($bh_no)){
- $where .= " and bh_no = '".$bh_no."' ";
- }
- if($status > -1){
- $where .= " and status = ".$status." ";
- }
-
-
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- $list = $this->bhccwl->find_all($where,"id,bh_no,status,create_time,public_time,update_time",$order_str,$start,$perpage);
- if(empty($list)){
- $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
- echo json_encode($rows);exit;
- }
- $status_list = $this->bhccwl->getStatus();
- foreach($list as $k=>$v){
- $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
- $list[$k]['create_time'] = date("Y-m-d",$v['create_time']);
- $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
-
- $str = "";
- if($v['status'] == 0){
- $str .= "<div style='text-align:center;'>";
- $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>";
- $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>";
- $str .= "</div>";
- }
- $list[$k]['update_time'] = $str;
- }
- $total = $this->bhccwl->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
- echo json_encode($rows);exit;
- }else{
- $this->_Template('beihuogl_ccwlbhindex',$this->data);
- }
- }
- //仓储物流部备货 在编辑页面添加数据
- private function _ccwlbhsavexzbh(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $select_id = $data['select_id'];
- $id = $data['id'];
- $bh_no = $data['bh_no'];
- if(empty($select_id)){
- echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
- exit;
- }
- $info = $this->bhccwl->read($id);
- if(empty($info)){
- echo json_encode(['success'=>false,'msg'=>'数据不存在']);
- exit;
- }
- if($info['bh_no'] != $bh_no){
- echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);
- exit;
- }
- $bh_no = $info['bh_no'];
- $list = $this->bhsq->find_all('id in ('.implode(',',$select_id).') ' );
- foreach($list as $k=>$v){
- if(empty($v['sku'])){
- echo json_encode(['success'=>false,'msg'=>'提交的数据中有的sku为空,请核对填写信息']);
- exit;
- }
- if(!empty($v['bh_no'])){
- echo json_encode(['success'=>false,'msg'=>'提交的数据中有的已经被调用,请联系技术核对']);
- exit;
- }
- }
- $classid = $this->logic_u9tools->getClass();
- $typeclass = $this->logic_u9tools->getTypeClass();
- foreach($list as $k=>$v){
- $whlabel_info = $this->goods->find("sku = '".$v['sku']."'",'sku,features,jm','id desc');
- if(empty($whlabel_info)){
- $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
- if(empty($whlabel_info)){
- echo json_encode(['success'=>false,'msg'=>$v['sku'].'未在进销存浏览那找到对应信息']);
- exit;
- }
- if(empty($v['jm'])){
- $r = $this->logic_u9tools->getOneU9bmHasGift($whlabel_info['features'],$classid,$typeclass);
- $this->bhsq->save([
- 'jm'=>$r['jm'],
- 'drck'=>$this->getU9Drck($whlabel_info['features']),
- 'features'=>$whlabel_info['features'],
- ],$v['id']);
- }
- $list[$k]['jm'] = $r['jm'];
- }else{
- $this->bhsq->save([
- 'jm'=>$whlabel_info['jm'],
- 'drck'=>$this->getU9Drck($whlabel_info['features']),
- 'features'=>$whlabel_info['features'],
- ],$v['id']);
- $list[$k]['jm'] = $whlabel_info['jm'];
- }
- }
- $status_list = $this->bhccwl->getStatus();
- $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $plat_list = array_column($plat_list,'title','id');
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
- $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
- $list[$k]['bh_no'] = $info['bh_no'];
- }
- echo json_encode(['success'=>true,'msg'=>'编辑成功','data'=>$list]);exit;
-
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);
- exit;
- }
- }
- private function _ccwlbhedit($arg_array){
- if($this->input->method() === 'post'){
- $select_id = $this->input->post('arr_id',true);
- if(empty($select_id)){
- echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
- exit;
- }
- $id = $this->input->post('id',true);
- $info = $this->bhccwl->read($id);
- $bh_no = $info['bh_no'];
- $this->db->where_in('id',$select_id);
- $this->db->update('bhsq',[
- 'bh_no'=>$bh_no,
- 'sq_status'=>4,
- 'ccwl_status'=>1,
- ]);
- $this->db->select('SUM(ccwl_num) as total_ccwl_num');
- $this->db->where_in('id',$select_id);
- $query = $this->db->get('bhsq');
- $result = $query->row();
- $total_ccwl_num = $result->total_ccwl_num? $result->total_ccwl_num:0;
- $time = time();
- $this->bhccwl->save([
- 'num'=>$total_ccwl_num,
- 'update_time'=>$time,
- ],$info['id']);
- echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
- }else{
- $id = $arg_array[0];
- $info = $this->bhccwl->find("id = ".$id);
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and sq_status = 4 and ccwl_status = 1");
-
- $status_list = $this->bhccwl->getStatus();
- $info['status_show'] = isset($status_list[$info['status']])?$status_list[$info['status']]:"";
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $plat_list = array_column($plat_list,'title','id');
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
- $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
- }
- // $this->data['info'] = $info;
- $this->data['list'] = $list;
- $this->data['info'] = $info;
- $this->_Template('beihuogl_ccwlbhedit',$this->data);
- }
- }
- private function _ccwldelitem(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $id = $data['id'];
- $bh_no = $data['bh_no'];
- $info = $this->bhsq->read($id);
- $ccwl_num = $info['ccwl_num'];
-
-
- if(empty($info)){
- echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
- }
- if(empty($info['bh_no'])){
- if($info['sq_status'] == 2 && $info['ccwl_status'] == 0){
- echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
- }else{
- echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
- }
- }
- if($info['bh_no'] != $bh_no){
- echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
- }
- $ccwl_info = $this->bhccwl->find("bh_no = '".$info['bh_no']."'");
- $ccwl_info['num'] = $ccwl_info['num'] - $ccwl_num;
-
- $this->db->trans_start();
- $this->bhccwl->save([
- 'num'=>$ccwl_info['num'],
- ],$ccwl_info['id']);
- $this->bhsq->save([
- 'sq_status'=>2,
- 'ccwl_status'=>0,
- 'bh_no'=>''
- ],$id);
- if($this->db->trans_status() === FALSE){
- $this->db->trans_rollback();
- echo json_encode(['success'=>false,'msg'=>'删除失败']);exit;
- }else{
- $this->db->trans_commit();
- echo json_encode(['success'=>true,'msg'=>'删除成功']);exit;
- }
-
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
- }
- }
- private function _ccwleditxzbh(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- //超过三月没审核的 就不展示了
- $time = time() - 60*24*3600;
- $where = "sq_status = 2 and ccwl_status = 0 and public_time > ".$time." ";
- if(!empty($data['sqr'])){
- $where .= " and sqr = '".$data['sqr']."' ";
- }
- if(!empty($data['shop_id'])){
- $where .= " and shop_id = ".$data['shop_id']." ";
- }
- if(!empty($data['plat_id'])){
- $where .= " and plat_id = ".$data['plat_id']." ";
- }
- if(!empty($data['sku'])){
- $where .= " and sku = '".$data['sku']."' ";
- }
- $order_str = "id desc";
- $list = $this->bhsq->find_all($where,"*",$order_str,0,20);
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $plat_list = array_column($plat_list,'title','id');
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['plat_id'] = isset($plat_list[$v['plat_id']])?$plat_list[$v['plat_id']]:"";
- $list[$k]['public_time'] = date("Y-m-d",$v['public_time']);
- }
- if(empty($list)){
- echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
- }else{
- echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
- }
- }else{
- $data = $this->input->get();
- $this->data['id'] = $data['id'];
- $this->data['bh_no'] = $data['bh_no'];
- $plat_list = $this->typeclass->find_all("classid = 32 and id != 2297","id,title");
- $this->data['plat_list'] = $plat_list;
- $this->_Template('beihuogl_ccwleditxzbh',$this->data);
- }
- }
- private function _ccwlbhsave(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- $id = $data['id'];
- $val = $data['val'];
- $column = $data['column'];
- $update_arr = [];
- if($column == 'status'){
- $update_arr = [
- 'status'=>(int)$val,
- 'update_time'=>time(),
- 'public_time'=>time(),
- ];
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
- }
- $r = $this->bhccwl->save($update_arr,$id);
- if($r){
- echo json_encode(['success'=>true,'msg'=>'修改成功']);exit;
- }else{
- echo json_encode(['success'=>false,'msg'=>'修改失败']);exit;
- }
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);exit;
- }
- }
- //仓库的备货单列表
- private function _ckbhindex(){
- if($this->input->method() === 'post'){
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $bh_no = $this->input->post('bh_no',true);
- $status = $this->input->post('status',true);
- $ktime = $this->input->post('ktime',true);
- $jtime = $this->input->post('jtime',true);
- $ktime = strtotime($ktime);
- $jtime = strtotime($jtime);
- $where = "public_time >= ".$ktime." and public_time < ".$jtime." and status = 1 ";
- if(!empty($bh_no)){
- $where .= " and bh_no = '".$bh_no."' ";
- }
- if($status > -1){
- $where .= " and status = ".$status." ";
- }
-
-
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
- $list = $this->bhccwl->find_all($where,"id,bh_no,ck_status,public_time,ckpublic_time",$order_str,$start,$perpage);
- if(empty($list)){
- $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
- echo json_encode($rows);exit;
- }
- $status_list = $this->bhccwl->getCkStatus();
- foreach($list as $k=>$v){
- $list[$k]['bh_no'] = "<h9 class='window' data-h='/beihuogl/showckbh/".$v['id']."' data-t='订单号:".$v['bh_no']."'><p>".$v['bh_no']."</p></h9>";
- $list[$k]['ck_status'] = isset($status_list[$v['ck_status']])?$status_list[$v['ck_status']]:"";
- $list[$k]['public_time'] = empty($v['public_time'])?"":date("Y-m-d",$v['public_time']);
- $list[$k]['ckpublic_time'] = empty($v['ckpublic_time'])?"":date("Y-m-d",$v['ckpublic_time']);
- $str = "";
- if($v['ck_status'] == 0){
- $str .= "<div style='text-align:center;'>";
- $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>";
- // $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>";
- $str .= "</div>";
- }
- if($v['ck_status'] == 1 || $v['ck_status'] == 2){
- $str .= "<div style='text-align:center;'>";
- $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>";
- $str .= "</div>";
- }
- if($v['ck_status'] > 2){
- $str .= "<div style='text-align:center;'>";
- $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>";
- $str .= "</div>";
- }
-
- $list[$k]['update_time'] = $str;
- }
- $total = $this->bhccwl->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
- echo json_encode($rows);exit;
- }else{
- $this->_Template('beihuogl_ckbhindex',$this->data);
- }
- }
- private function _ckbhedit($arg_array){
- if($this->input->method() === 'post'){
- $id = $this->input->post('id',true);
- $bh_no = $this->input->post('bh_no',true);
- $info = $this->bhccwl->read($id);
- if(empty($info)){
- echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
- }
- if($info['ck_status'] == 0 && $info['status'] == 1){
- }else{
- echo json_encode(['success'=>false,'msg'=>'状态不对,不可审核']);exit;
- }
- if($info['bh_no'] != $bh_no){
- echo json_encode(['success'=>false,'msg'=>'数据信息异常联系技术处理']);exit;
- }
- $num = 0;
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
- foreach($list as $k=>$v){
- $num += $v['ck_num'];
- }
- $r = $this->bhccwl->save([
- 'ck_status'=>1,
- 'ck_num'=>$num,
- 'update_time'=>time(),
- 'ckpublic_time'=>time(),
- ],$id);
- if($r){
- echo json_encode(['success'=>true,'msg'=>'审核成功']);exit;
- }else{
- echo json_encode(['success'=>false,'msg'=>'审核失败']);exit;
- }
- }else{
- $id = $arg_array[0];
- $info = $this->bhccwl->find("id = ".$id);
- $status_list = $this->bhccwl->getCkStatus();
- $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
-
- $drck_list = $this->bhccwl->getDrck();
- $this->data['drck_list'] = $drck_list;
- $this->data['drck_json'] = json_encode($drck_list);
- $this->data['info'] = $info;
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."'");
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
- }
- $this->data['list'] = $list;
- $this->_Template('beihuogl_ckbhedit',$this->data);
- }
- }
- private function _makeu9scd($arg_array){
- if($this->input->method() === 'post'){
- $data = $this->input->post(null,true);
- $info = $this->bhccwl->read($data['id']);
- if(empty($info)){
- echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
- }
- if($info['ck_status'] == 1 && $info['status'] == 1){
- }else{
- echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
- exit;
- }
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' and is_u9sc = 0 ");
- $params = [
- 'org_code'=>"120",//组织代码 龙盈工厂
- 'djhlx'=>'2000',//单号类型 备货生产单
- 'scbm_code'=>"12008",//龙盈生产部门
- "time"=>time(),
- 'owner_org_code'=>"120",
- 'title'=>$info['bh_no'],
- 'shipremarks'=>$info['bh_no'],
- ];
- $final_list = [];
- foreach($list as $k=>$v){
- $final_list[] =[
- 'do_id'=>$v['id'],
- 'drck'=>$v['drck'],
- 'jm'=>$v['jm'],
- 'sl'=>$v['ck_num'],
- ];
- }
- $params['list'] = $final_list;
- $token = $this->settingtest->get_yytoken_120();
- $res = $this->apiyyv1->scdCreate($params,$token);
- if(empty($res[0]['Data'])){
- $this->logic_ding->sendToDing("生成u9生产单失败,错误信息:".json_encode($res,JSON_UNESCAPED_UNICODE));
- echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
- }
- $this->logic_ding->sendToDing("生成u9生产单成功,进行记录:".json_encode($res,JSON_UNESCAPED_UNICODE));
- $r_s_list = $res[0]['Data'];
- foreach($list as $k=>$v){
- $list[$k]['u9_data'] = $r_s_list[$k];
- }
- //m_isSucess
- $flag_status = 0;//判断是否有创建失败的
- $u9sc_status = 0;//判断是否有创建成功的
- foreach($list as $k=>$v){
- if($v['u9_data']['m_isSucess']== 1){
- $u9sc_status += 1;
- $this->bhsq->save([
- 'is_u9sc'=>1,
- 'u9sc_no'=>$v['u9_data']['m_code'],
- ],$v['id']);
- }else{
- $flag_status += 0;
- $this->bhsq->save([
- 'u9sc_remark'=>$v['u9_data']['m_errorMsg'],
- ],$v['id']);
- }
- }
- $len = count($list);
- //都创建失败了 就直接gg
- if($u9sc_status == 0){
- echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
- }
- if(($u9sc_status < $len) && ( $flag_status< $len) ){
- $this->bhccwl->save([
- 'ck_status'=>2,
- ],$info['id']);
- echo json_encode(['success'=>true,'msg'=>'生成u9生产单部分成功']);exit;
- }
- if($u9sc_status == $len){
- $this->bhccwl->save([
- 'ck_status'=>3,
- ],$info['id']);
- echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
- }
- echo json_encode(['success'=>false,'msg'=>'代码异常']);exit;
-
- }else{
- $id = $arg_array[0];
- $info = $this->bhccwl->read($id);
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- $drck_list = $this->bhccwl->getDrck();
- $status_list = $this->bhccwl->getCkStatus();
- $info['ck_status_show'] = isset($status_list[$info['ck_status']])?$status_list[$info['ck_status']]:"";
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
- }
- $this->data['list'] = $list;
- $this->data['info'] = $info;
- $this->_Template('beihuogl_makeu9scd',$this->data);
- }
- }
- private function _ddscscd(){
- if($this->input->method() === 'post'){
- $id = $this->input->post('id',true);
- $bh_no = $this->input->post('bh_no',true);
- $bhsq_info = $this->bhsq->read($id);
- $bhccwl_info = $this->bhccwl->find("bh_no = '".$bhsq_info['bh_no']."' ");
- if(empty($bhccwl_info)){
- echo json_encode(['success'=>false,'msg'=>'数据不存在']);exit;
- }
- // if($bhccwl_info['ck_status'] != 1){
- // echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
- // exit;
- // }
- if(!in_array($bhccwl_info['ck_status'],[1,2])){
- echo json_encode(['success'=>false,'msg'=>'状态不对,不可生成u9生产单']);
- exit;
- }
- if(!empty($bhsq_info['u9sc_no'])){
- echo json_encode(['success'=>false,'msg'=>'状态不允许生成生产单,有疑问联系技术处理']);
- exit;
- }
- $params = [
- 'org_code'=>"120",//组织代码 龙盈工厂
- 'djhlx'=>'2000',//单号类型 备货生产单
- 'scbm_code'=>"12008",//龙盈生产部门
- "time"=>time(),
- 'owner_org_code'=>"120",
- 'title'=>$bhccwl_info['bh_no'],
- 'shipremarks'=>$bhccwl_info['bh_no'],
- ];
- $list[] = [
- 'do_id'=>$bhsq_info['id'],
- 'drck'=>$bhsq_info['drck'],
- 'jm'=>$bhsq_info['jm'],
- 'sl'=>$bhsq_info['ck_num'],
- ];
- $params['list'] = $list;
- $token = $this->settingtest->get_yytoken_120();
- $res = $this->apiyyv1->scdCreate($params,$token);
- if(empty($res[0]['Data'])){
- echo json_encode(['success'=>false,'msg'=>'生成u9生产单失败']);exit;
- }
- if($res[0]['Data'][0]['m_isSucess']== 1){
- $this->bhsq->save([
- 'is_u9sc'=>1,
- 'u9sc_no'=>$res[0]['Data'][0]['m_code'],
- ],$bhsq_info['id']);
- $tmp_list = $this->bhsq->find_all("bh_no = '".$bh_no."' and is_u9sc = 0 ");
- if(empty($tmp_list)){
- $tmp_status = 3;
- }else{
- $tmp_status = 2;
- }
- $this->bhccwl->save([
- 'ck_status'=>$tmp_status,
- ],$bhccwl_info['id']);
- echo json_encode(['success'=>true,'msg'=>'生成u9生产单成功']);exit;
- }else{
- $this->bhsq->save([
- 'u9sc_remark'=>$res[0]['Data'][0]['m_errorMsg'],
- ],$bhsq_info['id']);
- echo json_encode(['success'=>false,'msg'=>$res[0]['Data'][0]["m_errorMsg"]]);exit;
- }
-
-
- }else{
- exit('No direct script access allowed');
- }
- }
- private function _showckbh($arg_array){
- if($this->input->method() === 'post'){
- exit('No direct script access allowed');
- }
- $id = $arg_array[0];
- $drck_list = $this->bhccwl->getDrck();
- $shop_list = $this->shop->find_all("1=1","id,shopname");
- $shop_list = array_column($shop_list,'shopname','id');
- $info = $this->bhccwl->read($id);
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
- $list_dcd = $this->bhdcd->find_all("bh_no = '".$info['bh_no']."' ");
- foreach($list as $k=>$v){
- $list[$k]['shop_id'] = isset($shop_list[$v['shop_id']])?$shop_list[$v['shop_id']]:"";
- $list[$k]['drck_show'] = isset($drck_list[$v['drck']])?$drck_list[$v['drck']]:"";
- }
- $this->data['info'] = $info;
- $this->data['list'] = $list;
- $this->data['list_dcd'] = $list_dcd;
- $this->_Template('beihuogl_showckbh',$this->data);
- }
- //仓库录入调出单
- private function _ckdcd(){
- if($this->input->method() === 'post'){
- $lrdcd = $this->input->post('lrdcd',true);
- if(empty($lrdcd)){
- //列表展示
- $page = $this->input->post('page',true);
- $perpage = $this->input->post('perpage',true);
- $bh_no = $this->input->post('bh_no',true);
- $dcd_no = $this->input->post('dcd_no',true);
- $status = $this->input->post('status',true);
- $ktime = $this->input->post('ktime',true);
- $jtime = $this->input->post('jtime',true);
- $ktime = strtotime($ktime);
- $jtime = strtotime($jtime);
-
- $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
- if(!empty($bh_no)){
- $where .= " and bh_no = '".$bh_no."' ";
- }
- if($status > -1){
- $where .= " and status = ".$status." ";
- }
-
- if(!empty($dcd_no)){
- $where .= " and dcd_no = '".$dcd_no."' ";
- }
-
-
- //数据排序
- $order_str = "id desc";
- if(empty($page))
- {
- $start = 0;
- $perpage = 1;
- }
- else
- {
- $start = ($page - 1)*$perpage;
- }
-
- $list = $this->bhdcd->find_all($where,"id,bh_no,dcd_no,drd_no,status,jm,num,kw,create_time",$order_str,$start,$perpage);
-
- if(empty($list)){
- $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
- echo json_encode($rows);exit;
- }
- $status_list = $this->bhdcd->getStatus();
- foreach($list as $k=>$v){
- $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>";
- $list[$k]['status'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
- $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
- $list[$k]['kw'] = empty($v['kw'])?"":$v['kw'];
- $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
- }
-
-
- $total = $this->bhdcd->find_count($where);
- $pagenum = ceil($total/$perpage);
- $over = $total-($start+$perpage);
- $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
- echo json_encode($rows);exit;
- }else{
- if(empty($lrdcd)){
- echo json_encode(['success'=>false,'msg'=>'调出单号不可以为空']);exit;
- }
- $num = $this->bhdcd->find("dcd_no = '".$lrdcd."'");
- if(!empty($num)){
- echo json_encode(['success'=>false,'msg'=>'调出单号已录入,不可重复录入']);exit;
- }
- //查询录入执行的调出单
- $token = $this->settingtest->get_yytoken_120();
- $res = $this->apiyyv1->cxDcdAboutErp($lrdcd,$token);
- if(empty($res[0]['Data'])){
- echo json_encode(['success'=>false,'msg'=>'请检查调出单号,未在u9获取相关信息']);exit;
- }
- $time = time();
- $final_list = [];
- foreach($res[0]['Data'] as $k=>$v){
- $good_info = $this->goods->find("jm = '".$v['iteminfo_itemcode']."' ");
- $tmp_sku = '';
- $tmp_title = '';
- $tmp_features = '';
- $tmp_number='';
- if(!empty($good_info)){
- $tmp_sku = $good_info['sku'];
- $tmp_title = $good_info['title'];
- $tmp_features = $good_info['features'];
- $tmp_number = str_replace("-","", $good_info['features']);
- }
- $final_list[] = [
- 'sku'=>$tmp_sku,
- 'dcd_no'=>$v['docno'],
- 'jm'=>$v['iteminfo_itemcode'],
- 'zh'=>$v['iteminfo_itemname'],
- 'num'=>$v['costuomqty'],
- 'real_num'=>$v['costuomqty'],
- 'bh_no'=>$v['erp_no'],
- 'create_time'=>$time,
- 'title'=>$tmp_title,
- 'features'=>$tmp_features,
- 'number'=>$tmp_number,
- ];
- }
- $r =$this->db->insert_batch('bhdcd',$final_list);
- if($r){
- echo json_encode(['success'=>true,'msg'=>'录入成功']);
- }else{
- echo json_encode(['success'=>false,'msg'=>'录入失败']);
- }
- exit;
- }
- }else{
- $status_list = $this->bhdcd->getStatus();
- $this->data['status_list'] = $status_list;
- $this->_Template('beihuogl_ckdcd',$this->data);
- }
- }
- private function _ckbherprk($arg_array){
- if($this->input->method() === 'post'){
- $data = $this->input->post(null,true);
- $dcd_no = $data['dcd_no'];
- $drd_no = $data['drd_no'];
- $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."' and drd_no = '".$drd_no."'");
- $whlabel_arr = [];
- $time = time();
- foreach($list as $k=>$v){
- for($i=0;$i<$v['num'];$i++){
- $whlabel_arr[] = [
- 'sku'=>$v['sku'],
- 'number'=>$v['number'],
- 'features'=>$v['features'],
- 'title'=>$v['title'],
- 'zh'=>$v['zh'],
- 'warehouse'=>'13',
- 'enter'=>$time,
- 'state'=>0,
- 'retreatwarehouse'=>'13',
- 'time'=>$time,
- 'details'=>$v['kw'],
- 'bs'=>1,
- 'rktype'=>9,
- ];
- }
-
- }
- $this->db->trans_start();
- $this->db->insert_batch('whlabel',$whlabel_arr);
- $this->db->where('dcd_no',$dcd_no);
- $this->db->where('drd_no',$drd_no);
- $this->db->update('bhdcd',['status'=>3,'rk_time'=>$time]);
- if($this->db->trans_status() === FALSE){
- $this->db->trans_rollback();
- echo json_encode(['success'=>false,'msg'=>'录入失败']);exit;
- }else{
- $this->db->trans_commit();
- echo json_encode(['success'=>true,'msg'=>'录入成功']);
- }
- }else{
- $dcd_no = $arg_array[0];
- $list = $this->bhdcd->find_all("dcd_no = '".$dcd_no."'");
- $jm_list = array_column($list,'jm');
-
- $status_list = $this->bhdcd->getStatus();
- $in_where = "( ";
- foreach($jm_list as $k=>$v){
- $in_where .= "'".$v."',";
- }
- $in_where = rtrim($in_where,",");
- $in_where .= " )";
- foreach($list as $k=>$v){
- $list[$k]['status_show'] = isset($status_list[$v['status']])?$status_list[$v['status']]:"";
- $list[$k]['drd_no'] = empty($v['drd_no'])?"":$v['drd_no'];
- if(!empty($v['kw'])){
- $list[$k]['kw'] = $v['kw'];
- }else{
- if(!empty($list[$k]['sku'])){
- $whlabel_info = $this->whlabel->find(" warehouse = '13' and (sku = '".$list[$k]['sku']."') and ( details != '' and details IS NOT NULL )","*","id desc");
- if(!empty($whlabel_info)){
- if(!empty($whlabel_info['details'])){
- $list[$k]['kw'] = $whlabel_info['details'];
- $this->bhdcd->save([
- 'kw'=>$whlabel_info['details'],
- ],$v['id']);
- }else{
- $list[$k]['kw'] = "";
- }
- }else{
- $list[$k]['kw'] = "";
- }
- }else{
- $list[$k]['kw'] = "";
- }
-
- }
-
- $list[$k]['create_time'] = empty($v['create_time'])?"":date("Y-m-d H:i:s",$v['create_time']);
- }
- $this->data['list'] = $list;
- $this->_Template('beihuogl_ckbherprk',$this->data);
- }
- }
- private function _bhdcdsave(){
- if($this->input->method() === 'post'){
- $id = $this->input->post('id',true);
- $val = $this->input->post('val',true);
- $column = $this->input->post('column',true);
- $info = $this->bhdcd->read($id);
- $update_arr = [];
- if($column == 'real_num'){
- if($val > $info['num']){
- echo json_encode(['success'=>false,'msg'=>'录入数量不能大于原数量']);exit;
- }
- $update_arr = [
- 'real_num'=>(int)$val,
- ];
- }elseif($column == 'kw'){
- $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' ","*","id desc");
- if(!empty($winfo)){
- $winfo = $this->whlabel->find("warehouse = '13' and sku = '".$info['sku']."' and details = '".$val."'","*","id desc");
- if(empty($winfo)){
- echo json_encode(['success'=>false,'msg'=>'请仔细核查该库位信息']);exit;
- }
- }
-
- $update_arr = [
- 'kw'=>trim($val),
- ];
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求参数未设置']);exit;
- }
- $r = $this->bhdcd->save($update_arr,$id);
- if($r){
- echo json_encode(['success'=>true,'msg'=>'保存成功']);
- }else{
- echo json_encode(['success'=>false,'msg'=>'保存失败']);
- }
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求方式错误']);exit;
- }
- }
- private function _u9scdexcel($arg_array){
- $id = $arg_array[0];
- $info = $this->bhccwl->read($id);
- $list = $this->bhsq->find_all("bh_no = '".$info['bh_no']."' ");
-
- //生成excel
- $filename = $info['bh_no']."备货生产单.xls";
- $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
- <head>
- <!--[if gte mso 9]><xml>
- <x:ExcelWorkbook>
- <x:ExcelWorksheets>
- <x:ExcelWorksheet>
- <x:Name>EXCEL</x:Name>
- <x:WorksheetOptions>
- <x:Print>
- <x:ValidPrinterInfo />
- </x:Print>
- </x:WorksheetOptions>
- </x:ExcelWorksheet>
- </x:ExcelWorksheets>
- </x:ExcelWorkbook>
- </xml>
- <![endif]-->
- </head><body>";
- $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
- $str .= "<tr><td>备货单号</td><td>中文品名</td><td>u9料号</td><td>生产数量</td><td>u9生产单号</td></tr>";
- foreach ($list as $key=>$value)
- {
-
- $str .= "<tr>";
- $str .= "<td>". $value['bh_no']. "</td>";
- $str .= "<td>". $value['title']. "</td>";
- $str .= "<td>". $value['jm']. "</td>";
- $str .= "<td>". $value['ck_num']. "</td>";
- $str .= "<td>". $value['u9sc_no']. "</td>";
- $str .= "</tr>";
- }
- $str .= "</table></body></html>";
- header( "Content-Type: application/vnd.ms-excel; name='excel'" );
- header( "Content-type: application/octet-stream" );
- header( "Content-Disposition: attachment; filename=".$filename );
- header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
- header( "Pragma: no-cache" );
- header( "Expires: 0" );
- exit($str);
-
- }
- }
|