PHP代码改写成JavaScript代码,求大神帮忙!!!

方圆百里我最屌 发布于 05/22 15:53
阅读 167
收藏 0
public function actionHandle()
{
    // 对应 Y 轴 关系
    $relation = [
    '3002a' => ['name' => '2#回火炉', 'index' => 0],
    '3001a' => ['name' => '1#回火炉', 'index' => 1],
    '2002a' => ['name' => '2#冷水机', 'index' => 2],
    '2001a' => ['name' => '1#清洗机', 'index' => 3],
    '1004a' => ['name' => '4#加热炉', 'index' => 4],
    '1003a' => ['name' => '3#加热炉', 'index' => 5],
    '1002a' => ['name' => '2#加热炉', 'index' => 6],
    '1001a' => ['name' => '1#加热炉', 'index' => 7],
    ];
    // sql 语句
    $sql = "select * from ctrl_lmstask";
    // 执行 sql
    $result = Yii::$app->db->createCommand($sql)->queryAll();

    $data = [ ];
    foreach ($result as $key => $value) {
        $tempData = [isset($relation[$value['EquipSerial']]['index']) ? 
            $relation[$value['EquipSerial']]['index'] : '', $value['PlanStartTime'], 
            $value['PlanEndTime']];
        $name = $value['BatchIndex'];
        $temp[$name][] = $tempData;
        // 不能继续循环 或者 下次循环的 name 和当前值不同,说明当前 name 处理结束
        if (!isset($result[$key + 1]) || $result[$key + 1]['BatchIndex'] != $name) {
            $data[] = [
                    'name' => $name,
                    'data' => $temp[$name]
            ];
        }
    }
    echo json_encode($temp);
    echo "\n";
    echo json_encode($data);
    echo "\n";
}

 

加载中
0
梅开源
梅开源

你们公司哪个要用node.js的叫他来改

 

返回顶部
顶部