美文网首页
thinkphp 批量更新数据2021-10-13

thinkphp 批量更新数据2021-10-13

作者: 阿然学编程 | 来源:发表于2021-10-12 18:26 被阅读0次
    public function batchAllot()
    {
        $id = input('ids');
        $dispose_account = input('dispose_account');
        if (!empty($id) && !empty($dispose_account)) {
            $data = Db::name('orders')->field('id')->whereIn('id', $id)->select();
            foreach ($data as $v) {
                $res = Db::name('orders')->where('id', $v['id'])->update([
                    'dispose_account' => $dispose_account,
                    'accepted_at' => date('Y-m-d'),
                    'status' => 3
                ]);
            }
            if (!$res) return $this->jsonData(400, '分配失败');
            return $this->jsonSuccessData('分配成功');
        }
        return $this->jsonData(400, '参数为空');
    }

或者使用模型方法 saveAll()

相关文章

网友评论

      本文标题:thinkphp 批量更新数据2021-10-13

      本文链接:https://www.haomeiwen.com/subject/nldeoltx.html