| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580 |
- <?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);
- }elseif($arg == 'ccwlskucheck'){
- $this->_ccwlskucheck();
- }
- 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);
- }
- }
- //一键校验选中SKU
- private function _ccwlskucheck(){
- if($this->input->method() === 'post'){
- $data = $this->input->post();
- if(empty($data['arr_id'])){
- echo json_encode(['success'=>false,'msg'=>'至少选一个呀!!!']);
- exit;
- }
- $list = $this->bhsq->find_all('id in ('.implode(',',$data['arr_id']).')');
- $error_list = [];
- foreach($list as $k=>$v){
- if(empty($v['sku'])){
- $error_list[] = [
- 'msg'=>$v['value'].'请录入SKU',
- ];
- continue;
- }
- $num = $this->goods->find_count("sku = '".$v['sku']."'");
- if(!empty($num)){
- continue;
- }
- $whlabel_info = $this->whlabel->find("sku = '".$v['sku']."'",'sku,features','id desc');
- if(empty($whlabel_info)){
- $error_list[] = [
- 'msg'=>$v['sku'].'未在进销存浏览那找到对应信息',
- ];
- }
- }
- if(empty($error_list)){
- echo json_encode(['success'=>true,'msg'=>'校验成功,没有异常信息']);
- exit;
- }else{
- echo json_encode(['success'=>true,'msg'=>'校验失败,请核对填写信息','error_list'=>$error_list]);
- exit;
- }
- }else{
- echo json_encode(['success'=>false,'msg'=>'请求失败']);
- exit;
- }
- }
- //仓储物流合成备货单
- 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);
-
- }
- }
|