Parcourir la source

梳理从供货商选品至商品表功能

sunxbiao il y a 1 an
Parent
commit
668637107c
1 fichiers modifiés avec 59 ajouts et 48 suppressions
  1. 59 48
      app/controller/merchant/gong/Goods.php

+ 59 - 48
app/controller/merchant/gong/Goods.php

@@ -228,68 +228,79 @@ class Goods extends BaseController
228
         return app('json')->success($successJoin . '个商品加入成功,' . $failJoin . '个商品加入失败,' . $joinNum . '个商品已经加入');
228
         return app('json')->success($successJoin . '个商品加入成功,' . $failJoin . '个商品加入失败,' . $joinNum . '个商品已经加入');
229
     }
229
     }
230
 
230
 
231
-    public function insert_product($spu_id, $mer_id) {
231
+    /**
232
+     * 将 微唯宝商品 选品(加入) 到系统内部商户商品表
233
+     * @param $spu_id
234
+     * @param $mer_id
235
+     * @return bool
236
+     */
237
+    public function insert_product($spu_id, $mer_id)
238
+    {
232
         try {
239
         try {
233
-            $data=Db::name('douhuomall')->where('spu_id',$spu_id)->find();
234
-            // 是否为多规格
235
-            $sku_data=json_decode($data['skuId_info'],true);
236
-            $spec_type=count($sku_data);
237
-            if($spec_type>1){
238
-                $spec_type=1;
239
-            }else{
240
-                $spec_type=0;
240
+            // 1、获取商品信息
241
+            $data = Db::name('douhuomall')->where('spu_id', $spu_id)->find();
242
+
243
+            // 2、是否为多规格
244
+            $sku_data = json_decode($data['skuId_info'], true);
245
+            $spec_type = count($sku_data);
246
+            if ($spec_type > 1) {
247
+                $spec_type = 1;
248
+            } else {
249
+                $spec_type = 0;
241
             }
250
             }
242
 
251
 
243
-            //商品主图
244
-            $spuId_info=json_decode($data['spuId_info'],true);
245
-            $slider_image=$spuId_info['detail_img_list']??'';
246
-            $image=$spuId_info['cover_url']??'';
247
-
248
-            $slider_image = empty($slider_image) ? $image : implode(',',json_decode($slider_image,true));
252
+            // 3、商品主图
253
+            $spuId_info = json_decode($data['spuId_info'], true);
254
+            $slider_image = $spuId_info['detail_img_list'] ?? '';
255
+            $image = $spuId_info['cover_url'] ?? '';
256
+            $slider_image = empty($slider_image) ? $image : implode(',', json_decode($slider_image, true));
249
             $yanglaojin_scale = (!empty($data['pension']) && !empty($data['market_price'])) ? bcdiv($data['pension'], $data['market_price'], 2) : 0;
257
             $yanglaojin_scale = (!empty($data['pension']) && !empty($data['market_price'])) ? bcdiv($data['pension'], $data['market_price'], 2) : 0;
250
-            //商品入库数据
251
-            $product_insert_data=[
252
-                'mer_id'=>$mer_id,
253
-                'image'=>$image,
254
-                'slider_image'=>$slider_image,
255
-                'store_name'=>$data['title'],
256
-                'store_info'=>1,
257
-                'keyword'=>mb_substr($data['title'],0,3),
258
-                'is_show'=> ($mer_id == $this->specialMerId) ? 1:0,
259
-                'status'=>1,
260
-                'cate_id'=> ($mer_id == $this->specialMerId) ? $data['cxb_cate_id'] : $data['cate_ids'],
261
-                'unit_name'=>'个',
262
-                'price'=>$data['market_price'],
263
-                'cost'=>$data['cost_price'],
264
-                'ot_price'=>$data['ot_price'],
265
-                'stock'=>'1000',
266
-                'spec_type'=>$spec_type,
267
-                'extension_type'=>1,
268
-                'mer_status'=>1,
269
-                'is_used'=>1,
270
-                'old_product_id'=>$data['id'],
271
-                'volunteer'=>0,
272
-                'type'=>($mer_id == $this->specialMerId) ? 5: 1,
273
-                'pension'=>'0.00',
274
-                'commission'=>5,
275
-                'spu_id'=>$data['spu_id'],
258
+
259
+            // 4、商品入库数据
260
+            $product_insert_data = [
261
+                'mer_id' => $mer_id,
262
+                'image' => $image,
263
+                'slider_image' => $slider_image,
264
+                'store_name' => $data['title'],
265
+                'store_info' => 1,
266
+                'keyword' => mb_substr($data['title'], 0, 3),
267
+                'is_show' => ($mer_id == $this->specialMerId) ? 1 : 0,
268
+                'status' => 1,
269
+                'cate_id' => ($mer_id == $this->specialMerId) ? $data['cxb_cate_id'] : $data['cate_ids'],
270
+                'unit_name' => '个',
271
+                'price' => $data['market_price'],
272
+                'cost' => $data['cost_price'],
273
+                'ot_price' => $data['ot_price'],
274
+                'stock' => '1000',
275
+                'spec_type' => $spec_type,
276
+                'extension_type' => 1,
277
+                'mer_status' => 1,
278
+                'is_used' => 1,
279
+                'old_product_id' => $data['id'],
280
+                'volunteer' => 0,
281
+                'type' => ($mer_id == $this->specialMerId) ? 5 : 1,
282
+                'pension' => '0.00',
283
+                'commission' => 5,
284
+                'spu_id' => $data['spu_id'],
276
                 'temp_id' => 105,
285
                 'temp_id' => 105,
277
                 'plate_mer_profit' => $data['mer_profit'],
286
                 'plate_mer_profit' => $data['mer_profit'],
278
-		        'concession_pri' => $data['mer_profit'],
287
+                'concession_pri' => $data['mer_profit'],
279
                 'yanglaojin_scale' => $yanglaojin_scale
288
                 'yanglaojin_scale' => $yanglaojin_scale
280
             ];
289
             ];
281
-            $insert_id=Db::name('store_product')->insertGetId($product_insert_data);
290
+            $insert_id = Db::name('store_product')->insertGetId($product_insert_data);
282
 
291
 
292
+            // 5、更新商品详情表
283
             $detail = $spuId_info['detail'];
293
             $detail = $spuId_info['detail'];
284
-            if(!is_null(json_decode($detail))){
294
+            if (!is_null(json_decode($detail))) {
285
                 $detail_list = json_decode($detail);
295
                 $detail_list = json_decode($detail);
286
                 $detail = '';
296
                 $detail = '';
287
-                foreach($detail_list as $value){
288
-                    $detail .= '<img src="'.$value.'"></img>';
297
+                foreach ($detail_list as $value) {
298
+                    $detail .= '<img src="' . $value . '"></img>';
289
                 }
299
                 }
290
             }
300
             }
291
-            Db::name('store_product_content')->insert(['content'=>$detail,'product_id'=>$insert_id]);
292
-            $this->insert_sku($insert_id,$sku_data);
301
+            Db::name('store_product_content')->insert(['content' => $detail, 'product_id' => $insert_id]);
302
+
303
+            $this->insert_sku($insert_id, $sku_data);
293
             return true;
304
             return true;
294
         } catch (Exception $e) {
305
         } catch (Exception $e) {
295
             Log::error($spu_id . "加入选品失败:" . $e->getMessage());
306
             Log::error($spu_id . "加入选品失败:" . $e->getMessage());