where(['store_id'=>$this->store_id,'is_delete'=>0])->select('goods_id')->column(); // 2.获取未上传的商品 $needUploadGoods = Goods::find()->where(['store_id'=>$this->store_id,'is_delete'=>0,'status'=>1,'product_type'=>0])->andWhere(['not in','id',$goodsId])->limit(1000)->select('id,cover_pic,name,store_id')->asArray()->all(); if(count($needUploadGoods) <= 0){ // 没有要需要上传的图片 return true; } // 组装 写入数据库的数据 $insertSql = ''; foreach($needUploadGoods as $item){ $str = "INSERT INTO ".UploadGoodsImage::tableName()."(`store_id`,`goods_id`,`pic_url`,`status`,`image_name`,`created_at`) VALUES (".$this->store_id.",".$item['id'].",'".$item['cover_pic']."',0,'".$item['id']."-".$item['name']."',".time().");"; $insertSql .= $str; } $connection = \Yii::$app->db; $command = $connection->createCommand($insertSql); $result = $command->query(); // 写入真正的上传图片队列 foreach($needUploadGoods as $value){ queue_push(new UplaodImageJob($value)); } \Yii::error('队列执行,写入数据 => ' . count($result) . '条'); } }