初始上传

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

104
addon/notes/model/Group.php Executable file
View File

@@ -0,0 +1,104 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\notes\model;
use app\model\BaseModel;
/**
* 笔记分组
*/
class Group extends BaseModel
{
/**
* 添加笔记分组
* @param $data
* @return array
*/
public function addNotesGroup($data)
{
$data['create_time'] = time();
$res = model('notes_group')->add($data);
return $this->success($res);
}
/**
* 编辑笔记分组
* @param $condition
* @param $data
* @return array
*/
public function editNotesGroup($condition, $data)
{
$data['update_time'] = time();
$res = model('notes_group')->update($data, $condition);
return $this->success($res);
}
/**
* 删除笔记分组
* @param $group_id
* @param $site_id
* @return array|\multitype
*/
public function deleteNotesGroup($group_id, $site_id)
{
//笔记数
$notes_count = model('notes')->getCount([['group_id', '=', $group_id], ['site_id', '=', $site_id]]);
if ($notes_count > 0) {
return $this->error('', '该分组下存在店铺笔记,暂不能删除');
} else {
$res = model('notes_group')->delete([['group_id', '=', $group_id], ['site_id', '=', $site_id]]);
return $this->success($res);
}
}
/**
* 获取笔记分组信息
* @param array $condition
* @param string $field
* @return array
*/
public function getNotesGroupInfo($condition = [], $field = '*')
{
$info = model('notes_group')->getInfo($condition, $field);
return $this->success($info);
}
/**
* 获取笔记分组列表
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getNotesGroupList($condition = [], $field = '*', $order = '', $limit = null)
{
$list = model('notes_group')->getList($condition, $field, $order, '', '', '', $limit);
return $this->success($list);
}
/**
* 获取笔记分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getNotesGroupPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
{
$list = model('notes_group')->pageList($condition, $field, $order, $page, $page_size);
return $this->success($list);
}
}

299
addon/notes/model/Notes.php Executable file
View File

@@ -0,0 +1,299 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\notes\model;
use app\model\BaseModel;
use extend\WxCrawler;
/**
* 笔记
*/
class Notes extends BaseModel
{
//笔记类型
private $note_type = [
[ 'type' => 'shop_said', 'name' => '掌柜说' ],
[ 'type' => 'goods_item', 'name' => '单品介绍' ],
//['type' => 'article', 'name' => '种草文章'],
//['type' => 'wechat_article', 'name' => '公众号文章'],
//['type' => 'goods_video', 'name' => '短视频']
];
/**
* 获取笔记类型
* @return array
*/
public function getNoteType()
{
return $this->note_type;
}
/**
* 添加笔记
* @param $data
* @return array
*/
public function addNotes($data)
{
$data[ 'create_time' ] = time();
model('notes')->startTrans();
try {
//添加笔记
if ($data[ 'status' ] == 1) {
$data[ 'release_time' ] = time();
}
model('notes')->add($data);
//更新分组笔记数等信息
model('notes_group')->setInc([ [ 'group_id', '=', $data[ 'group_id' ] ] ], 'notes_num');
if ($data[ 'status' ] == 1) {
model('notes_group')->setInc([ [ 'group_id', '=', $data[ 'group_id' ] ] ], 'release_num');
}
model('notes')->commit();
return $this->success();
} catch (\Exception $e) {
model('notes')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 文章发布
* @param $params
*/
public function releaseEvent($params)
{
$site_id = $params[ 'site_id' ] ?? 0;
$note_id = $params[ 'note_id' ];
$status = $params[ 'status' ];
$condition = array (
[ 'note_id', '=', $note_id ],
[ 'site_id', '=', $site_id ]
);
$info = model('notes')->getInfo($condition);
if (!empty($info)) {
if ($info[ 'status' ] != $status) {
if ($status == 1) {
$release_time = time();
model('notes_group')->setInc([ [ 'group_id', '=', $info[ 'group_id' ] ] ], 'release_num');
} else {
$release_time = 0;
model('notes_group')->setDec([ [ 'group_id', '=', $info[ 'group_id' ] ] ], 'release_num');
}
$data = array (
'release_time' => $release_time,
'status' => $status
);
model('notes')->update($data, $condition);
}
return $this->success();
} else {
return $this->error();
}
}
/**
* 编辑笔记
* @param $data
* @return array
*/
public function editNotes($data)
{
$data[ 'update_time' ] = time();
model('notes')->startTrans();
try {
$info = model('notes')->getInfo([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'note_id', '=', $data[ 'note_id' ] ] ]);
//添加笔记
model('notes')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'note_id', '=', $data[ 'note_id' ] ] ]);
$release_data = array (
'note_id' => $data[ 'note_id' ],
'site_id' => $data[ 'site_id' ]
);
if ($info[ 'group_id' ] != $data[ 'group_id' ]) {
model('notes_group')->setDec([ [ 'group_id', '=', $info[ 'group_id' ] ] ], 'notes_num');
model('notes_group')->setInc([ [ 'group_id', '=', $data[ 'group_id' ] ] ], 'notes_num');
//减去原分组的发布数
if ($info[ 'status' ] == 1) {
model('notes_group')->setDec([ [ 'group_id', '=', $info[ 'group_id' ] ] ], 'release_num');
}
//增加新分组的发布数
if ($data[ 'status' ] == 1) {
model('notes_group')->setInc([ [ 'group_id', '=', $data[ 'group_id' ] ] ], 'release_num');
}
} else {
$release_data[ 'status' ] = $data[ 'status' ];
$this->releaseEvent($release_data);
}
//更新分组笔记数等信息
if ($data[ 'status' ] == 1) {
model('notes_group')->setInc([ [ 'group_id', '=', $data[ 'group_id' ] ] ], 'release_num');
}
model('notes')->commit();
return $this->success();
} catch (\Exception $e) {
model('notes')->rollback();
return $this->error('', $e->getMessage());
}
}
/**
* 删除笔记
* @param $condition
* @return array|\multitype
*/
public function deleteNotes($condition)
{
//笔记数
$notes_info = model('notes')->getInfo($condition, 'group_id,status');
if (empty($notes_info)) {
return $this->success('', '数据不合法');
} else {
model('notes')->startTrans();
try {
//删除笔记
model('notes')->delete($condition);
//更新分组笔记数等信息
if ($notes_info[ 'status' ] == 1) {
model('notes_group')->setDec([ [ 'group_id', '=', $notes_info[ 'group_id' ] ] ], 'notes_num');
model('notes_group')->setDec([ [ 'group_id', '=', $notes_info[ 'group_id' ] ] ], 'release_num');
} else {
model('notes_group')->setDec([ [ 'group_id', '=', $notes_info[ 'group_id' ] ] ], 'notes_num');
}
model('notes')->commit();
return $this->success();
} catch (\Exception $e) {
model('notes')->rollback();
return $this->error('', $e->getMessage());
}
}
}
/**
* 修改排序
* @param int $sort
* @param int $class_id
*/
public function modifyNotesSort($sort, $note_id, $site_id)
{
$res = model('notes')->update([ 'sort' => $sort ], [ [ 'note_id', '=', $note_id ], [ 'site_id', '=', $site_id ] ]);
return $this->success($res);
}
/**
* 获取笔记信息
* @param array $condition
* @param string $field
* @return array
*/
public function getNotesInfo($condition = [], $field = '*')
{
$info = model("notes")->getInfo($condition, $field);
return $this->success($info);
}
/**
* 获取笔记信息
* @param array $condition
* @param string $field
* @param int $type
* @return array
*/
public function getNotesDetailInfo($condition = [], $field = '*', $type = 1)
{
$info = model('notes')->getInfo($condition, $field);
if (!empty($info)) {
$goods_field = 'sku_id,goods_name,goods_stock,price,goods_image,goods_id';
$goods_list = model('goods')->getList([ [ 'site_id', '=', $info[ 'site_id' ] ], [ 'goods_id', 'in', $info[ 'goods_ids' ] ], [ 'goods_state', '=', 1 ], [ 'is_delete', '=', 0 ] ], $goods_field);
if (!empty($goods_list)) {
foreach ($goods_list as $k => $v) {
$goods_list[ $k ][ 'goods_stock' ] = numberFormat($goods_list[ $k ][ 'goods_stock' ]);
}
}
$info[ 'goods_list' ] = $goods_list;
}
//添加浏览记录
if ($type == 2) {
model('notes')->setInc($condition, 'read_num', 1);
}
return $this->success($info);
}
/**
* 获取笔记列表
* @param array $condition
* @param string $field
* @param string $order
* @param string $limit
*/
public function getNotesList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
{
$list = model('notes')->getList($condition, $field, $order, $alias, $join, '', $limit);
return $this->success($list);
}
/**
* 获取笔记分页列表
* @param array $condition
* @param number $page
* @param string $page_size
* @param string $order
* @param string $field
*/
public function getNotesPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'pn.sort asc')
{
$field = 'pn.*,png.group_name';
$alias = 'pn';
$join = [
[
'notes_group png',
'png.group_id = pn.group_id',
'left'
]
];
$note_type = $this->getNoteType();
$note_type = array_column($note_type, 'name', 'type');
$list = model('notes')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
foreach ($list[ 'list' ] as $k => $v) {
$list[ 'list' ][ $k ][ 'note_type_name' ] = $note_type[ $v[ 'note_type' ] ];
}
return $this->success($list);
}
/**
* 采集微信公众号的文章信息
* @param $params
*/
public function pullWechatArticle($params)
{
$url = $params[ 'url' ];
$crawler = new WxCrawler();
$data = $crawler->crawByUrl($url);
// echo $data['data']['content_html'];exit();
return $data;
}
}

70
addon/notes/model/Record.php Executable file
View File

@@ -0,0 +1,70 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\notes\model;
use app\model\BaseModel;
/**
* 笔记点赞记录
*/
class Record extends BaseModel
{
/**
* 添加点赞记录
* @param $data
* @return array
*/
public function addRecord($data)
{
$info = model('notes_dianzan_record')->getInfo([['member_id', '=', $data['member_id']], ['note_id', '=', $data['note_id']]], 'record_id');
if (empty($info)) {
$res = model('notes_dianzan_record')->add($data);
if ($res) {
model("notes")->setInc([['note_id', '=', $data['note_id']]], 'dianzan_num', 1);
}
return $this->success($res);
} else {
return $this->error();
}
}
/**
* 取消点赞
* @param $member_id
* @param $note_id
* @return array
*/
public function deleteRecord($member_id, $note_id)
{
$res = model('notes_dianzan_record')->delete([['member_id', '=', $member_id], ['note_id', '=', $note_id]]);
if ($res) {
model("notes")->setDec([['note_id', '=', $note_id]], 'dianzan_num', 1);
}
return $this->success($res);
}
/**
* 检测商品是否收藏
* @param $note_id
* @param $member_id
* @return array
*/
public function getIsDianzan($note_id, $member_id)
{
$count = model('notes_dianzan_record')->getCount([['member_id', '=', $member_id], ['note_id', '=', $note_id]]);
return $this->success($count);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\notes\model\share;
use addon\notes\model\Notes as NotesModel;
use app\model\share\WchatShareBase as BaseModel;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '店铺笔记列表',
'config_key' => 'WCHAT_SHARE_CONFIG_NOTES_LIST',
'path' => [ '/pages_tool/store_notes/note_list' ],
'method_prefix' => 'noteList',
],
[
'title' => '店铺笔记分享',
'config_key' => 'WCHAT_SHARE_CONFIG_NOTES_DETAIL',
'path' => [ '/pages_tool/store_notes/note_detail' ],
'method_prefix' => 'noteDetail',
],
];
protected $sort = 4;
/**
* 店铺笔记列表
* @param $param
* @return array
*/
protected function noteListShareData($param)
{
//跳转路径
$link = $this->getShareLink($param);
$config_data = $this->noteListShareConfig($param)[ 'value' ];
$data = [
'link' => $link,
'desc' => $config_data[ 'desc' ],
'imgUrl' => $config_data[ 'imgUrl' ],
'title' => $config_data[ 'title' ]
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
/**
* 店铺笔记分享配置
* @param $param
* @return array
*/
public function noteListShareConfig($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' => ''
];
}
if (empty($data[ 'value' ][ 'imgUrl' ])) {
$data[ 'value' ][ 'imgUrl' ] = img('addon/notes/icon.png');
}
return [
'value' => $data[ 'value' ],
];
}
/**
* 店铺笔记分享数据
* @param $param
* @return array
*/
protected function noteDetailShareData($param)
{
$site_id = $param[ 'site_id' ] ?? 0;
parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
if (isset($query[ 'note_id' ]) || isset($query[ 'id' ])) {
$note_id = $query['id'] ?? $query['note_id'];
$condition = [
[ 'site_id', '=', $site_id ],
[ 'note_id', '=', $note_id ]
];
$note_model = new NotesModel();
$note_detail = $note_model->getNotesDetailInfo($condition, '*', 2)[ 'data' ];
if (!empty($note_detail)) {
$title = $note_detail[ 'note_title' ];
$desc = $note_detail[ 'note_title' ];
$link = $this->getShareLink($param);
$image_url = img(explode(',', $note_detail[ 'cover_img' ])[ 0 ]);
$data = [
'title' => $title,
'desc' => $desc,
'link' => $link,
'imgUrl' => $image_url,
'detail' => $note_detail,
];
return [
'permission' => [
'hideOptionMenu' => false,
'hideMenuItems' => [],
],
'data' => $data,//分享内容
];
}
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\notes\model\share;
use app\model\share\WeappShareBase;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShare extends WeappShareBase
{
protected $config = [
[
'title' => '店铺笔记列表',
'config_key' => 'WEAPP_SHARE_CONFIG_NOTES_LIST',
'path' => [ '/pages_tool/store_notes/note_list' ],
'method_prefix' => 'noteList',
],
];
protected $sort = 6;
/**
* 拼团返利列表
* @param $param
* @return array
*/
protected function noteListShareData($param)
{
//获取和替换配置数据
$config_data = $this->noteListShareConfig($param);
$title = $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 noteListShareConfig($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' => '有一些优选商品向你推荐',
'imageUrl' => '',
];
}
$variable = [];
return [
'value' => $data[ 'value' ],
'variable' => $variable,
];
}
}