WeappShare.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\fenxiao\model\share;
  11. use app\model\member\Member as MemberModel;
  12. use app\model\share\WeappShareBase as BaseModel;
  13. use app\model\system\Config as ConfigModel;
  14. /**
  15. * 分享
  16. */
  17. class WeappShare extends BaseModel
  18. {
  19. protected $config = [
  20. [
  21. 'title' => '分销推广',
  22. 'config_key' => 'WEAPP_SHARE_CONFIG_FENXIAO_PROMOTE',
  23. 'path' => ['/pages_promotion/fenxiao/promote_code'],
  24. 'method_prefix' => 'promote',
  25. ],
  26. ];
  27. protected $sort = 2;
  28. /**
  29. * 首页分享数据
  30. * @param $param
  31. * @return array
  32. */
  33. protected function promoteShareData($param)
  34. {
  35. $member_id = $param['member_id'] ?? 0;
  36. $param['path'] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param['path']);
  37. if(strpos($param['path'], '?')) $param['path'] = explode('?', $param['path'])[0];
  38. //会员信息
  39. $member_model = new MemberModel();
  40. $member_info = $member_model->getMemberInfo([['member_id', '=', $member_id]], 'nickname, headimg')['data'];
  41. //获取和替换配置数据
  42. $config_data = $this->promoteShareConfig($param);
  43. $title = str_replace('{nickname}', $member_info['nickname'], $config_data['value']['title']);
  44. $image_url = $config_data['value']['imageUrl'] ? img($config_data['value']['imageUrl']) : '';
  45. $path = $this->getSharePath($param);
  46. $data = [
  47. 'title' => $title,
  48. 'path' => $path,
  49. 'imageUrl' => $image_url,
  50. ];
  51. return [
  52. 'permission' => [
  53. 'onShareAppMessage' => true,
  54. 'onShareTimeline' => true,
  55. ],
  56. 'data' => $data,//分享内容
  57. ];
  58. }
  59. /**
  60. * 首页分享配置
  61. * @param $param
  62. * @return array
  63. */
  64. protected function promoteShareConfig($param)
  65. {
  66. $site_id = $param['site_id'];
  67. $config = $param['config'];
  68. $config_model = new ConfigModel();
  69. $data = $config_model->getConfig([
  70. ['site_id', '=', $site_id],
  71. ['app_module', '=', 'shop'],
  72. ['config_key', '=', $config['config_key']],
  73. ])['data'];
  74. if (empty($data['value'])) {
  75. $data['value'] = [
  76. 'title' => '快来加入{nickname}的团队吧,一起赚有佣金哦',
  77. 'imageUrl' => '',
  78. ];
  79. }
  80. $variable = [
  81. ['title' => '用户昵称', 'name' => '{nickname}'],
  82. ];
  83. return [
  84. 'value' => $data['value'],
  85. 'variable' => $variable,
  86. ];
  87. }
  88. }