0
篇帖子
去年工作中遇到的一个需求,自动更换客户的微信号码 Mysql数据库建表过程:
CREATE TABLE `kefu_member` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`wechat` varchar(255) NOT NULL,
`team` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
CREATE TABLE `kefu_team` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`team` varchar(255) NOT NULL,
`manage` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
CREATE TABLE `kefu_online` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`team` varchar(255) NOT NULL,
`customer` varchar(255) NOT NULL,
`click` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
新建一个admin.php管理界面,用于操作和选择修改组别归属管理员;
<?php
/**
* Created by PhpStorm.
* User: nobita
* Date: 2018/3/30
* Time: 17:24
*/
include 'config.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>选择客服</title>
</head>
<body>
<form action="post.php" method="post">
选择更改组别:
<?php $team_sql = "SELECT id,team,manage FROM `kefu_team`"; ?>
<?php $team = mysqli_query($link,$team_sql); ?>
<select name="team">
<?php while( $row = mysqli_fetch_assoc($team) ): ?>
<?php
$id = $row['id'];
$teams = $row['team'];
$manage = $row['manage'];
?>
<option name="<?php echo $id ?>" value="<?php echo $teams ?>"><?php echo $manage ?></option>
<?php endwhile;?>
</select>
<br />
选择一跳客服:
<select name="one_jump">
<?php $customer_sql = "SELECT id,name,wechat FROM `kefu_member`"; ?>
<?php $customer = mysqli_query($link,$customer_sql); ?>
<?php while( $row = mysqli_fetch_assoc($customer) ): ?>
<?php
$id = $row['id'];
$name = $row['name'];
$wechat = $row['wechat'];
?>
<option name="<?php echo $id ?>" value="<?php echo $wechat ?>"><?php echo $name ?></option>
<?php endwhile;?>
</select>
<p>选择二跳客服:</p>
<?php $twocustomer_sql = "SELECT id,name,wechat FROM `kefu_member`"; ?>
<?php $twojump = mysqli_query($link,$twocustomer_sql); ?>
<?php while( $row = mysqli_fetch_assoc($twojump) ): ?>
<?php
$id = $row['id'];
$name = $row['name'];
$wechat = $row['wechat'];
?>
<p><input type="checkbox" name="two_jump[<?php echo $id ?>]" value="<?php echo $wechat ?>" /> <?php echo $name ?></p>
<?php endwhile;?>
<div class="submit_btn"> <input type="submit" value="Submit" /> </div>
</form>
</body>
</html>
<?php
/* Close the connection 关闭连接*/
mysqli_close($link);
?>
新建post.php用于接收admin.php POST传递过来的参数,写入数据库;
<?php
/**
* Created by PhpStorm.
* User: nobita
* Date: 2018/3/30
* Time: 14:33
*/
include 'config.php';
$customer_sql = "SELECT id,name,wechat FROM `kefu_member`";
$twocustomer_sql = "SELECT id,name,wechat FROM `kefu_member`";
$team_sql = "SELECT id,team FROM `kefu_team`";
$two_team_sql = "SELECT id,team FROM `kefu_team`";
$customer = mysqli_query($link,$customer_sql);
?>
<?php
$kefu_array = $_POST;
$kefu_json = json_encode($kefu_array);
$kefu_item = json_decode($kefu_json);
$team = $kefu_item->team;
$sql = "UPDATE `kefu_online` SET `team` = '$team',`customer` = '$kefu_json' WHERE `team` = '$team'";
$result = mysqli_query($link,$sql);
echo $sql;
var_dump($result);
?>
<?php
/* Close the connection 关闭连接*/
mysqli_close($link);
?>
<?php
/**
* Created by PhpStorm.
* User: nobita
* Date: 2018/3/30
* Time: 14:56
*/
include 'config.php';
$manage_team = $_GET['team'];
?>
<?php
$sql = "SELECT id,team,customer FROM `kefu_online` WHERE team = '$manage_team'";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_array($result);
$row_json = $row['customer'];
$data = json_decode($row_json,true);
$one_jump = $data['one_jump'];
$two_jump = $data['two_jump'];
echo 'two_jump = [';
echo '"'.implode('","',$two_jump).'"';
echo '];';
?>
one_jump = ["<?php echo $one_jump ?>"];
var tel = "4008115377";
<?php
/* Close the connection 关闭连接*/
mysqli_close($link);
?>
本博客内所有原创和翻译的文章的版权归本人所有,允许第三方转载,但转载时请务必保留作者名,并注明出处链接,否则本人将保留追究其法律责任的权利。
「人生在世,留句话给我吧」