WeappShare.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\coupon\model\share;
  11. use app\model\share\WeappShareBase;
  12. use app\model\system\Config as ConfigModel;
  13. /**
  14. * 分享
  15. */
  16. class WeappShare extends WeappShareBase
  17. {
  18. protected $config = [
  19. [
  20. 'title' => '领券中心',
  21. 'config_key' => 'WEAPP_SHARE_CONFIG_COUPON_LIST',
  22. 'path' => [ '/pages_tool/goods/coupon' ],
  23. 'method_prefix' => 'couponList',
  24. ],
  25. ];
  26. protected $sort = 2;
  27. /***************************** 领券中心 ***************************/
  28. /**
  29. * 首页分享数据
  30. * @param $param
  31. * @return array
  32. */
  33. protected function couponListShareData($param)
  34. {
  35. //获取和替换配置数据
  36. $config_data = $this->couponListShareConfig($param);
  37. $title = $config_data[ 'value' ][ 'title' ];
  38. $image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
  39. $path = $this->getSharePath($param);
  40. $data = [
  41. 'title' => $title,
  42. 'path' => $path,
  43. 'imageUrl' => $image_url,
  44. ];
  45. return [
  46. 'permission' => [
  47. 'onShareAppMessage' => true,
  48. 'onShareTimeline' => true,
  49. ],
  50. 'data' => $data,//分享内容
  51. ];
  52. }
  53. /**
  54. * 首页分享配置
  55. * @param $param
  56. * @return array
  57. */
  58. protected function couponListShareConfig($param)
  59. {
  60. $site_id = $param[ 'site_id' ];
  61. $config = $param[ 'config' ];
  62. $config_model = new ConfigModel();
  63. $data = $config_model->getConfig([
  64. [ 'site_id', '=', $site_id ],
  65. [ 'app_module', '=', 'shop' ],
  66. [ 'config_key', '=', $config[ 'config_key' ] ],
  67. ])[ 'data' ];
  68. if (empty($data[ 'value' ])) {
  69. $data[ 'value' ] = [
  70. 'title' => '送你一张优惠券,快来领取吧',
  71. 'imageUrl' => '',
  72. ];
  73. }
  74. $variable = [];
  75. return [
  76. 'value' => $data[ 'value' ],
  77. 'variable' => $variable,
  78. ];
  79. }
  80. }