初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

293
app/model/share/WchatShare.php Executable file
View File

@@ -0,0 +1,293 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace app\model\share;
use app\model\goods\Goods as GoodsModel;
use app\model\system\Site as SiteModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WchatShare extends WchatShareBase
{
protected $config = [
// [
// 'title' => '商城首页',
// 'config_key' => 'WCHAT_SHARE_CONFIG_INDEX',
// 'path' => ['/','/pages/index/index'],
// 'method_prefix' => 'index',
// ],
[
'title' => '商品列表页',
'config_key' => 'WCHAT_SHARE_CONFIG_GOODS_LIST',
'path' => ['/pages/goods/list'],
'method_prefix' => 'goodsList',
],
[
'title' => '商品详情页',
'config_key' => 'WCHAT_SHARE_CONFIG_GOODS_DETAIL',
'path' => ['/pages/goods/detail'],
'method_prefix' => 'goodsDetail',
],
[
'title' => '支付宝支付',
'config_key' => 'WCHAT_SHARE_CONFIG_ALIPAY',
'path' => ['/pages_tool/pay/wx_pay'],
'method_prefix' => 'alipay',
],
];
protected $sort = 1;
/**
* 首页分享数据
* @param $param
* @return array
*/
protected function indexShareData($param)
{
$site_id = $param['site_id'] ?? 0;
//站点设置
$site_model = new SiteModel();
$site_info = $site_model->getSiteInfo([['site_id', '=', $site_id]])['data'];
//跳转路径
$link = $this->getShareLink($param);
//获取和替换配置数据
$config_method = preg_replace('/Data$/', 'Config',__FUNCTION__);
$config_data = $this->$config_method($param);
$title = str_replace('{site_name}', $site_info['site_name'], $config_data['value']['title']);
$desc = str_replace('{site_name}', $site_info['site_name'], $config_data['value']['desc']);
$image_url = $config_data['value']['imgUrl'] ?: $site_info['logo_square'];
//如果都没有设置 则取默认分享图标
if(empty($image_url)){
$image_url = $this->getDefaultShareIcon();
}
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
/**
* 首页分享配置
* @param $param
* @return array
*/
protected function indexShareConfig($param)
{
$site_id = $param['site_id'];
$config = $param['config'];
$config_model = new ConfigModel();
$data = $config_model->getConfig([
['site_id', '=', $site_id],
['app_module', '=', 'shop'],
['config_key', '=', $config['config_key']],
])['data'];
if (empty($data['value'])) {
$data['value'] = [
'title' => '{site_name}',
'desc' => '用心精选,常来逛逛',
'imgUrl' => '',
];
}
$variable = [
['title' => '店铺名称', 'name' => '{site_name}'],
];
return [
'value' => $data['value'],
'variable' => $variable,
];
}
/**
* 商品详情分享数据
* @param $param
* @return array[]|void
*/
protected function goodsDetailShareData($param)
{
$site_id = $param['site_id'] ?? 0;
$url = $param['url'];
$parse_res = parse_url($url);
parse_str($parse_res['query'] ?? '', $query);
if(isset($query['goods_id'])){
$goods_id = $query['goods_id'];
$goods = new GoodsModel();
$goods_info = $goods->getGoodsInfo([ ['site_id', '=', $site_id], ['goods_id', '=', $goods_id] ], 'price,goods_name,goods_image')['data'];
if(!empty($goods_info)){
$config_method = preg_replace('/Data$/', 'Config',__FUNCTION__);
$config_data = $this->$config_method($param);
$title = str_replace('{goods_name}', $goods_info['goods_name'], $config_data['value']['title']);
$desc = str_replace('{price}', $goods_info['price'], $config_data['value']['desc']);
$desc = str_replace('\n', '\r\n', $desc);
$link = $this->getShareLink($param);
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => explode(',', $goods_info['goods_image'])[0] ?? '',
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
/**
* 商品详情分享配置
* @param $param
* @return array
*/
public function goodsDetailShareConfig($param)
{
$site_id = $param['site_id'];
$config = $param['config'];
$config['config_key'] = 'WCHAT_SHARE_CONFIG_GOODS_DETAIL';
$config_model = new ConfigModel();
$data = $config_model->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', $config['config_key']]])['data'];
if (empty($data['value'])) {
$data['value'] = [
'title' => "{goods_name}",
'desc' => "优惠价:¥{price}\n全场正品\n收藏热度:★★★★★",
];
}
$variable = [
['title' => '商品名称', 'name' => '{goods_name}'],
['title' => '价格', 'name' => '{price}'],
];
return [
'value' => $data['value'],
'variable' => $variable,
];
}
/**
* 商品列表分享数据
* @param $param
* @return array
*/
protected function goodsListShareData($param)
{
$site_id = $param['site_id'] ?? 0;
//站点设置
$site_model = new SiteModel();
$site_info = $site_model->getSiteInfo([['site_id', '=', $site_id]])['data'];
//跳转路径
$link = $this->getShareLink($param);
//获取和替换配置数据
$config_method = preg_replace('/Data$/', 'Config',__FUNCTION__);
$config_data = $this->$config_method($param);
$title = $config_data['value']['title'];
$desc = $config_data['value']['desc'];
$image_url = $config_data['value']['imgUrl'] ?: $site_info['logo_square'];
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
/**
* 商品列表分享配置
* @param $param
* @return array
*/
protected function goodsListShareConfig($param)
{
$site_id = $param['site_id'];
$config = $param['config'];
$config_model = new ConfigModel();
$data = $config_model->getConfig([
['site_id', '=', $site_id],
['app_module', '=', 'shop'],
['config_key', '=', $config['config_key']],
])['data'];
if (empty($data['value'])) {
$data['value'] = [
'title' => '来看看有哪些好物吧',
'desc' => "用心精选\n常来逛逛",
'imgUrl' => '',
];
}
$variable = [
];
return [
'value' => $data['value'],
'variable' => $variable,
];
}
/**
* 支付宝支付分享数据
* @param $param
* @return array
*/
protected function alipayShareData($param)
{
$data = [
'title' => '',
'desc' => '',
'link' => $param['url'],
'imgUrl' => '',
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace app\model\share;
use app\model\BaseModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WchatShareBase extends BaseModel
{
protected $config = [];
protected $sort = 999;
/**
* @param array $param
* @return mixed
*/
public function getShareData($param)
{
$path = parse_url($param['url'])['path'] ?? '';
$path = preg_replace("/^\/h5/", '', $path);
foreach($this->config as $val){
if(in_array($path, $val['path'])){
$method = $val['method_prefix'].'ShareData';
if(method_exists($this, $method)){
return $this->$method(array_merge($param, ['config' => $val]));
}
}
}
}
/**
* 获取分享配置
* @param $param
* @return array
*/
public function getShareConfig($param)
{
$data = [];
foreach($this->config as $val){
$method = $val['method_prefix'].'ShareConfig';
if(method_exists($this, $method)){
$item = $this->$method(array_merge($param, ['config' => $val]));
$item['config'] = $val;
$data[] = $item;
}
}
return [
'sort' => $this->sort,
'data' => $data,
];
}
/**
* 设置分享内容
* @param $site_id
* @param $data
* @return array
*/
public function setShareConfig($site_id, $data)
{
$config_model = new ConfigModel();
foreach($data as $key=>$val){
$config_key = $val['config_key'];
$config_data = [];
if(isset($val['title'])) $config_data['title'] = $val['title'];
if(isset($val['desc'])) $config_data['desc'] = $val['desc'];
if(isset($val['imgUrl'])) $config_data['imgUrl'] = $val['imgUrl'];
$config_model->setConfig($config_data, '公众号分享设置', 1, [
['site_id', '=', $site_id],
['app_module', '=', 'shop'],
['config_key', '=', $config_key],
]);
}
return $this->success();
}
/**
* 获取分享链接
* @param $param
* @return string
*/
protected function getShareLink($param)
{
$member_id = $param['member_id'];
$link = $param['url'];
//如果链接中有原分享人数据要先去掉
$link = preg_replace("/source_member=\d+/", "", $link);
$link = rtrim($link, '?');
if(!empty($member_id)){
if(strpos($link, '?')){
$link .= '&';
}else{
$link .= '?';
}
$link .= 'source_member='.$member_id;
}
return $link;
}
/**
* 默认分享图标
* @return string
*/
protected function getDefaultShareIcon()
{
return img('public/static/img/wx_share_icon.png');
}
}

98
app/model/share/WeappShare.php Executable file
View File

@@ -0,0 +1,98 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace app\model\share;
use app\model\system\Site as SiteModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShare extends WeappShareBase
{
protected $config = [
// [
// 'title' => '商城首页',
// 'config_key' => 'WEAPP_SHARE_CONFIG_INDEX',
// 'path' => ['/pages/index/index'],
// 'method_prefix' => 'index',
// ],
];
protected $sort = 1;
/**
* 首页分享数据
* @param $param
* @return array
*/
protected function indexShareData($param)
{
$site_id = $param['site_id'] ?? 0;
//站点设置
$site_model = new SiteModel();
$site_info = $site_model->getSiteInfo([['site_id', '=', $site_id]])['data'];
//获取和替换配置数据
$config_data = $this->indexShareConfig($param);
$title = str_replace('{site_name}', $site_info['site_name'], $config_data['value']['title']);
$image_url = $config_data['value']['imageUrl'] ? img($config_data['value']['imageUrl']) : '';
$path = $this->getSharePath($param);
$data = [
'title' => $title,
'path' => $path,
'imageUrl' => $image_url,
];
return [
'permission' => [
'onShareAppMessage' => true,
'onShareTimeline' => true,
],
'data' => $data,//分享内容
];
}
/**
* 首页分享配置
* @param $param
* @return array
*/
protected function indexShareConfig($param)
{
$site_id = $param['site_id'];
$config = $param['config'];
$config_model = new ConfigModel();
$data = $config_model->getConfig([
['site_id', '=', $site_id],
['app_module', '=', 'shop'],
['config_key', '=', $config['config_key']],
])['data'];
if (empty($data['value'])) {
$data['value'] = [
'title' => '{site_name}',
'imageUrl' => '',
];
}
$variable = [
['title' => '店铺名称', 'name' => '{site_name}'],
];
return [
'value' => $data['value'],
'variable' => $variable,
];
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace app\model\share;
use app\model\BaseModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShareBase extends BaseModel
{
protected $config = [];
protected $sort = 999;
/**
* @param array $param
* @return mixed
*/
public function getShareData($param)
{
$path = parse_url($param['path'])['path'] ?? '';
foreach($this->config as $val){
if(in_array($path, $val['path'])){
$method = $val['method_prefix'].'ShareData';
if(method_exists($this, $method)){
return $this->$method(array_merge($param, ['config' => $val]));
}
}
}
}
/**
* 获取分享配置
* @param $param
* @return array
*/
public function getShareConfig($param)
{
$data = [];
foreach($this->config as $val){
$method = $val['method_prefix'].'ShareConfig';
if(method_exists($this, $method)){
$item = $this->$method(array_merge($param, ['config' => $val]));
$item['config'] = $val;
$data[] = $item;
}
}
return [
'sort' => $this->sort,
'data' => $data,
];
}
/**
* 设置分享内容
* @param $site_id
* @param $data
* @return array
*/
public function setShareConfig($site_id, $data)
{
$config_model = new ConfigModel();
foreach($data as $key=>$val){
$config_key = $val['config_key'];
$config_data = [];
if(isset($val['title'])) $config_data['title'] = $val['title'];
if(isset($val['imageUrl'])) $config_data['imageUrl'] = $val['imageUrl'];
$config_model->setConfig($config_data, '小程序分享设置', 1, [
['site_id', '=', $site_id],
['app_module', '=', 'shop'],
['config_key', '=', $config_key],
]);
}
return $this->success();
}
/**
* 获取分享路径
* @param $param
* @return string
*/
public function getSharePath($param)
{
$member_id = $param['member_id'];
$path = $param['path'];
//如果链接中有原分享人数据要先去掉
$path = preg_replace("/source_member=\d+/", "", $path);
$path = rtrim($path, '?');
if(!empty($member_id)){
if(strpos($path, '?')){
$path .= '&';
}else{
$path .= '?';
}
$path .= 'source_member='.$member_id;
}
return $path;
}
}