WchatShare.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\pointexchange\model\share;
  11. use addon\pointexchange\model\Exchange as ExchangeModel;
  12. use app\model\share\WchatShareBase as BaseModel;
  13. use app\model\system\Config as ConfigModel;
  14. /**
  15. * 分享
  16. */
  17. class WchatShare extends BaseModel
  18. {
  19. protected $config = [
  20. [
  21. 'title' => '积分商城',
  22. 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
  23. 'path' => [ '/pages_promotion/point/list' ],
  24. 'method_prefix' => 'goodsList',
  25. ],
  26. [
  27. 'title' => '积分商品',
  28. 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
  29. 'path' => [ '/pages_promotion/point/detail' ],
  30. 'method_prefix' => 'goodsDetail',
  31. ],
  32. ];
  33. protected $sort = 6;
  34. /**
  35. * 积分商城列表
  36. * @param $param
  37. * @return array
  38. */
  39. protected function goodsListShareData($param)
  40. {
  41. //跳转路径
  42. $link = $this->getShareLink($param);
  43. $config_data = $this->goodsListShareConfig($param)[ 'value' ];
  44. $data = [
  45. 'link' => $link,
  46. 'desc' => $config_data[ 'desc' ],
  47. 'imgUrl' => $config_data[ 'imgUrl' ],
  48. 'title' => $config_data[ 'title' ]
  49. ];
  50. return [
  51. 'permission' => [
  52. 'hideOptionMenu' => false,
  53. 'hideMenuItems' => [],
  54. ],
  55. 'data' => $data,//分享内容
  56. ];
  57. }
  58. /**
  59. * 积分商城列表分享配置
  60. * @param $param
  61. * @return array
  62. */
  63. public function goodsListShareConfig($param)
  64. {
  65. $site_id = $param[ 'site_id' ];
  66. $config = $param[ 'config' ];
  67. $config_model = new ConfigModel();
  68. $data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
  69. if (empty($data[ 'value' ])) {
  70. $data[ 'value' ] = [
  71. 'title' => "积分商城",
  72. 'desc' => "积分兑换更优惠哦",
  73. 'imgUrl' => ''
  74. ];
  75. }
  76. if (empty($data[ 'value' ][ 'imgUrl' ])) {
  77. $data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
  78. }
  79. return [
  80. 'value' => $data[ 'value' ],
  81. ];
  82. }
  83. /**
  84. * 积分商城详情
  85. * @param $param
  86. * @return array
  87. */
  88. protected function goodsDetailShareData($param)
  89. {
  90. $site_id = $param[ 'site_id' ] ?? 0;
  91. parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
  92. if (isset($query[ 'id' ])) {
  93. $id = $query[ 'id' ];
  94. $exchange_model = new ExchangeModel();
  95. $exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
  96. $exchange_info = $exchange_info[ 'data' ];
  97. $condition = [
  98. [ 'peg.id', '=', $id ],
  99. [ 'peg.site_id', '=', $site_id ],
  100. [ 'peg.state', '=', 1 ],
  101. ];
  102. $exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
  103. if (!empty($exchange_detail)) {
  104. switch ( $exchange_detail[ 'type' ] ) {
  105. case 1://商品
  106. $title = $exchange_detail[ 'sku_name' ];
  107. $image_url = $exchange_detail[ 'sku_image' ];
  108. break;
  109. case 2://优惠券
  110. case 3://红包
  111. $title = $exchange_detail[ 'name' ];
  112. $image_url = $exchange_detail[ 'image' ];
  113. break;
  114. }
  115. if ($image_url) {
  116. $image_url = img($image_url);
  117. } else {
  118. $image_url = $this->getDefaultShareIcon();
  119. }
  120. $exchange_condition = [];
  121. if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
  122. if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "¥{$exchange_detail['exchange_price']}";
  123. $desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
  124. $link = $this->getShareLink($param);
  125. $data = [
  126. 'title' => $title,
  127. 'desc' => $desc,
  128. 'link' => $link,
  129. 'imgUrl' => $image_url,
  130. ];
  131. return [
  132. 'permission' => [
  133. 'hideOptionMenu' => false,
  134. 'hideMenuItems' => [],
  135. ],
  136. 'data' => $data,//分享内容
  137. ];
  138. }
  139. }
  140. }
  141. }