|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
<?php
|
|
|
2
|
+
|
|
2
|
3
|
namespace app\controller\api\douhuomall;
|
|
3
|
4
|
|
|
4
|
5
|
use app\traits\GongApiRequest;
|
|
|
@@ -119,55 +120,55 @@ class Take
|
|
119
|
120
|
}
|
|
120
|
121
|
}
|
|
121
|
122
|
|
|
122
|
|
- public function updata_product_img($spu_id){
|
|
|
123
|
+ public function updata_product_img($spu_id)
|
|
|
124
|
+ {
|
|
123
|
125
|
// 1、验证该 SPUId 是否上架了 如果上架了 需要去更新商品 图片
|
|
124
|
|
- $product_id = Db::name('store_product')->where('spu_id',$spu_id)->value('product_id');
|
|
125
|
|
- if(!$product_id) return true;
|
|
|
126
|
+ $product_id = Db::name('store_product')->where('spu_id', $spu_id)->value('product_id');
|
|
|
127
|
+ if (!$product_id) return true;
|
|
126
|
128
|
|
|
127
|
129
|
// 2、查找微唯宝 商品
|
|
128
|
|
- $data = Db::name('douhuomall')->where('spu_id',$spu_id)->find();
|
|
|
130
|
+ $data = Db::name('douhuomall')->where('spu_id', $spu_id)->find();
|
|
129
|
131
|
|
|
130
|
132
|
// 3、获取 商品主图
|
|
131
|
|
- $spuId_info=json_decode($data['spuId_info'],true);
|
|
132
|
|
- $slider_image=$spuId_info['detail_img_list']??'';
|
|
133
|
|
- $image=$spuId_info['cover_url']??'';
|
|
|
133
|
+ $spuId_info = json_decode($data['spuId_info'], true);
|
|
|
134
|
+ $slider_image = $spuId_info['detail_img_list'] ?? '';
|
|
|
135
|
+ $image = $spuId_info['cover_url'] ?? '';
|
|
134
|
136
|
try {
|
|
135
|
|
- $slider_image = implode(',',json_decode($slider_image,true));
|
|
136
|
|
- }catch (\Exception $exception){
|
|
|
137
|
+ $slider_image = implode(',', json_decode($slider_image, true));
|
|
|
138
|
+ } catch (\Exception $exception) {
|
|
137
|
139
|
$slider_image = $image;
|
|
138
|
140
|
}
|
|
139
|
141
|
|
|
140
|
142
|
//更新产品图片数据
|
|
141
|
|
- $product_insert_data=[
|
|
142
|
|
- 'image'=>$image,
|
|
143
|
|
- 'slider_image'=>$slider_image,
|
|
|
143
|
+ $product_insert_data = [
|
|
|
144
|
+ 'image' => $image,
|
|
|
145
|
+ 'slider_image' => $slider_image,
|
|
144
|
146
|
];
|
|
145
|
|
- Db::name('store_product')->where('product_id',$product_id)->update($product_insert_data);
|
|
146
|
|
- echo '更新产品图片数据成功'.json_encode($product_insert_data);
|
|
|
147
|
+ Db::name('store_product')->where('product_id', $product_id)->update($product_insert_data);
|
|
|
148
|
+ echo '更新产品图片数据成功' . json_encode($product_insert_data);
|
|
147
|
149
|
$detail = $spuId_info['detail'];
|
|
148
|
|
- if(!is_null(json_decode($detail))){
|
|
|
150
|
+ if (!is_null(json_decode($detail))) {
|
|
149
|
151
|
$detail_list = json_decode($detail);
|
|
150
|
152
|
$detail = '';
|
|
151
|
|
- foreach($detail_list as $value){
|
|
152
|
|
- $detail .= "<img src='".$value."' referrerpolicy='no-referrer' /></img>";
|
|
|
153
|
+ foreach ($detail_list as $value) {
|
|
|
154
|
+ $detail .= "<img src='" . $value . "' referrerpolicy='no-referrer' /></img>";
|
|
153
|
155
|
}
|
|
154
|
156
|
}
|
|
155
|
|
- Db::name('store_product_content')->where('product_id',$product_id)->update(['content'=>$detail]);
|
|
|
157
|
+ Db::name('store_product_content')->where('product_id', $product_id)->update(['content' => $detail]);
|
|
156
|
158
|
return true;
|
|
157
|
159
|
}
|
|
158
|
160
|
|
|
159
|
161
|
|
|
160
|
|
-
|
|
161
|
162
|
public function seveImg($goods_id, $img_url, $targetDir)
|
|
162
|
163
|
{
|
|
163
|
164
|
return $img_url;
|
|
164
|
|
- if(!$img_url) return $img_url;
|
|
165
|
|
- if (is_array($img_url)){
|
|
|
165
|
+ if (!$img_url) return $img_url;
|
|
|
166
|
+ if (is_array($img_url)) {
|
|
166
|
167
|
$new_img_url = [];
|
|
167
|
168
|
foreach ($img_url as $value) {
|
|
168
|
169
|
$new_img_url[] = $this->seveImgUrl($goods_id, $value, $targetDir);
|
|
169
|
170
|
}
|
|
170
|
|
- }else{
|
|
|
171
|
+ } else {
|
|
171
|
172
|
$new_img_url = $this->seveImgUrl($goods_id, $img_url, $targetDir);
|
|
172
|
173
|
}
|
|
173
|
174
|
return $new_img_url;
|
|
|
@@ -176,7 +177,7 @@ class Take
|
|
176
|
177
|
public function seveImgUrl($goods_id, $remoteImageUrl, $targetDir)
|
|
177
|
178
|
{
|
|
178
|
179
|
// 目标路径(确保目录存在)
|
|
179
|
|
- $targetDirTow = rand(1000, 10000). $this->upImgName(basename($remoteImageUrl));
|
|
|
180
|
+ $targetDirTow = rand(1000, 10000) . $this->upImgName(basename($remoteImageUrl));
|
|
180
|
181
|
$targetPath = $targetDir . $targetDirTow; // 使用basename获取文件名
|
|
181
|
182
|
|
|
182
|
183
|
// 检查目标目录是否存在,如果不存在则创建
|
|
|
@@ -193,7 +194,7 @@ class Take
|
|
193
|
194
|
if ($imageContent !== false) {
|
|
194
|
195
|
// 保存图片到指定路径
|
|
195
|
196
|
if (file_put_contents($targetPath, $imageContent)) {
|
|
196
|
|
- $new_img_url = env('APP_URL').'/images/gong/'.$goods_id.'/'. $targetDirTow;
|
|
|
197
|
+ $new_img_url = env('APP_URL') . '/images/gong/' . $goods_id . '/' . $targetDirTow;
|
|
197
|
198
|
return $new_img_url;
|
|
198
|
199
|
} else {
|
|
199
|
200
|
echo "保存图片时发生错误。";
|
|
|
@@ -215,7 +216,8 @@ class Take
|
|
215
|
216
|
return $filename;
|
|
216
|
217
|
}
|
|
217
|
218
|
|
|
218
|
|
- public function deleteFilesInDirectory($dir) {
|
|
|
219
|
+ public function deleteFilesInDirectory($dir)
|
|
|
220
|
+ {
|
|
219
|
221
|
if (!is_dir($dir)) return true;
|
|
220
|
222
|
|
|
221
|
223
|
// 打开目录
|
|
|
@@ -262,12 +264,12 @@ class Take
|
|
262
|
264
|
&& $data['market_price'] == $findData['market_price']
|
|
263
|
265
|
&& $data['profit'] == $findData['profit']) {
|
|
264
|
266
|
$count = Db::name('store_product')
|
|
265
|
|
- ->where('spu_id','=', $data['spu_id'])
|
|
266
|
|
- ->where('is_show','=', 0)
|
|
267
|
|
- ->where('is_status','=', 0)
|
|
|
267
|
+ ->where('spu_id', '=', $data['spu_id'])
|
|
|
268
|
+ ->where('is_show', '=', 0)
|
|
|
269
|
+ ->where('is_status', '=', 0)
|
|
268
|
270
|
->count();
|
|
269
|
271
|
if ($count) {
|
|
270
|
|
- Db::name('store_product')->where('spu_id','=', $data['spu_id'])->update([
|
|
|
272
|
+ Db::name('store_product')->where('spu_id', '=', $data['spu_id'])->update([
|
|
271
|
273
|
'is_show' => 1
|
|
272
|
274
|
]);
|
|
273
|
275
|
}
|
|
|
@@ -301,7 +303,7 @@ class Take
|
|
301
|
303
|
public function remove($goodsIds)
|
|
302
|
304
|
{
|
|
303
|
305
|
Db::startTrans();
|
|
304
|
|
- try{
|
|
|
306
|
+ try {
|
|
305
|
307
|
// 删除选品库对应的数据
|
|
306
|
308
|
Db::name('douhuomall')->whereIn('spu_id', $goodsIds)->update([
|
|
307
|
309
|
'status' => 3,
|
|
|
@@ -325,11 +327,12 @@ class Take
|
|
325
|
327
|
/**
|
|
326
|
328
|
* 二维数组根据某个字段排序
|
|
327
|
329
|
* @param array $array 要排序的数组
|
|
328
|
|
- * @param string $keys 要排序的键字段
|
|
329
|
|
- * @param string $sort 排序类型 SORT_ASC SORT_DESC
|
|
|
330
|
+ * @param string $keys 要排序的键字段
|
|
|
331
|
+ * @param string $sort 排序类型 SORT_ASC SORT_DESC
|
|
330
|
332
|
* @return array 排序后的数组
|
|
331
|
333
|
*/
|
|
332
|
|
- function arrSort($array, $keys, $sort = SORT_DESC) {
|
|
|
334
|
+ function arrSort($array, $keys, $sort = SORT_DESC)
|
|
|
335
|
+ {
|
|
333
|
336
|
$keysValue = [];
|
|
334
|
337
|
foreach ($array as $k => $v) {
|
|
335
|
338
|
$keysValue[$k] = $v[$keys];
|