更新
This commit is contained in:
parent
641f53ec6e
commit
dc69ce86ce
@ -306,22 +306,22 @@ class StoreProduct extends BaseController
|
|||||||
public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0)
|
public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0)
|
||||||
{
|
{
|
||||||
if ($product_id == 0) return app('json')->fail('参数错误');
|
if ($product_id == 0) return app('json')->fail('参数错误');
|
||||||
$product = $this->repository->getAdminOneProduct($product_id, 0);
|
$products = $this->repository->getAdminOneProduct($product_id, 0);
|
||||||
$product = $product->toArray();
|
$product = $products->toArray();
|
||||||
$product['mer_id'] = $mer_id;
|
$product['mer_id'] = $mer_id;
|
||||||
$product['old_product_id'] = $product['product_id'];
|
$product['old_product_id'] = $product['product_id'];
|
||||||
$productId = $this->repository->create($product, 0, 1);
|
$productId = $this->repository->create($product, 0, 1);
|
||||||
$data = [
|
$data = [
|
||||||
'product_id' => $productId,
|
'product_id' => $productId,
|
||||||
'mer_id' => $mer_id,
|
'mer_id' => $mer_id,
|
||||||
'source_mer_id' => $product['mer_id'],
|
'source_mer_id' => $products['mer_id'],
|
||||||
'street_code' => $street_code,
|
'street_code' => $street_code,
|
||||||
'weight' => 1,
|
'weight' => 1,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'create_time' => date('Y-m-d H:i:s'),
|
'create_time' => date('Y-m-d H:i:s'),
|
||||||
'type_id' => $type_id,
|
'type_id' => $type_id,
|
||||||
'category_id' => $category_id,
|
'category_id' => $category_id,
|
||||||
'cate_id' => $product['type']
|
'cate_id' => $product['cate_id']
|
||||||
];
|
];
|
||||||
Db::name('cloud_product')->insert($data);
|
Db::name('cloud_product')->insert($data);
|
||||||
return $productId;
|
return $productId;
|
||||||
|
@ -31,158 +31,72 @@ class Demo extends BaseController
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$arr=Db::name('store_product')->where('mer_id',208)->where('status',1)->where('is_show',0)->find();
|
return app('json')->success('修改成功');
|
||||||
|
$arr=Db::name('store_product')->whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])->where('status',1)->where('is_show',0)->field('product_id')->select();
|
||||||
|
$mer_id=167;//导入到的商户
|
||||||
|
$street_code=510521107;//导入到的商户
|
||||||
|
$type_id=17;//导入到的商户分类
|
||||||
|
$category_id=2566;//导入到的商户分类
|
||||||
|
foreach($arr as $k=>$v){
|
||||||
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$mer_id=236;//导入到的商户
|
||||||
|
$street_code=510521123;//导入到的商户
|
||||||
|
foreach($arr as $k=>$v){
|
||||||
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
|
}
|
||||||
|
|
||||||
|
$mer_id=237;//导入到的商户
|
||||||
|
$street_code=510521115;//导入到的商户
|
||||||
|
|
||||||
|
foreach($arr as $k=>$v){
|
||||||
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
|
}
|
||||||
|
|
||||||
|
$mer_id=238;//导入到的商户
|
||||||
|
$street_code=510521105;//导入到的商户
|
||||||
|
|
||||||
|
foreach($arr as $k=>$v){
|
||||||
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
|
}
|
||||||
|
|
||||||
$mer_id=239;//导入到的商户
|
$mer_id=239;//导入到的商户
|
||||||
$street_code=510521116;//导入到的商户
|
$street_code=510521116;//导入到的商户
|
||||||
$type_id=17;//导入到的商户分类
|
|
||||||
foreach($arr as $k=>$v){
|
foreach($arr as $k=>$v){
|
||||||
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$v['category_id']]);//短信通知
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
}
|
}
|
||||||
|
|
||||||
halt(1);
|
//江阳
|
||||||
$mer_id = 104;
|
$mer_id=31;//导入到的商户
|
||||||
$file = request()->file('file');
|
$street_code=510502108;//导入到的商户
|
||||||
$zip_name = explode('.', $file->getOriginalName())[0];
|
|
||||||
// 上传到本地服务器
|
foreach($arr as $k=>$v){
|
||||||
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
|
|
||||||
$path = public_path('uploads/pic').$dir;
|
|
||||||
try {
|
|
||||||
$zip = new ZipArchive;
|
|
||||||
$filePath = public_path('uploads') . $savename;
|
|
||||||
$zip->open($filePath);
|
|
||||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
|
||||||
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
|
|
||||||
$filename = $this->transcoding($statInfo['name']);
|
|
||||||
$mkdFile = explode('/',$filename);
|
|
||||||
if ($statInfo['crc'] == 0) {
|
|
||||||
// 新建目录
|
|
||||||
if (!file_exists($path . '/' . $filename)) {
|
|
||||||
mkdir($path . '/' . $filename, 0777, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 拷贝文件
|
|
||||||
if(count($mkdFile)==3){
|
|
||||||
if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) {
|
|
||||||
mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true);
|
|
||||||
}
|
|
||||||
copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$zip->close();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$directory = $path.'/'.$zip_name;
|
$mer_id=32;//导入到的商户
|
||||||
$files = scandir($directory);
|
$street_code=510502107;//导入到的商户
|
||||||
$dir = 'def/' . date('Y-m-d');
|
|
||||||
$upload = UploadService::create();
|
|
||||||
/**循环目录 */
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if ($file === '.' || $file === '..' || $file === '__MACOSX') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!is_dir($directory . '/' . $file)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$files_two = scandir($directory . '/' . $file);
|
|
||||||
|
|
||||||
$image_extensions = array('jpg', 'jpeg', 'png');
|
foreach($arr as $k=>$v){
|
||||||
$image = '';
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
$slider_image = [];
|
}
|
||||||
$details = [];
|
|
||||||
$sku_arr = [];
|
$mer_id=118;//导入到的商户
|
||||||
/**清洗图片 */
|
$street_code=510502106;//导入到的商户
|
||||||
foreach ($files_two as $file_two) {
|
|
||||||
if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') {
|
foreach($arr as $k=>$v){
|
||||||
continue;
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
}
|
}
|
||||||
$arr = explode('.', $file_two);
|
|
||||||
if (in_array($arr[1], $image_extensions)) {
|
$mer_id=39;//导入到的商户
|
||||||
/**首图 */
|
$street_code=510502105;//导入到的商户
|
||||||
$images[] = $file_two;
|
|
||||||
if ($image == '' && is_numeric($arr[0])) {
|
foreach($arr as $k=>$v){
|
||||||
$image = $directory . '/' . $file . '/' . $file_two;
|
Queue::push(ProductCopyJob::class, ['product_id' => $v['product_id'], 'mer_id' =>$mer_id,'street_code'=>$street_code,'type_id'=>$type_id,'category_id'=>$category_id]);//短信通知
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/**轮播图 */
|
|
||||||
if (is_numeric($arr[0]) && count($slider_image) < 4) {
|
|
||||||
$slider_image[] = $directory . '/' . $file . '/' . $file_two;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/**详情图 */
|
|
||||||
if (is_numeric($arr[0])) {
|
|
||||||
$details[] = $directory . '/' .$file.'/'. $file_two;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/**sku图 */
|
|
||||||
$sku = explode('==', $arr[0]);
|
|
||||||
if ($sku) {
|
|
||||||
$sku = implode(',', $sku);
|
|
||||||
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$where = ['mer_id' => $mer_id, 'is_del' => 0];
|
|
||||||
$update = [];
|
|
||||||
$update_content['title'] = '';
|
|
||||||
$update_content['image'] = [];
|
|
||||||
$update_content['type'] = 1;
|
|
||||||
$find = Db::name('store_product')->where($where)->where('store_name', $file)->find();
|
|
||||||
if ($find) {
|
|
||||||
try {
|
|
||||||
/**更新商品图片 */
|
|
||||||
$image = $upload->to($dir)->stream(file_get_contents($image));
|
|
||||||
$update['image'] = $image->filePath;
|
|
||||||
foreach ($slider_image as $k => $v) {
|
|
||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
|
||||||
$update['slider_image'][] = $oss->filePath;
|
|
||||||
}
|
|
||||||
if (isset($update['slider_image'])) {
|
|
||||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
|
||||||
}
|
|
||||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
|
||||||
/**更新规格图片 */
|
|
||||||
foreach ($sku_arr as $k => $v) {
|
|
||||||
// $sku = explode(',', $k);
|
|
||||||
// if(count($sku)==2){
|
|
||||||
// $sku_name=$sku[0];
|
|
||||||
// }else{
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
|
||||||
if ($store_product_attr_value) {
|
|
||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
|
||||||
Db::name('store_product_attr_value')
|
|
||||||
->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])
|
|
||||||
->update(['image' => $oss->filePath]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**更新详情图片 */
|
|
||||||
$store_product_content = Db::name('store_product_content')->where(['product_id' => $find['product_id']])->find();
|
|
||||||
foreach ($details as $k => $v) {
|
|
||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
|
||||||
$update_content['image'][] = $oss->filePath;
|
|
||||||
}
|
|
||||||
if ($store_product_content) {
|
|
||||||
if (isset($update_content['image']) && !empty($update_content['image'])) {
|
|
||||||
Db::name('store_product_content')
|
|
||||||
->where(['product_id' => $find['product_id']])
|
|
||||||
->update(['content' => json_encode($update_content)]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$update_content['product_id'] = $find['product_id'];
|
|
||||||
Db::name('store_product_content')
|
|
||||||
->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]);
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
halt($e->getMessage(), $e->getLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
halt(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transcoding($fileName)
|
public function transcoding($fileName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user