//添加关联赠品(确定) 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; }