|
@@ -0,0 +1,60 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Modules\Mini\Services;
|
|
|
+
|
|
|
+use App\Base\BaseService;
|
|
|
+use App\Exceptions\ClientException;
|
|
|
+use App\Models\Goods\Goods;
|
|
|
+use App\Models\Goods\GoodsSku;
|
|
|
+use App\Models\Goods\Spec;
|
|
|
+use App\Models\Goods\SpecAttr;
|
|
|
+
|
|
|
+class GoodsService extends BaseService
|
|
|
+{
|
|
|
+ public function info($params)
|
|
|
+ {
|
|
|
+ $id = $params['id'];
|
|
|
+ $goods = Goods::where("status", Goods::STATUS_OK)->where("id", $id)->first();
|
|
|
+
|
|
|
+ $goods->view_total++;
|
|
|
+ $goods->save();
|
|
|
+ return [
|
|
|
+ "id" => $goods->id,
|
|
|
+ "image_list" => $goods->image_list,
|
|
|
+ "spec" => array_map(function ($specId) {
|
|
|
+ try {
|
|
|
+ /** @var Spec $spec */
|
|
|
+ $spec = Spec::find($specId);
|
|
|
+ return [
|
|
|
+ "id" => $spec->id,
|
|
|
+ "name" => $spec->name,
|
|
|
+ "is_custom" => $spec->is_custom,
|
|
|
+ "attr" => $spec->attrs->map(function (SpecAttr $a) {
|
|
|
+ return [
|
|
|
+ "id" => $a->id,
|
|
|
+ "name" => $a->name,
|
|
|
+ ];
|
|
|
+ }),
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ throw new ClientException("商品规格有误,请联系管理员");
|
|
|
+ }
|
|
|
+ }, $goods->spec),
|
|
|
+ "sku" => $goods->sku->map(function (GoodsSku $sku) {
|
|
|
+ if (empty($sku->sn)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ "id" => $sku->id,
|
|
|
+ "sn" => $sku->sn,
|
|
|
+ "url_3d" => $sku->url_3d,
|
|
|
+ "spec_attr" => $sku->spec_attr_list,
|
|
|
+ ];
|
|
|
+ })->filter()->values(),
|
|
|
+ "desc_html" => $goods->desc_html,
|
|
|
+ "faq_html" => $goods->faq_html,
|
|
|
+ "spec_attr_html" => $goods->spec_attr_html,
|
|
|
+ ];
|
|
|
+
|
|
|
+ }
|
|
|
+}
|