浏览代码

获取海报

shish 1 年之前
父节点
当前提交
2eab96d7b9
共有 1 个文件被更改,包括 86 次插入1 次删除
  1. 86 1
      app-hd/controllers/ItemController.php

+ 86 - 1
app-hd/controllers/ItemController.php

@@ -9,7 +9,10 @@ use bizGhs\item\classes\ItemClass;
 use bizGhs\item\services\ItemService;
 use bizHd\custom\classes\CustomClass;
 use bizHd\product\classes\ProductClass;
+use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
+use common\components\imgUtil;
+use common\components\miniUtil;
 use common\components\stringUtil;
 use common\components\util;
 use Yii;
@@ -261,4 +264,86 @@ class ItemController extends BaseController
         $list = PtItemClass::getItemList($where);
         util::success($list);
     }
-}
+
+    //获取给散客下单的花材海报 ssh 20220111
+    public function actionGetPoster()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $item = ItemClass::getById($id, true);
+        if (empty($item) || $item->mainId != $this->mainId) {
+            util::fail('获取失败');
+        }
+        $cover = $item->cover ?? '';
+        if (empty($cover)) {
+            util::fail('获取失败');
+        }
+
+        $merchant = WxOpenClass::getMallWxInfo();
+        $page = 'pages/item/detail';
+        $ptStyle = dict::getDict('ptStyle', 'mall');
+        $shop = $this->shop;
+        $lsShopId = $shop->lsShopId ?? 0;
+        //scene不能超过32个字条
+        $scene = "id=" . $id . '&a=' . $lsShopId;
+        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
+        $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
+        $miniCodeBase64 = stringUtil::ossBase64($miniCode);
+
+        Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
+
+        $prefix = imgUtil::getPrefix();
+
+        $price = $item->skPrice ?? 0;
+        if ($item->discountPrice > 0) {
+            $skMore = $item->skMore ?? 0;
+            $price = bcadd($item->discountPrice, $skMore, 2);
+        }
+        $newPrice = '¥' . floatval($price);
+        $priceBase64 = stringUtil::ossBase64($newPrice);
+
+        $name = $item->name ?? '';
+        $nameBase64 = stringUtil::ossBase64($name);
+
+        $staff = $this->shopAdmin;
+        $staffName = $staff->name ?? '';
+        $newStaffName = $staffName . ' 为您推荐';
+        $staffNameBase64 = stringUtil::ossBase64($newStaffName);
+
+        //花材主图
+        $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
+        $itemCoverBase64 = stringUtil::ossBase64($itemCover);
+
+        $logoBase64 = '';
+        if (in_array($this->mainId, [52, 1459, 13495])) {
+            $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
+            if ($this->mainId == 1459) {
+                $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
+            }
+            if ($this->mainId == 13495) {
+                $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
+            }
+            $logoBase64 = stringUtil::ossBase64($logo);
+        }
+
+        $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
+        //花材主图
+        $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
+        //小程序码
+        $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
+        if (!empty($logoBase64)) {
+            //logo
+            $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
+        }
+        //为你推荐
+        $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
+        //标题
+        $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
+        //价格
+        $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
+
+        $respond = ['imgUrl' => $url];
+        util::success($respond);
+    }
+
+}