Poster.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\system;
  11. use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
  12. use addon\store\model\Config as StoreConfig;
  13. use app\model\BaseModel;
  14. use app\model\upload\Upload;
  15. use app\model\web\Config;
  16. use extend\Poster as PosterExtend;
  17. /**
  18. * 海报生成类
  19. */
  20. class Poster extends BaseModel
  21. {
  22. /**
  23. * 商品海报
  24. */
  25. public function goods($app_type, $page, $qrcode_param, $promotion_type, $site_id, $store_id = 0)
  26. {
  27. try {
  28. $goods_info = $this->getGoodsInfo($qrcode_param[ 'goods_id' ], $site_id, $store_id);
  29. if (empty($goods_info)) return $this->error('未获取到商品信息');
  30. $qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
  31. if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
  32. //判断海报是否存在或停用
  33. $template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
  34. $site_model = new Site();
  35. $condition = array (
  36. [ "site_id", "=", $site_id ]
  37. );
  38. $site_info = $site_model->getSiteInfo($condition);
  39. if (!empty($qrcode_param[ 'source_member' ])) {
  40. $member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
  41. }
  42. $upload_config_model = new Config();
  43. $upload_config_result = $upload_config_model->getDefaultImg($site_id);
  44. if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
  45. $poster_width = 720;
  46. $poster_height = 1150;
  47. $poster = new PosterExtend($poster_width, $poster_height);
  48. $option = [
  49. [
  50. 'action' => 'setBackground', // 设背景色
  51. 'data' => [ 255, 255, 255 ]
  52. ],
  53. [
  54. 'action' => 'imageCopy', // 写入商品图
  55. 'data' => [
  56. explode(',', $goods_info[ 'goods_image' ])[ 0 ] ?? '',
  57. 50,
  58. 165,
  59. 620,
  60. 620,
  61. 'square',
  62. true,
  63. 1
  64. ]
  65. ],
  66. [
  67. 'action' => 'imageText', // 写入商品名称
  68. 'data' => [
  69. $goods_info[ 'goods_name' ],
  70. 22,
  71. [ 35, 35, 35 ],
  72. 50,
  73. 915,
  74. 360,
  75. 2,
  76. true,
  77. 1
  78. ]
  79. ],
  80. [
  81. 'action' => 'imageCopy', // 写入商品二维码
  82. 'data' => [
  83. $qrcode_info[ 'data' ][ 'path' ],
  84. 435,
  85. 825,
  86. 240,
  87. 240,
  88. 'square',
  89. 0,
  90. 1
  91. ]
  92. ],
  93. [
  94. 'action' => 'imageText', // 写入提示
  95. 'data' => [
  96. '长按识别二维码',
  97. 19,
  98. [ 102, 102, 102 ],
  99. 465,
  100. 1110,
  101. 490,
  102. 1,
  103. 1,
  104. 1
  105. ]
  106. ],
  107. [
  108. 'action' => 'imageText', // 写入商品价格单位
  109. 'data' => [
  110. '¥',
  111. 27,
  112. [ 255, 0, 0 ],
  113. 50,
  114. 860,
  115. 490,
  116. 2,
  117. true,
  118. 1
  119. ]
  120. ],
  121. [
  122. 'action' => 'imageText', // 写入商品价格
  123. 'data' => [
  124. $goods_info[ 'discount_price' ],
  125. 30,
  126. [ 255, 0, 0 ],
  127. 78,
  128. 862,
  129. 490,
  130. 2,
  131. true,
  132. 1
  133. ]
  134. ],
  135. ];
  136. if (!empty($member_info)) {
  137. $member_option = [
  138. [
  139. 'action' => 'imageCircularCopy', // 写入用户头像
  140. 'data' => [
  141. !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
  142. 50,
  143. 30,
  144. 100,
  145. 100
  146. ]
  147. ],
  148. [
  149. 'action' => 'imageText', // 写入分享人昵称
  150. 'data' => [
  151. $member_info[ 'nickname' ],
  152. 22,
  153. [ 10, 10, 10 ],
  154. 170,
  155. 80,
  156. 580,
  157. 1,
  158. 1,
  159. 1
  160. ]
  161. ],
  162. [
  163. 'action' => 'imageText', // 写入分享人昵称
  164. 'data' => [
  165. '分享给你一个商品',
  166. 18,
  167. [ 102, 102, 102 ],
  168. 170,
  169. 115,
  170. 580,
  171. 1,
  172. 1,
  173. 1
  174. ]
  175. ]
  176. ];
  177. $option = array_merge($option, $member_option);
  178. }
  179. } else {
  180. $condition = [
  181. [ 'template_id', '=', $goods_info[ 'template_id' ] ],
  182. [ 'site_id', '=', $site_id ]
  183. ];
  184. $poster_template_model = new PosterTemplateModel();
  185. $poster_data = $poster_template_model->getPosterTemplateInfo($condition);
  186. $poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
  187. $poster_width = 720;
  188. $poster_height = 1280;
  189. $poster = new PosterExtend($poster_width, $poster_height);
  190. $fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
  191. if ($goods_info[ 'price' ] == 0) {
  192. $line = '一一一';
  193. } else {
  194. $line = '一一一一';
  195. }
  196. if (!empty($poster_data[ 'data' ][ 'background' ])) {
  197. $background = str_replace(" ", "", img($poster_data[ 'data' ][ 'background' ]));
  198. list($width, $height, $type, $attr) = getimagesize($background);
  199. $height = 720 * $height / $width;
  200. $back_ground = [
  201. 'action' => 'imageCopy', // 写入背景图
  202. 'data' => [
  203. img($poster_data[ 'data' ][ 'background' ]),
  204. 0,
  205. 0,
  206. $poster_width,
  207. $poster_height,
  208. 'square',
  209. true,
  210. 1
  211. ]
  212. ];
  213. } else {
  214. $back_ground = [
  215. 'action' => 'setBackground', // 设背景色
  216. 'data' => [ 255, 255, 255 ]
  217. ];
  218. }
  219. $ground = [ [
  220. 'action' => 'setBackground', // 设背景色
  221. 'data' => [ 255, 255, 255 ]
  222. ] ];
  223. $option = [
  224. $back_ground,
  225. [
  226. 'action' => 'imageText', // 写入店铺名称
  227. 'data' => [
  228. $site_info[ 'data' ][ 'site_name' ],
  229. $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate * 2,
  230. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
  231. $poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
  232. ( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
  233. $poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
  234. $poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
  235. true,
  236. $poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
  237. ]
  238. ],
  239. [
  240. 'action' => 'imageCopy', // 店铺logo
  241. 'data' => [
  242. !empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
  243. $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
  244. $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
  245. $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
  246. $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
  247. 'square',
  248. true,
  249. $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
  250. ]
  251. ],
  252. [
  253. 'action' => 'imageCopy', // 写入商品图
  254. 'data' => [
  255. $goods_info[ 'sku_image' ],
  256. $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
  257. $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
  258. $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
  259. $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
  260. !empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
  261. 0,
  262. $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
  263. ]
  264. ],
  265. [
  266. 'action' => 'imageText', // 写入商品名称
  267. 'data' => [
  268. $goods_info[ 'goods_name' ],
  269. $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
  270. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
  271. $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
  272. ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2 + 10,
  273. $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
  274. 1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
  275. true,
  276. $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
  277. ]
  278. ],
  279. [
  280. 'action' => 'imageCopy', // 写入商品二维码
  281. 'data' => [
  282. $qrcode_info[ 'data' ][ 'path' ],
  283. $poster_data[ 'data' ][ 'qrcode_left' ] * 2,
  284. $poster_data[ 'data' ][ 'qrcode_top' ] * 2,
  285. $poster_data[ 'data' ][ 'qrcode_width' ] * 2,
  286. $poster_data[ 'data' ][ 'qrcode_height' ] * 2,
  287. 'square',
  288. 0,
  289. 1
  290. ]
  291. ],
  292. [
  293. 'action' => 'imageText', // 写入商品价格
  294. 'data' => [
  295. '¥' . $goods_info[ 'discount_price' ],
  296. $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
  297. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
  298. $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
  299. ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
  300. $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
  301. $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
  302. true,
  303. $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
  304. ]
  305. ],
  306. ];
  307. if ($goods_info[ 'market_price' ] > 0) {
  308. $market_price = [
  309. [
  310. 'action' => 'imageText', // 写入商品划线价格
  311. 'data' => [
  312. '¥' . $goods_info[ 'market_price' ],
  313. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
  314. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
  315. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
  316. ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
  317. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
  318. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
  319. true,
  320. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
  321. ]
  322. ],
  323. [
  324. 'action' => 'imageText', // 写入线
  325. 'data' => [
  326. $line,
  327. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
  328. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
  329. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2 - 5,
  330. ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
  331. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
  332. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
  333. true,
  334. $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
  335. ]
  336. ],
  337. ];
  338. $option = array_merge($option, $market_price);
  339. }
  340. if (!empty($member_info)) {
  341. $member_option = [
  342. [
  343. 'action' => 'imageCopy', // 写入用户头像
  344. 'data' => [
  345. !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
  346. $poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
  347. $poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
  348. $poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
  349. $poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
  350. !empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
  351. 0,
  352. $poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
  353. ]
  354. ],
  355. [
  356. 'action' => 'imageText', // 写入分享人昵称
  357. 'data' => [
  358. $member_info[ 'nickname' ],
  359. $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
  360. hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
  361. $poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
  362. ( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
  363. $poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
  364. $poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
  365. 0,
  366. $poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
  367. ]
  368. ],
  369. ];
  370. $option = array_merge($ground, $option, $member_option);
  371. }
  372. }
  373. $option_res = $poster->create($option);
  374. if (is_array($option_res)) return $option_res;
  375. $res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'goods_id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
  376. if ($res[ 'code' ] == 0) {
  377. $upload = new Upload($site_id);
  378. $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
  379. if ($cloud_res[ 'code' ] >= 0) {
  380. return $this->success([ "path" => $cloud_res[ 'data' ] ]);
  381. } else {
  382. return $this->error();
  383. }
  384. }
  385. return $res;
  386. } catch (\Exception $e) {
  387. return $this->error($e->getMessage());
  388. }
  389. }
  390. /**
  391. * 获取用户信息
  392. * @param unknown $member_id
  393. */
  394. private function getMemberInfo($member_id)
  395. {
  396. $info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
  397. return $info;
  398. }
  399. /**
  400. * 获取商品信息
  401. * @param unknown $sku_id
  402. */
  403. private function getGoodsInfo($goods_id, $site_id, $store_id)
  404. {
  405. $field = 'g.goods_id,g.goods_name,g.introduction,gs.price,gs.discount_price,g.goods_image,g.sku_id,gs.collect_num,g.template_id,g.market_price,gs.sku_image';
  406. $join = [
  407. [ 'goods_sku gs', 'gs.sku_id=g.sku_id', 'left' ]
  408. ];
  409. if (!empty($store_id)) {
  410. $store_config = ( new StoreConfig() )->getStoreBusinessConfig($site_id)[ 'data' ][ 'value' ];
  411. if ($store_config[ 'store_business' ] == 'store') {
  412. $join[] = [ 'store_goods_sku sgs', 'gs.sku_id = sgs.sku_id and sgs.store_id=' . $store_id, 'left' ];
  413. $field = str_replace('gs.price', 'IFNULL(IF(g.is_unify_price = 1,gs.price,sgs.price), gs.price) as price', $field);
  414. $field = str_replace('gs.discount_price', 'IFNULL(IF(g.is_unify_price = 1,gs.discount_price,sgs.price), gs.discount_price) as discount_price', $field);
  415. }
  416. }
  417. $info = model('goods')->getInfo([ 'g.goods_id' => $goods_id ], $field, 'g', $join);
  418. return $info;
  419. }
  420. /**
  421. * 获取商品二维码
  422. * @param unknown $app_type 请求类型
  423. * @param unknown $page uniapp页面路径
  424. * @param unknown $qrcode_param 二维码携带参数
  425. * @param string $promotion_type 活动类型 null为无活动
  426. */
  427. private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
  428. {
  429. $res = event('Qrcode', [
  430. 'site_id' => $site_id,
  431. 'app_type' => $app_type,
  432. 'type' => 'create',
  433. 'data' => $qrcode_param,
  434. 'page' => $page,
  435. 'qrcode_path' => 'upload/qrcode/goods',
  436. 'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'goods_id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
  437. ], true);
  438. return $res;
  439. }
  440. /**
  441. * 获取海报信息
  442. * @param unknown $template_id
  443. */
  444. private function getTemplateInfo($template_id)
  445. {
  446. $info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
  447. return $info;
  448. }
  449. /**
  450. * 分享图片
  451. * @param $page
  452. * @param $qrcode_param
  453. * @param $site_id
  454. * @return array|\extend\multitype|PosterExtend|string|string[]
  455. */
  456. public function shareImg($page, $qrcode_param, $site_id, $store_id = 0)
  457. {
  458. try {
  459. $goods_info = $this->getGoodsInfo($qrcode_param[ 'goods_id' ], $site_id, $store_id);
  460. if (empty($goods_info)) return $this->error('未获取到商品信息');
  461. // $file_path = 'upload/share_img/goods_'.$goods_info['goods_id'] .'/sku_'.$goods_info['sku_id'] .'.jpg';
  462. // if (file_exists($file_path)) return $this->success(['path' => $file_path]);
  463. $poster_width = 600;
  464. $poster_height = 480;
  465. $poster = new PosterExtend($poster_width, $poster_height);
  466. $option = [
  467. [
  468. 'action' => 'setBackground', // 设背景色
  469. 'data' => [ 255, 255, 255 ]
  470. ],
  471. [
  472. 'action' => 'imageCopy', // 商品图
  473. 'data' => [
  474. $goods_info[ 'sku_image' ],
  475. 30,
  476. 50,
  477. 200,
  478. 200,
  479. 'square',
  480. 50,
  481. 1
  482. ]
  483. ],
  484. [
  485. 'action' => 'imageText', // 写入商品名称
  486. 'data' => [
  487. $goods_info[ 'goods_name' ],
  488. 25,
  489. [ 51, 51, 51 ],
  490. 250,
  491. 100,
  492. 330,
  493. 2,
  494. false,
  495. 1
  496. ]
  497. ],
  498. [
  499. 'action' => 'imageText', // 写入商品价格
  500. 'data' => [
  501. '¥',
  502. 15,
  503. [ 255, 0, 0 ],
  504. 250,
  505. 230,
  506. 300,
  507. 2,
  508. false,
  509. 1,
  510. PUBLIC_PATH . 'static/font/custom.ttf'
  511. ]
  512. ],
  513. [
  514. 'action' => 'imageText', // 写入商品价格
  515. 'data' => [
  516. $goods_info[ 'discount_price' ],
  517. 32,
  518. [ 255, 0, 0 ],
  519. 265,
  520. 230,
  521. 300,
  522. 2,
  523. false,
  524. 1,
  525. PUBLIC_PATH . 'static/font/custom.ttf'
  526. ]
  527. ],
  528. [
  529. 'action' => 'imageCopy', // 背景图
  530. 'data' => [
  531. 'upload/share_img/bg/goods_1.png',
  532. 0,
  533. 0,
  534. 600,
  535. 480,
  536. 'square',
  537. 0,
  538. 1
  539. ]
  540. ],
  541. ];
  542. $option_res = $poster->create($option);
  543. if (is_array($option_res)) {
  544. return $option_res;
  545. }
  546. $res = $option_res->jpeg('upload/share_img/goods_' . $goods_info[ 'goods_id' ],
  547. 'sku_' . $goods_info[ 'sku_id' ]);
  548. return $res;
  549. } catch (\Exception $e) {
  550. return $this->error($e->getMessage());
  551. }
  552. }
  553. /**
  554. * 删除分享图片
  555. * @param int $goods_id
  556. */
  557. public function clearShareImg(int $goods_id)
  558. {
  559. $dir = 'upload/share_img/goods_' . $goods_id;
  560. @deleteDir($dir);
  561. }
  562. }