common_goods.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /**
  3. * 取得商品缩略图的完整URL路径,接收商品信息数组,返回所需的商品缩略图的完整URL
  4. *
  5. * @param array $goods 商品信息数组
  6. * @param string $type 缩略图类型 值为240,480,1280
  7. * @return string
  8. */
  9. function goods_thumb($goods = array(), $type = '') {
  10. $type_array = explode(',_', ltrim(GOODS_IMAGES_EXT, '_'));
  11. if ($type == 'default') {
  12. $type = '';
  13. } elseif (!in_array($type, $type_array)) {
  14. $type = '240';
  15. }
  16. if (empty($goods)) {
  17. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  18. }
  19. if (array_key_exists('apic_cover', $goods)) {
  20. $goods['goods_image'] = $goods['apic_cover'];
  21. }
  22. if (empty($goods['goods_image'])) {
  23. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  24. }
  25. $file = $goods['goods_image'];
  26. $fname = basename($file);
  27. //对象存储文件
  28. $upload_type = explode('_', $fname);
  29. if (in_array($upload_type['0'], array('alioss', 'cos'))) {
  30. $store_id = $upload_type['1'];
  31. $date= substr($upload_type['2'], 0, 8);
  32. $aliendpoint_type = config('ds_config.aliendpoint_type');
  33. if ($aliendpoint_type) {
  34. $image_url= HTTP_TYPE . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file;
  35. } else {
  36. $image_url= 'https://' . config('ds_config.alioss_bucket') . '.' . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file;
  37. }
  38. $param=array();
  39. if($type){
  40. $param[]='resize,m_pad,w_'.$type.',h_'.$type;
  41. }
  42. //是否有水印
  43. $storewatermark_model=model('storewatermark');
  44. $wm_arr=$storewatermark_model->getOneStorewatermarkByStoreId($store_id);
  45. if(!empty($wm_arr)){
  46. if($wm_arr['swm_image_name']){//有图片水印
  47. $temp=explode('_', $wm_arr['swm_image_name']);
  48. $pos_array=['se','nw','north','ne','west','center','east','sw','south','se'];
  49. if(in_array($temp['0'], array('alioss', 'cos'))){
  50. $pos='se';
  51. if(isset($pos_array[$wm_arr['swm_image_pos']])){
  52. $pos=$pos_array[$wm_arr['swm_image_pos']];
  53. }
  54. $param[]='watermark,image_'.rtrim(strtr(base64_encode(ATTACH_WATERMARK.'/'.$wm_arr['swm_image_name']), '+/', '-_'), '=').',t_'.$wm_arr['swm_image_transition'].',g_'.$pos.'';
  55. }
  56. }
  57. if($wm_arr['swm_text']){//有文字水印
  58. $pos='se';
  59. if(isset($pos_array[$wm_arr['swm_text_pos']])){
  60. $pos=$pos_array[$wm_arr['swm_text_pos']];
  61. }
  62. $param[]='watermark,size_'.$wm_arr['swm_text_size'].',text_'.rtrim(strtr(base64_encode($wm_arr['swm_text']), '+/', '-_'), '=').',color_'.trim($wm_arr['swm_text_color'],'#').',g_'.$pos.'';
  63. }
  64. }
  65. return $image_url.(!empty($param)?('?x-oss-process=image/'.implode('/', $param)):'');
  66. }
  67. //取店铺ID
  68. if (preg_match('/^(\d+_)/', $fname)) {
  69. $store_id = substr($fname, 0, strpos($fname, '_'));
  70. } else {
  71. $store_id = $goods['store_id'];
  72. }
  73. $date= substr($fname, strpos($fname, '_')+1, 8);
  74. $thumb_host = UPLOAD_SITE_URL . '/' . ATTACH_GOODS;
  75. if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . str_ireplace('.', '_' . $type . '.', $file))) {
  76. if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file)) {
  77. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  78. } else {
  79. return $thumb_host . '/' . $store_id . '/' . $date . '/' . $file;
  80. }
  81. }
  82. return $thumb_host . '/' . $store_id . '/' . $date . '/' . ($type == '' ? $file : str_ireplace('.', '_' . $type . '.', $file));
  83. }
  84. /**
  85. * 取得商品视频的完整URL路径
  86. *
  87. * @param string $file 视频名称
  88. * @return string
  89. */
  90. function goods_video($file) {
  91. $fname = basename($file);
  92. $upload_type = explode('_', $fname);
  93. if (in_array($upload_type['0'], array('alioss', 'cos'))) {//对象存储文件
  94. $store_id = $upload_type['1'];
  95. $aliendpoint_type = config('ds_config.aliendpoint_type');
  96. if ($aliendpoint_type) {
  97. return HTTP_TYPE . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $file;
  98. } else {
  99. return 'https://' . config('ds_config.alioss_bucket') . '.' . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $file;
  100. }
  101. } else {
  102. $store_id = substr($fname, 0, strpos($fname, '_'));
  103. if ($file && file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $file)) {
  104. return UPLOAD_SITE_URL . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $file;
  105. } else {
  106. return '';
  107. }
  108. }
  109. }
  110. /**
  111. * 取得商品视频的完整URL路径
  112. *
  113. * @param string $file 视频名称
  114. * @return string
  115. */
  116. function goods_resource($file) {
  117. $fname = basename($file);
  118. $upload_type = explode('_', $fname);
  119. if (in_array($upload_type['0'], array('alioss', 'cos'))) {//对象存储文件
  120. $store_id = $upload_type['1'];
  121. $aliendpoint_type = config('ds_config.aliendpoint_type');
  122. if ($aliendpoint_type) {
  123. return HTTP_TYPE . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS_RESOURCE . '/' . $store_id . '/' . $file;
  124. } else {
  125. return 'https://' . config('ds_config.alioss_bucket') . '.' . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS_RESOURCE . '/' . $store_id . '/' . $file;
  126. }
  127. } else {
  128. $store_id = substr($fname, 0, strpos($fname, '_'));
  129. if ($file && file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS_RESOURCE . '/' . $store_id . '/' . $file)) {
  130. return UPLOAD_SITE_URL . '/' . ATTACH_GOODS_RESOURCE . '/' . $store_id . '/' . $file;
  131. } else {
  132. return '';
  133. }
  134. }
  135. }
  136. /**
  137. * 取得商品缩略图的完整URL路径,接收图片名称与店铺ID
  138. *
  139. * @param string $file 图片名称
  140. * @param string $type 缩略图尺寸类型,值为240,480,1280
  141. * @param mixed $store_id 店铺ID 如果传入,则返回图片完整URL,如果为假,返回系统默认图
  142. * @return string
  143. */
  144. function goods_cthumb($file, $type = '', $store_id = false) {
  145. $type_array = explode(',_', ltrim(GOODS_IMAGES_EXT, '_'));
  146. if ($type == 'default') {
  147. $type = '';
  148. } elseif (!in_array($type, $type_array)) {
  149. $type = '240';
  150. }
  151. if (empty($file)) {
  152. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  153. }
  154. $fname = basename($file);
  155. // 取店铺ID
  156. $upload_type = explode('_', $fname);
  157. //外网存储图片
  158. if (in_array($upload_type['0'], array('alioss', 'cos'))) {
  159. $store_id = $upload_type['1'];
  160. $date= substr($upload_type['2'], 0, 8);
  161. $aliendpoint_type = config('ds_config.aliendpoint_type');
  162. if ($aliendpoint_type) {
  163. $image_url= HTTP_TYPE . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file;
  164. } else {
  165. $image_url= 'https://' . config('ds_config.alioss_bucket') . '.' . config('ds_config.alioss_endpoint') . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file;
  166. }
  167. $param=array();
  168. if($type){
  169. $param[]='resize,m_pad,w_'.$type.',h_'.$type;
  170. }
  171. //是否有水印
  172. $storewatermark_model=model('storewatermark');
  173. $wm_arr=$storewatermark_model->getOneStorewatermarkByStoreId($store_id);
  174. if(!empty($wm_arr)){
  175. if($wm_arr['swm_image_name']){//有图片水印
  176. $temp=explode('_', $wm_arr['swm_image_name']);
  177. $pos_array=['se','nw','north','ne','west','center','east','sw','south','se'];
  178. if(in_array($temp['0'], array('alioss', 'cos'))){
  179. $pos='se';
  180. if(isset($pos_array[$wm_arr['swm_image_pos']])){
  181. $pos=$pos_array[$wm_arr['swm_image_pos']];
  182. }
  183. $param[]='watermark,image_'.rtrim(strtr(base64_encode(ATTACH_WATERMARK.'/'.$wm_arr['swm_image_name']), '+/', '-_'), '=').',t_'.$wm_arr['swm_image_transition'].',g_'.$pos.'';
  184. }
  185. }
  186. if($wm_arr['swm_text']){//有文字水印
  187. $pos='se';
  188. if(isset($pos_array[$wm_arr['swm_text_pos']])){
  189. $pos=$pos_array[$wm_arr['swm_text_pos']];
  190. }
  191. $param[]='watermark,size_'.$wm_arr['swm_text_size'].',text_'.rtrim(strtr(base64_encode($wm_arr['swm_text']), '+/', '-_'), '=').',color_'.trim($wm_arr['swm_text_color'],'#').',g_'.$pos.'';
  192. }
  193. }
  194. return $image_url.(!empty($param)?('?x-oss-process=image/'.implode('/', $param)):'');
  195. }
  196. if ($store_id === false || !is_numeric($store_id)) {
  197. $store_id = substr($fname, 0, strpos($fname, '_'));
  198. }
  199. $date= substr($fname, strpos($fname, '_')+1, 8);
  200. // 本地存储时,增加判断文件是否存在,用默认图代替
  201. $thumb_host = UPLOAD_SITE_URL . '/' . ATTACH_GOODS;
  202. if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . ($type == '' ? $file : str_ireplace('.', '_' . $type . '.', $file)))) {
  203. if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $store_id . '/' . $date . '/' . $file)) {
  204. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  205. } else {
  206. return $thumb_host . '/' . $store_id . '/' . $date . '/' . $file;
  207. }
  208. return ds_get_pic(ATTACH_COMMON,substr_replace(config('ds_config.default_goods_image'),"_".$type.".png",-4));
  209. }
  210. return $thumb_host . '/' . $store_id . '/' . $date . '/' . ($type == '' ? $file : str_ireplace('.', '_' . $type . '.', $file));
  211. }
  212. /**
  213. * 商品二维码
  214. * @param array $goods_info
  215. * @return string
  216. */
  217. function goods_qrcode($goods_info) {
  218. return HOME_SITE_URL . '/qrcode?url=' . urlencode(config('ds_config.h5_site_url') . '/pages/home/goodsdetail/Goodsdetail?goods_id=' . $goods_info['goods_id']);
  219. }
  220. /**
  221. * 商品二维码
  222. * @param array $goods_info
  223. * @return string
  224. */
  225. function store_qrcode($store_id) {
  226. return HOME_SITE_URL . '/qrcode?url=' . urlencode(config('ds_config.h5_site_url') . '/pages/home/storedetail/Storedetail?id=' . $store_id);
  227. }
  228. /**
  229. * 取得抢购缩略图的完整URL路径
  230. *
  231. * @param string $imgurl 商品名称
  232. * @param string $type 缩略图类型 值为small,mid,max
  233. * @return string
  234. */
  235. function groupbuy_thumb($image_name = '') {
  236. if (empty($image_name)) {
  237. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  238. }
  239. $temp = explode('.', $image_name);
  240. $base_name = $temp[0];
  241. if (!isset($temp[1])) {
  242. $temp[1] = 'jpg';
  243. }
  244. $ext = $temp[1];
  245. $upload_type = explode('_', $base_name);
  246. if (in_array($upload_type['0'], array('alioss', 'cos'))) {
  247. $store_id=$upload_type['1'];
  248. }else{
  249. $store_id=$upload_type['0'];
  250. }
  251. $url = ds_get_pic(ATTACH_GROUPBUY . DIRECTORY_SEPARATOR . $store_id, $image_name);
  252. if (!$url) {
  253. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  254. }
  255. return $url;
  256. }
  257. /**
  258. * 取得买家缩略图的完整URL路径
  259. *
  260. * @param string $imgurl 商品名称
  261. * @param string $type 缩略图类型 值为240,1024
  262. * @return string
  263. */
  264. function sns_thumb($image_name = '', $type = '') {
  265. if (!in_array($type, array('240', '1024')))
  266. $type = '240';
  267. if (empty($image_name)) {
  268. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  269. }
  270. $upload_type = explode('_', $image_name);
  271. if (in_array($upload_type['0'], array('alioss', 'cos'))) {
  272. $member_id=$upload_type['1'];
  273. }else{
  274. $member_id=$upload_type['0'];
  275. }
  276. $url = ds_get_pic(ATTACH_MALBUM . DIRECTORY_SEPARATOR . $member_id, $image_name);
  277. if (!$url) {
  278. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  279. }
  280. return $url;
  281. }
  282. /**
  283. * 取得买家缩略图的完整URL路径
  284. *
  285. * @param string $imgurl 商品名称
  286. * @param string $type 缩略图类型 值为240,1024
  287. * @return string
  288. */
  289. function flea_thumb($image_name = '', $type = '') {
  290. if (!in_array($type, array('240', '1024')))
  291. $type = '240';
  292. if (empty($image_name)) {
  293. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  294. }
  295. $upload_type = explode('_', $image_name);
  296. if (in_array($upload_type['0'], array('alioss', 'cos'))) {
  297. $member_id=$upload_type['1'];
  298. }else{
  299. $member_id=$upload_type['0'];
  300. }
  301. $url = ds_get_pic(ATTACH_MFLEA . '/' . $member_id, $image_name);
  302. if (!$url) {
  303. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  304. }
  305. return $url;
  306. }
  307. /**
  308. * 取得积分商品缩略图的完整URL路径
  309. *
  310. * @param string $imgurl 商品名称
  311. * @param string $type 缩略图类型 值为small
  312. * @return string
  313. */
  314. function pointprod_thumb($image_name = '', $type = '') {
  315. if (empty($image_name)) {
  316. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  317. }
  318. $url = ds_get_pic(ATTACH_POINTPROD, $image_name);
  319. if (!$url) {
  320. return ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  321. }
  322. return $url;
  323. }
  324. /**
  325. * 取得品牌图片
  326. *
  327. * @param string $image_name
  328. * @return string
  329. */
  330. function brand_image($image_name = '') {
  331. if ($image_name != '') {
  332. return ds_get_pic(ATTACH_BRAND, $image_name);
  333. }
  334. return UPLOAD_SITE_URL . '/' . ATTACH_COMMON . '/default_brand_image.gif';
  335. }
  336. /**
  337. * 取得分类图片
  338. *
  339. * @param string $image_name
  340. * @return string
  341. */
  342. function goodsclass_image($gc_image)
  343. {
  344. if (empty($gc_image)) {
  345. return UPLOAD_SITE_URL . '/' . ATTACH_COMMON . '/default_goodsclass_image.jpg';
  346. }
  347. $url=ds_get_pic(ATTACH_COMMON,$gc_image);
  348. if (!$url) {
  349. return UPLOAD_SITE_URL . '/' . ATTACH_COMMON . '/default_goodsclass_image.jpg';
  350. }
  351. return $url;
  352. }
  353. /**
  354. * 取得订单状态文字输出形式
  355. *
  356. * @param array $order_info 订单数组
  357. * @return string $order_state 描述输出
  358. */
  359. function get_order_state($order_info) {
  360. switch ($order_info['order_state']) {
  361. case ORDER_STATE_CANCEL:
  362. $order_state = lang('order_state_cancel');
  363. break;
  364. case ORDER_STATE_NEW:
  365. $order_state = lang('order_state_new');
  366. break;
  367. case ORDER_STATE_DEPOSIT:
  368. $order_state = lang('order_state_deposit');
  369. break;
  370. case ORDER_STATE_REST:
  371. $order_state = lang('order_state_rest');
  372. break;
  373. case ORDER_STATE_PAY:
  374. $order_state = lang('order_state_pay');
  375. break;
  376. case ORDER_STATE_PICKUP:
  377. $order_state = lang('order_state_pickup');
  378. break;
  379. case ORDER_STATE_SEND:
  380. $order_state = lang('order_state_send');
  381. break;
  382. case ORDER_STATE_SUCCESS:
  383. $order_state = lang('order_state_success');
  384. break;
  385. }
  386. return $order_state;
  387. }
  388. /**
  389. * 取得订单支付类型文字输出形式
  390. *
  391. * @param array $payment_code
  392. * @return string
  393. */
  394. function get_order_payment_name($payment_code) {
  395. return str_replace(array('offline', 'online', 'alipay', 'alipay_h5', 'alipay_app', 'wxpay_native', 'wxpay_jsapi', 'wxpay_h5', 'wxpay_app', 'wxpay_minipro', 'predeposit'), array('货到付款', '在线付款', '支付宝PC支付', '支付宝手机支付', '支付宝APP支付', '微信扫码支付', '微信公众号支付', '微信H5支付', '微信APP支付', '小程序支付', '站内余额支付'), $payment_code);
  396. }
  397. /**
  398. * 取得订单商品销售类型文字输出形式
  399. *
  400. * @param array $goods_type
  401. * @return string 描述输出
  402. */
  403. function get_order_goodstype($goods_type) {
  404. return str_replace(array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'), array('', '抢购', '秒杀', '优惠套装', '赠品', '拼团', '会员折扣', '砍价', '批发', '预售'), $goods_type);
  405. }
  406. /**
  407. * 取得结算文字输出形式
  408. *
  409. * @param array $bill_state
  410. * @return string 描述输出
  411. */
  412. function get_bill_state($bill_state) {
  413. return str_replace(array('1', '2', '3', '4'), array('已出账', '商家已确认', '平台已审核', '结算完成'), $bill_state);
  414. }
  415. /**
  416. * 取得广告图片
  417. *
  418. * @param string $image_name
  419. * @return string
  420. */
  421. function adv_image($image_name = '') {
  422. if ($image_name != '') {
  423. return ds_get_pic(ATTACH_ADV, $image_name);
  424. }
  425. }
  426. ?>