shish 1 год назад
Родитель
Сommit
d5e300cf0a
1 измененных файлов с 44 добавлено и 0 удалено
  1. 44 0
      app-ghs/controllers/ItemController.php

+ 44 - 0
app-ghs/controllers/ItemController.php

@@ -529,6 +529,50 @@ class ItemController extends BaseController
         util::success($respond);
     }
 
+    //下载商品码,用于花市卖花 ssh 20240823
+    public function actionDownMiniCode()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? 0;
+        $item = ItemClass::getById($id, true);
+        if (empty($item)) {
+            util::fail('没有找到花材');
+        }
+        if ($item->mainId != $this->mainId) {
+            util::fail('不是你的花材');
+        }
+        $merchant = WxOpenClass::getWxInfo();
+        $page = 'admin/ghsProduct/detail';
+        $ptStyle = dict::getDict('ptStyle', 'hd');
+
+        //小程序码,scene不能超过32个字条
+        $scene = "id=" . $id . '&sId=' . $this->shopId;
+        $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
+        $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
+        $miniCodeBase64 = stringUtil::ossBase64($miniCode);
+
+        $prefix = imgUtil::getPrefix();
+        $url = $prefix . 'poster/mini_bg.jpg?x-oss-process=image';
+        //小程序码
+        $url .= '/watermark,image_' . $miniCodeBase64 . ',g_nw,x_0,y_0';
+
+        $name = $item->name ?? '';
+        $nameBase64 = stringUtil::ossBase64($name);
+        //标题
+        $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
+
+        $file = fopen($url, "rb");
+        Header("Content-type:  application/octet-stream ");
+        Header("Accept-Ranges:  bytes ");
+        Header("Content-Disposition:  attachment;filename={$name}.jpg");
+        $contents = "";
+        while (!feof($file)) {
+            $contents .= fread($file, 8192);
+        }
+        echo $contents;
+        fclose($file);
+    }
+
     //获取给花店下单的花材海报 ssh 20220111
     public function actionGetHdPoster()
     {