深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 611|回复: 1
打印 上一主题 下一主题

beacon下实现一个简单的ajax的案例

[复制链接]

800

主题

1379

帖子

7706

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7706
跳转到指定楼层
楼主
发表于 2021-4-22 14:05:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

  1. <?php

  2. class txcheckin extends tpage  {
  3.         
  4.         /*
  5.          * 构造函数:暂时什么都不做!
  6.         */
  7.         function txcheckin($app) {
  8.                 parent::__construct($app);        //一定要添加这一句
  9.         }
  10.         
  11.         function index(){
  12.                 global $smarty,$config;
  13.                 $this->prepareDictionary();
  14.                 //$this->app->getUser();
  15.                 $this->printBodyScale(); //需要用到页面自适应
  16.                 $this->app->printAjx(); //需要用界面ajax
  17.                 $this->app->printAjdb();//需要用界面ajdb
  18.                 $this->app->printConfirmFun();
  19.                 $this->app->printAlertFun();
  20.                 $this->app->printMsgBox("提示",
  21.                         "1. 如果清溪有正常扫描Check_Out, 则塘厦可以不扫Check_in;<BR>
  22.                          2.        如果清溪漏扫Check_Out, 则塘厦可以在此处补扫;");
  23.         }
  24.         
  25.         function prepareDictionary(){
  26.                 //1. 如果是中国,则直接退出
  27.                 if($this->app->language=="CN") return;
  28.                 //2. 中国以外的国家,必须有英语
  29.                 _D("提示","Hint");        _D("注意","Attention");        _D("警告","Warning");
  30.                 //3. 中国,英国之外的国家,可以适当的添加字典
  31.                 if($this->app->language=="VN"){
  32.                         //添加越南的字典
  33.                 }
  34.         }
  35.         
  36.                 /*
  37.                  * 打印自适应功能
  38.                  */
  39.                 function printBodyScale(){
  40.                         global $smarty;
  41.                         //方案一:
  42.                         //$js="<script>function bodyScale() {var devicewidth = document.documentElement.clientWidth;if(devicewidth>1366){var scale = devicewidth / 1366;  document.body.style.zoom = scale;}}window.onload = window.onresize = function () {bodyScale();};</script>";
  43.                         //$smarty->assign("bodyscale", $js);
  44.                         //方案二:
  45.                         $css="<style>
  46.                                                         @media only screen and (min-width: 1300px){
  47.                                                                 #mymain{
  48.                                                                         width: 1280px !important;
  49.                                                                         margin: 0 auto !important;
  50.                                                                         position: relative !important;
  51.                                                                 }
  52.                                                         }
  53.                                                 </style>";
  54.                         $smarty->assign("bodyscale", $css);                        
  55.                 }
  56.         
  57.         function GetRealData($data){
  58.                 $data=str_replace("--","",$data);
  59.                 $data=str_replace(";","",$data);
  60.                 $data=str_replace("'","",$data);
  61.                 $data=str_replace("\"","",$data);
  62.                 return $data;
  63.         }
  64.         
  65.         /*
  66.          * 创建工单
  67.          */
  68.          function action_get_trsn($param){
  69.                 $this->app->AjaxFail('action_get_trsn已执行,但未返回结果!');         
  70.                 $jsdata=array();
  71.                 $trsninfo=array();
  72.                 $trsninfo["R107"]="";
  73.                 $trsninfo["R108"]="";
  74.                 $trsninfo["INPUT"]="";
  75.                 $trsninfo["TR_SN"]="";
  76.                 $this->app->jsdata["data"]=$trsninfo; //先初始化,成不成功,都会传这些内容
  77.                 //读取参数
  78.                 $data=$param["ed_trsn"];
  79.                 $trsn=$this->GetRealData($data);
  80.                 if(strlen($trsn)<1){
  81.                         $this->app->AjaxFail("条码不能为空!", 100);
  82.                         return;
  83.                 }
  84.                 $trsninfo["TR_SN"]=$trsn;
  85.                 $this->app->jsdata["data"]=$trsninfo;
  86.                 //
  87.                
  88. //---
  89.                 $db = mysqli_connect("10.0.10.29", "root", "****");
  90.                 if (!$db) {
  91.                         die();
  92.                         $this->app->AjaxFail("mysqli_connect异常: ".iconv("GBK", "UTF-8//IGNORE", mysqli_connect_error()), 100);
  93.                         return;                        
  94.                 }  

  95.                 $this->app->prepare_mes();
  96.                
  97.                 //R107
  98.                 $sqlstr="select serial_number from sfc.r_wip_tracking_t where serial_number='{$trsn}'";
  99.                 $data=$this->app->mes->getRow($sqlstr);
  100.                 if($data){
  101.                         $trsninfo["R107"]="OK, 已经存在,无需处理!";
  102.                         $this->app->jsdata["data"]=$trsninfo;  //就算是错,也要回显示
  103.                 }else{
  104.                         $sql="select * from sfc.r_wip_tracking_t where serial_number='{$trsn}'";
  105.                         $result = mysqli_query($db,$sql);
  106.                         if (!$result) {
  107.                                 $trsninfo["R107"]="execute sql: ".mysqli_error($db);
  108.                         }else{
  109.                                 if($row = mysqli_fetch_assoc($result)){
  110.                                         $mysql1="insert ignore into sfc.`r_wip_tracking_t` (`SERIAL_NUMBER`, `SECTION_FLAG`, `MO_NUMBER`, `MODEL_NAME`, `TYPE`, `VERSION_CODE`, `LINE_NAME`, `SECTION_NAME`,
  111.                                         `GROUP_NAME`, `STATION_NAME`, `LOCATION`, `STATION_SEQ`, `ERROR_FLAG`, `IN_STATION_TIME`, `IN_LINE_TIME`, `OUT_LINE_TIME`, `SHIPPING_SN`, `WORK_FLAG`,
  112.                                         `FINISH_FLAG`, `ENC_CNT`, `SPECIAL_ROUTE`, `PALLET_NO`, `CONTAINER_NO`, `QA_NO`, `QA_RESULT`, `SCRAP_FLAG`, `NEXT_STATION`, `CUSTOMER_NO`,
  113.                                         `BOM_NO`, `BILL_NO`, `TRACK_NO`, `PO_NO`, `KEY_PART_NO`, `CARTON_NO`, `WARRANTY_DATE`, `REWORK_NO`, `REPAIR_CNT`, `EMP_NO`, `PO_LINE`,
  114.                                         `PALLET_FULL_FLAG`, `PMCC`, `GROUP_NAME_CQC`, `MO_NUMBER_OLD`, `ERP_MO`, `ATE_STATION_NO`, `MSN`, `IMEI`, `JOB`, `MCARTON_NO`, `SO_NUMBER`,
  115.                                          `SO_LINE`, `STOCK_NO`, `TRAY_NO`, `SHIP_NO`, `WIP_GROUP`, `SHIPPING_SN2`)
  116.                                         values
  117.                                         ('".$row["SERIAL_NUMBER"]."',NULL,'".$row["MO_NUMBER"]."','".$row["MODEL_NAME"]."',NULL,'".$row["VERSION_CODE"]."','".$row["LINE_NAME"]."','".$row["SECTION_NAME"]."','".$row["GROUP_NAME"]."','".$row["STATION_NAME"]."','".$row["LOCATION"]."','".$row["STATION_SEQ"]."','".$row["ERROR_FLAG"]."',
  118.                                         str_to_date('".$row["IN_STATION_TIME"]."','%Y%m%d%H%i%s'),'".$row["IN_LINE_TIME"]."',NULL,'".$row["SHIPPING_SN"]."','".$row["WORK_FLAG"]."','".$row["FINISH_FLAG"]."','".$row["ENC_CNT"]."','".$row["SPECIAL_ROUTE"]."','".$row["PALLET_NO"]."','".$row["CONTAINER_NO"]."','".$row["QA_NO"]."','".$row["QA_RESULT"]."','".$row["SCRAP_FLAG"]."','".$row["NEXT_STATION"]."',
  119.                                         '".$row["CUSTOMER_NO"]."','".$row["BOM_NO"]."',NULL,'".$row["TRACK_NO"]."',
  120.                                         NULL,'".$row["KEY_PART_NO"]."','".$row["CARTON_NO"]."',NULL,'".$row["REWORK_NO"]."','0','".$row["EMP_NO"]."',NULL,'".$row["PALLET_FULL_FLAG"]."',NULL,NULL,NULL,NULL,'',
  121.                                         'N/A','N/A','N/A',NULL,'','','".$row["STOCK_NO"]."','".$row["TRAY_NO"]."','".$row["SHIP_NO"]."','".$row["WIP_GROUP"]."','".$row["SHIPPING_SN2"]."')";
  122.                                         $this->app->mes->execute($mysql1);
  123.                                         $trsninfo["R107"]="OK!";
  124.                                 }else{
  125.                                         $trsninfo["R107"]="无此数据! {$trsn}";
  126.                                 }
  127.                         }
  128.                 }
  129.                
  130.                 //R108
  131.                 $sqlstr="select serial_number from sfc.r_wip_keyparts_t where serial_number='{$trsn}'";
  132.                 $data=$this->app->mes->getRow($sqlstr);
  133.                 if($data){
  134.                         $trsninfo["R108"]="OK, 已经存在,无需处理!";
  135.                         $this->app->jsdata["data"]=$trsninfo;  //就算是错,也要回显示
  136.                 }else{
  137.                         $sql="select * from sfc.r_wip_keyparts_t where serial_number='{$trsn}'";
  138.                         $result = mysqli_query($db,$sql);
  139.                         if (!$result) {
  140.                                 $trsninfo["R108"]="execute sql: ".mysqli_error($db);
  141.                         }else{
  142.                                 $icount=0;
  143.                                 while($row = mysqli_fetch_assoc($result)){
  144.                                         $icount=$icount+1;
  145.                                         $mysql1="insert ignore into sfc.`r_wip_keyparts_t` (`EMP_NO`, `SERIAL_NUMBER`, `KEY_PART_NO`, `KEY_PART_SN`, `KP_RELATION`, `GROUP_NAME`, `CARTON_NO`, `WORK_TIME`, `VERSION`, `PART_MODE`, `KP_CODE`, `MO_NUMBER`)  values ('".$row["EMP_NO"]."','".$row["SERIAL_NUMBER"]."','".$row["KEY_PART_NO"]."','".$row["KEY_PART_SN"]."','".$row["KP_RELATION"]."','".$row["GROUP_NAME"]."','".$row["CARTON_NO"]."','".$row["WORK_TIME"]."','".$row["VERSION"]."',NULL,'N/A','".$row["MO_NUMBER"]."')";
  146.                                         $this->app->mes->execute($mysql1);
  147.                                         $trsninfo["R108"]="OK!同步{$icount}条";
  148.                                 };
  149.                                 if($icount<1){
  150.                                         $trsninfo["R108"]="无此数据! {$trsn}";
  151.                                 }
  152.                         }
  153.                 }

  154.                 //INPUT
  155.                 $sqlstr="select sn from sfc.mes_data_key_t where sn='{$trsn}'";
  156.                 $data=$this->app->mes->getRow($sqlstr);
  157.                 if($data){
  158.                         $trsninfo["INPUT"]="OK, 已经存在,无需处理!";
  159.                         $this->app->jsdata["data"]=$trsninfo;  //就算是错,也要回显示
  160.                 }else{
  161.                         $sql="select * from sfc.mes_data_key_t where sn='{$trsn}'";
  162.                         $result = mysqli_query($db,$sql);
  163.                         if (!$result) {
  164.                                 $trsninfo["INPUT"]="execute sql: ".mysqli_error($db);
  165.                         }else{
  166.                                         function _LL($str){
  167.                                                  if(is_string($str)){
  168.                                                          return "'{$str}',";
  169.                                                  } else {
  170.                                                          return "NULL,";
  171.                                                  }
  172.                                         }
  173.                                 if($row = mysqli_fetch_assoc($result)){
  174.                                         $mysql1="insert ignore into sfc.`mes_data_key_t` (`MO`, `SN`, `MODEL_NAME`, `DATA_TYPE`, `MAC`, `ID1`, `ID2`, `ID3`, `ID4`, `ID5`, `ID6`, `ID7`, `ID8`, `ID9`, `ID10`, `ID11`, `ID12`, `ID13`, `ID14`, `ID15`, `IN_DATE`, `PRINT_FLAG`, `PRINT_TIME`, `PRINT_COUNT`) values(".
  175.                                                 _LL($row["MO"]).
  176.                                                 _LL($row["SN"]).
  177.                                                 _LL($row["MODEL_NAME"]).
  178.                                                 _LL($row["DATA_TYPE"]).
  179.                                                 _LL($row["MAC"]).
  180.                                                 _LL($row["ID1"]).
  181.                                                 _LL($row["ID2"]).
  182.                                                 _LL($row["ID3"]).
  183.                                                 _LL($row["ID4"]).
  184.                                                 _LL($row["ID5"]).
  185.                                                 _LL($row["ID6"]).
  186.                                                 _LL($row["ID7"]).
  187.                                                 _LL($row["ID8"]).
  188.                                                 _LL($row["ID9"]).
  189.                                                 _LL($row["ID10"]).
  190.                                                 _LL($row["ID11"]).
  191.                                                 _LL($row["ID12"]).
  192.                                                 _LL($row["ID13"]).
  193.                                                 _LL($row["ID14"]).
  194.                                                 _LL($row["ID15"]).
  195.                                                 _LL($row["IN_DATE"]).
  196.                                                 _LL($row["PRINT_FLAG"]).
  197.                                                 _LL($row["PRINT_TIME"])."'0')";        
  198.                                         $this->app->mes->execute($mysql1);
  199.                                         $trsninfo["INPUT"]="OK!";
  200.                                 }else{
  201.                                         $trsninfo["INPUT"]="无此数据! {$trsn}";
  202.                                 }
  203.                         }
  204.                 }               

  205.                 $this->app->AjaxOK($trsninfo,"已处理,明细见下表! {$trsn}");   
  206.         }
  207.          
  208.          
  209. }
复制代码
回复

使用道具 举报

800

主题

1379

帖子

7706

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7706
沙发
 楼主| 发表于 2021-4-22 14:07:21 | 只看该作者
<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>sharetronic-tx-checkin</title>
        <link rel="stylesheet" href="../css/themes/default/jquery.mobile.icons-1.4.5.min.css">
        <link rel="stylesheet" href="../css/themes/classic/jquery.mobile.theme-1.4.5.min.css">
        <link rel="stylesheet" href="../css/themes/default/jquery.mobile.structure-1.4.5.min.css">
        <style>
           .ui-field-contain label {
                        white-space:pre;
           }
                div#findBar.ui-grid-a > .ui-block-a { width: 65% }
                div#findBar.ui-grid-a > .ui-block-b { width: 35% }
        </style>
        <script src="../scripts/jquery-1.11.1.min.js"></script>
        <script src="../scripts/jquery.mobile-1.4.5.min.js"></script>
        {$bodyscale}       
        <script>
                //控件联动
                jQuery(function(){
                        jQuery("#ed_trsn").keydown(function(e){ if(e.keyCode == 13){ jQuery("#BT_02").click(); } });
                });

        </script>
        <script>
                jQuery(function(){
                        $("#BT_02").click(function(event){
                                $("#ed_trsn").focus().select();
                                $("#ed_extqty").val("");$("#ed_qty").val("");$("#ed_flag").val("");
                                $("#ed_loc").val("");$("#ed_mkp").val("");$("#ed_kp").val("");
                                $("#ed_lc").val("");$("#ed_mfrname").val("");$("#ed_dc").val("");
                                $("#ed_sn").val("");$("#ed_mfrcode").val("");
                                myAjaxProcess("form1","action_get_trsn",{},function(jsondata){
                                        if(jsondata.tag==418){
                                                        $("#ed_r107").val(jsondata.data.R107);
                                                        $("#ed_r108").val(jsondata.data.R108);
                                                        $("#ed_input").val(jsondata.data.INPUT);
                                                if(jsondata.res=="OK"){
                                                        showMessage("0",jsondata.msg); showSound(true);
                                                }else{
                                                        showMessage("2",jsondata.msg); showSound(false);
                                                        $("#ed_trsn").focus().select();
                                                }       
                                        }else{
                                                alert("返回的数据格式不正确,请联系MES管理人员!");
                                        }
                                });
                                return false;
                        })
                });       
        </script>       
</head>
<body>
<div data-role="page" id="pageone" class="ui-page-theme-c">
       
        <div class="ui-content" role="main">
       
    <form method="post" id="form1"  class="ui-mini">
    <div class="ui-grid-a" id="findBar">
      <div class="ui-block-a">
                <!-- 再分两列 -->
                <div class="ui-body ui-body-b ui-corner-all"  style="height:auto!important;height:7.6em;min-height:7.6em;">
                        {$msgbox}
                </div>
               
                <div class="ui-field-contain">
                        <label for="ed_trsn">产品条码</label>
                        <input type="text" name="ed_trsn" id="ed_trsn">
                </div>
               
                <div style="position: absolute;top: -100px;left: -100px;">
                        <input type="button" data-inline="true" id="BT_01" value="BT_01">
                        <input type="button" data-inline="true" id="BT_02" value="BT_02">
                        <input type="button" data-inline="true" id="BT_03" value="BT_03">
                </div>
               
       
                        <div class="ui-field-contain" data-inline="true">
                                <label for="ed_kp" >生产数据</label>
                                <input type="text" name="ed_r107" id="ed_r107"  style="background:#C2C2C2" readonly>
                        </div>
                        <div class="ui-field-contain" data-inline="true">
                                <label for="ed_mkp" >附件数据</label>
                                <input type="text" name="ed_r108" id="ed_r108"  style="background:#C2C2C2" readonly>
                        </div>
                        <div class="ui-field-contain" data-inline="true">
                                <label for="ed_mkp" >导号数据</label>
                                <input type="text" name="ed_input" id="ed_input"  style="background:#C2C2C2" readonly>
                        </div>


               
      </div><!-- ui-block-a -->

      <div class="ui-block-b">
                                 
      </div>
    </div>
    </form>

        </div><!-- div class="ui-content" role="main" -->
       
</div><!-- /page -->

{$pageajdb}

{$pageajx}



</body>
</html>
       
       

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 08:02 , Processed in 0.025288 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表