Poster.php 26 KB

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