WchatShare.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\notes\model\share;
  11. use addon\notes\model\Notes as NotesModel;
  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_NOTES_LIST',
  23. 'path' => [ '/pages_tool/store_notes/note_list' ],
  24. 'method_prefix' => 'noteList',
  25. ],
  26. [
  27. 'title' => '店铺笔记分享',
  28. 'config_key' => 'WCHAT_SHARE_CONFIG_NOTES_DETAIL',
  29. 'path' => [ '/pages_tool/store_notes/note_detail' ],
  30. 'method_prefix' => 'noteDetail',
  31. ],
  32. ];
  33. protected $sort = 4;
  34. /**
  35. * 店铺笔记列表
  36. * @param $param
  37. * @return array
  38. */
  39. protected function noteListShareData($param)
  40. {
  41. //跳转路径
  42. $link = $this->getShareLink($param);
  43. $config_data = $this->noteListShareConfig($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 noteListShareConfig($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' => "好物精选\n向您推荐",
  73. 'imgUrl' => ''
  74. ];
  75. }
  76. if (empty($data[ 'value' ][ 'imgUrl' ])) {
  77. $data[ 'value' ][ 'imgUrl' ] = img('addon/notes/icon.png');
  78. }
  79. return [
  80. 'value' => $data[ 'value' ],
  81. ];
  82. }
  83. /**
  84. * 店铺笔记分享数据
  85. * @param $param
  86. * @return array
  87. */
  88. protected function noteDetailShareData($param)
  89. {
  90. $site_id = $param[ 'site_id' ] ?? 0;
  91. parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
  92. if (isset($query[ 'note_id' ]) || isset($query[ 'id' ])) {
  93. $note_id = isset($query[ 'id' ]) ? $query[ 'id' ] : $query[ 'note_id' ];
  94. $condition = [
  95. [ 'site_id', '=', $site_id ],
  96. [ 'note_id', '=', $note_id ]
  97. ];
  98. $note_model = new NotesModel();
  99. $note_detail = $note_model->getNotesDetailInfo($condition, '*', 2)[ 'data' ];
  100. if (!empty($note_detail)) {
  101. $title = $note_detail[ 'note_title' ];
  102. $desc = $note_detail[ 'note_title' ];
  103. $link = $this->getShareLink($param);
  104. $image_url = img(explode(',', $note_detail[ 'cover_img' ])[ 0 ]);
  105. $data = [
  106. 'title' => $title,
  107. 'desc' => $desc,
  108. 'link' => $link,
  109. 'imgUrl' => $image_url,
  110. 'detail' => $note_detail,
  111. ];
  112. return [
  113. 'permission' => [
  114. 'hideOptionMenu' => false,
  115. 'hideMenuItems' => [],
  116. ],
  117. 'data' => $data,//分享内容
  118. ];
  119. }
  120. }
  121. }
  122. }