博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql批量插入更新操作
阅读量:5166 次
发布时间:2019-06-13

本文共 6087 字,大约阅读时间需要 20 分钟。

//添加关联赠品(确定)    public function addGiveGoods($ids,$child,$parent_sku_no){        $license=new LicenseModel();        $personnel_code=$_SESSION['user']['personnel_code'];        $time=date("Y-m-d H:i:s",time());        $sku_gift=M('sku_gift');        $sku_gift_stock=M('sku_gift_stock');        $sku_nos=array_column($child,'sku_no');        $sgg_where['sku_no']=array('in',$sku_nos);        $sku_gift_stock_info=$sku_gift_stock->field('sku_no,is_online')->where($sgg_where)->select();        foreach($sku_gift_stock_info as $k=>$v){            $sgg[$v['sku_no']]=$v['is_online'];        }        $s_where['parent_sku_no']=$parent_sku_no;        $s_where['is_deleted']=0;        $s_where['sku_no']=array('in',$sku_nos);        $s_info=$sku_gift->field('id,num,create_time,is_deleted,is_online,create_user')->where($s_where)->select();        foreach($s_info as $k=>$v){            $ss[$v['id']]=$v;        }        $pars2=array();        $pars3=array();        $sku_nos_info=array();        foreach($child as $k=>$v){            if(!empty($v['id'])){                $data[]=array(                    'id'=>$v['id'],                    'parent_sku_no'=>$parent_sku_no,                    'sku_no'=>$v['sku_no'],                    'create_time'=>$ss[$v['id']]['create_time'],                    'modified'=>$time,                    'num'=>$v['num'],                    'is_deleted'=>$ss[$v['id']]['is_deleted'],                    'is_online'=>$ss[$v['id']]['is_online'],                    'update_user'=>$personnel_code,                    'create_user'=>$ss[$v['id']]['create_user'],                );            }else{                $data[]=array(                    'id'=>$v['id'],                    'parent_sku_no'=>$parent_sku_no,                    'sku_no'=>$v['sku_no'],                    'create_time'=>$time,                    'modified'=>$time,                    'num'=>$v['num'],                    'is_deleted'=>0,                    'is_online'=>empty($sgg[$v['sku_no']])?0:1,                    'update_user'=>$personnel_code,                    'create_user'=>$personnel_code,                );                $sku_nos_info[]=$v['sku_no'];            }            if(empty($v['id'])){                $pars2[]=array(                    'message'=>$_SESSION['user']['true_name'].":赠品".$v['sku_no']."被商品".$parent_sku_no."关联了",                    'create_time'=>$time,                    'create_id'=>$personnel_code,                    'type'=>2,                    'sku_no'=>$v['sku_no']                );            }else{                if($ss[$v['id']]['num'] !=$v['num']){                    $pars3[]=array(                        'message'=>$_SESSION['user']['true_name'].":修改了商品".$parent_sku_no."所关联的赠品".$v['sku_no']."的数量,修改前[".$ss[$v['id']]['num']."],修改后[".$v['num']."]",                        'create_time'=>$time,                        'create_id'=>$personnel_code,                        'type'=>1,                        'sku_no'=>$parent_sku_no                    );                }            }        }        foreach($data as $k=>$v){            if(empty($v['id'])){                $update[]="('','".$v['parent_sku_no']."','".$v['sku_no']."','".$v['create_time']."','".$v['modified']."','".$v['num']."','".$v['is_deleted']."','".$v['is_online']."','".$v['update_user']."','".$v['create_user']."')";            }else{                $update[]="('".$v['id']."','".$v['parent_sku_no']."','".$v['sku_no']."','".$v['create_time']."','".$v['modified']."','".$v['num']."','".$v['is_deleted']."','".$v['is_online']."','".$v['update_user']."','".$v['create_user']."')";            }        }         if(!empty($update)){            $value=implode(',',$update);        }        if(!empty($data)){            $Model = new \Think\Model();            $res=$Model->execute("insert into ".C('DB_PREFIX')."sku_gift(`id`,`parent_sku_no`,`sku_no`,`create_time`,`modified`,`num`,`is_deleted`,`is_online`,`update_user`,`create_user`) VALUES $value ON DUPLICATE KEY UPDATE `id`=VALUES(id),`parent_sku_no`=VALUES(parent_sku_no),`sku_no`=VALUES(sku_no),`create_time`=VALUES(create_time),`modified`=VALUES(modified),`num`=VALUES(num),`is_deleted`=VALUES(is_deleted),`is_online`=VALUES(is_online),`update_user`=VALUES(update_user),`create_user`=VALUES(create_user)");            if(!$res){                return 100;            }        }        if(!empty($ids)){            $ids=explode(",",$ids);            $sg_where['id']=array('in',$ids);            $res_in=$sku_gift->field('parent_sku_no,sku_no')->where($sg_where)->select();            $ar=array(                'is_deleted'=>1,                'modified'=>$time,                'update_user'=>$personnel_code,            );            $res=$sku_gift->data($ar)->where($sg_where)->save();            if(!$res){                return 101;            }            $skus=implode(",",array_column($res_in,'sku_no'));            if(!empty($res_in)){                $pars=array(                    'message'=>$_SESSION['user']['true_name'].":商品".$parent_sku_no."的关联赠品".$skus."被删除了",                    'create_time'=>date('Y-m-d H:i:s',time()),                    'create_id'=>$_SESSION['user']['personnel_code'],                    'type'=>1,                    'sku_no'=>$parent_sku_no                );                $license->writeLog('sku_gift_log',$pars);            }        }        if(!empty($pars2)){            $license->writeAllLog('sku_gift_log',$pars2);        }        if(!empty($sku_nos_info)){            $sku_noss=implode(",",$sku_nos_info);            $params=array(                'message'=>$_SESSION['user']['true_name'].":商品".$parent_sku_no."添加了关联赠品".$sku_noss,                'create_time'=>date('Y-m-d H:i:s',time()),                'create_id'=>$_SESSION['user']['personnel_code'],                'type'=>1,                'sku_no'=>$parent_sku_no            );            $license->writeLog('sku_gift_log',$params);        }        if(!empty($pars3)){            $license->writeAllLog('sku_gift_log',$pars3);        }        return true;    }

 

转载于:https://www.cnblogs.com/zouke1220/p/9086710.html

你可能感兴趣的文章
(转)Tomcat 8 安装和配置、优化
查看>>
(转)Linxu磁盘体系知识介绍及磁盘介绍
查看>>
命令ord
查看>>
Sharepoint 2013搜索服务配置总结(实战)
查看>>
博客盈利请先考虑这七点
查看>>
使用 XMLBeans 进行编程
查看>>
写接口请求类型为get或post的时,参数定义的几种方式,如何用注解(原创)--雷锋...
查看>>
【OpenJ_Bailian - 2287】Tian Ji -- The Horse Racing (贪心)
查看>>
Java网络编程--socket服务器端与客户端讲解
查看>>
List_统计输入数值的各种值
查看>>
学习笔记-KMP算法
查看>>
Timer-triggered memory-to-memory DMA transfer demonstrator
查看>>
跨域问题整理
查看>>
[Linux]文件浏览
查看>>
获取国内随机IP的函数
查看>>
今天第一次写博客
查看>>
江城子·己亥年戊辰月丁丑日话凄凉
查看>>
Spring Mvc模式下Jquery Ajax 与后台交互操作
查看>>
(转)matlab练习程序(HOG方向梯度直方图)
查看>>
『Raid 平面最近点对』
查看>>