找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 拇指 mztk
查看: 1639|回复: 1

php thinkphp5.1批量*作

[复制链接]

134

主题

52

回帖

4913

积分

版主

积分
4913
发表于 2022-5-8 12:21:58 | 显示全部楼层 |阅读模式
本帖最后由 win 于 2022-5-8 12:37 编辑

php thinkphp5.1批量*作,批量删除、更新
//前端的ID
$id = Request::param('id');//用户的ID
$sid = Cookie::get('userid');

批量更新

1.遍历更新,这里没有使用用户ID
foreach ($id as $k) {
    $zdid = GerenModel::where('id', $k)->update(['std' => 1,'ctime' => time()]);}
2.数组更新
$map = [];
$map[] = ['id', 'IN', $id];
GerenModel::where($map)->where('sjid', $sid)->update(['std' => 1, 'ctime' => time()])

批量删除
1.遍历删除,这里没有使用用户IDforeach ($delid as $k) {
    $zdid = CaidanModel::where('id', $k)->where('cd', 2)->delete();
}

2.数组删除
//删除条件:选中的所有ID和用户ID,满足两个条件
$map = [];
$map[] = ['id', 'IN', $id];
GerenModel::where($map)->where('sjid', $sid)->delete()


回复

使用道具 举报

134

主题

52

回帖

4913

积分

版主

积分
4913
 楼主| 发表于 2022-5-8 12:37:37 | 显示全部楼层
//批量彻底删除
    public function del_pl_cd_do()
    {
        $id = Request::param('delid');
        $sid = Cookie::get('userid');
        //此方法的公共变量
        $ckip = request()->ip();    //获取当前IP地址
        $phptime = date('Y-m-d h:i:s');    //获取当前时间
        $username = Cookie::get('username');
        $map = [];
        $map[] = ['id', 'IN', $id];
        if (GerenModel::where($map)->where('sjid', $sid)->delete()) {
            $ctime = date("Y");   //根据日期创建日志文件
            $fkmsg = "[$username]----------------[$phptime]------------[$ckip]----------[批量彻底删除网址收藏]\r\n";
            if (!is_dir("static/uploads/$sid/shoucanglog")) { //如果文件目录不存在
                $dir = "static/uploads/$sid/shoucanglog";    //创建目录
                mkdir(iconv("UTF-8", "GBK", $dir), 0777, true);
                $fp = fopen("static/uploads/$sid/shoucanglog/$ctime.txt", 'a+');    //创建文件
                fwrite($fp, $fkmsg); //将得到的信息写入文件
                fclose($fp);  //关闭文件
            } else {
                file_put_contents("static/uploads/$sid/shoucanglog/$ctime.txt", $fkmsg, FILE_APPEND);
            }
            return json(['code' => 200, 'msg' => '批量删除成功!']);
        } else {
            return json(['code' => 301, 'msg' => '批量删除失败!']);
        }
    }
回复

使用道具 举报

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

本版积分规则

QQ|手机版|再加计算机 ( 鲁ICP备19060125号-10|鲁公网安备37028102001711号 )

GMT+8, 2026-9-11 18:28 , Processed in 0.108979 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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