| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479 |
- <?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();
- }
- 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>";
- }
- $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;
- }
- }
- }
|