初始上传

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

View File

@@ -0,0 +1,32 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use app\shop\controller\BaseShop;
use think\App;
/**
* 微信控制器基类
*/
class BaseWechat extends BaseShop
{
public function __construct(App $app = null)
{
$this->replace = [
'WECHAT_CSS' => __ROOT__ . '/addon/wechat/shop/view/public/css',
'WECHAT_JS' => __ROOT__ . '/addon/wechat/shop/view/public/js',
'WECHAT_IMG' => __ROOT__ . '/addon/wechat/shop/view/public/img',
];
parent::__construct($app);
}
}

View File

@@ -0,0 +1,305 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Wechat as WechatModel;
use addon\wechat\model\Fans as FansModel;
/**
* 微信粉丝控制器
*/
class Fans extends BaseWechat
{
/**
* 粉丝列表
* @return array|mixed
*/
public function lists()
{
$fans_model = new FansModel();
if (request()->isJson()) {
$page = input('page', 1);
$limit = input('page_size', PAGE_LIST_ROWS);
$is_subscribe = input('is_subscribe', '');//关注
$nickname = input('nickname', '');//粉丝名称
$start_time = input('start_time', '');
$end_time = input('end_time', '');
$condition[] = [ 'site_id', '=', $this->site_id ];
if ($is_subscribe !== '') {
$condition[] = [ 'is_subscribe', "=", $is_subscribe ];
}
if ($nickname != '') {
$condition[] = [ 'nickname', 'like', '%' . $nickname . '%' ];
}
if (!empty($start_time) && empty($end_time)) {
$condition[] = [ "subscribe_time", ">=", date_to_time($start_time) ];
} elseif (empty($start_time) && !empty($end_time)) {
$condition[] = [ "subscribe_time", "<=", date_to_time($end_time) ];
} elseif (!empty($start_time) && !empty($end_time)) {
$condition[] = [ 'subscribe_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
}
$fans_list = $fans_model->getFansPageList($condition, $page, $limit);
return $fans_list;
}
$tag_list = $fans_model->getFansTagList();
$this->assign('tag_list', $tag_list[ 'data' ]);
return $this->fetch('fans/lists');
}
/**
* 更新粉丝信息
*/
public function syncWechatFans()
{
$page_index = input('page', 0);
$page_size = input('limit', PAGE_LIST_ROWS);
$wechat_model = new WechatModel($this->site_id);
if ($page_index == 0) {
//建立连接同时获取所有用户openid 拉去粉丝信息列表(一次拉取调用最多拉取10000个关注者的OpenID可以通过多次拉取的方式来满足需求。)
$openid_list = [];
$is_continue = true;
$next_openid = null;
do {
$item_result = $wechat_model->user($next_openid);
if ($item_result[ "code" ] < 0)
return $item_result;
if (empty($item_result[ 'data' ][ 'data' ])) {
return success(0, '公众号暂无粉丝');
}
$next_openid = $item_result[ "data" ][ "next_openid" ];
$openid_item = $item_result[ "data" ][ 'data' ][ "openid" ];
if (empty($openid_item)) {
$is_continue = false;
} else {
$is_continue = false;
foreach ($openid_item as $k => $v) {
$openid_list[] = $v;
}
}
} while ($is_continue);
//将粉丝列表存入session
session('wechat_openid_list', $openid_list);
$total = count($openid_list);
if ($openid_list % $page_size == 0) {
$page_count = $total / $page_size;
} else {
$page_count = (int) ( $total / $page_size ) + 1;
}
$data = array (
'total' => $total,
'page_count' => $page_count,
);
return success(0, '', $data);
} else {
//对应页数更新用户粉丝信息
$openid_list = session('wechat_openid_list');
if (empty($openid_list)) {
return error();
}
$start = ( $page_index - 1 ) * $page_size;
$page_fans_openid_list = array_slice($openid_list, $start, $page_size);
if (empty($page_fans_openid_list)) {
return error();
}
$fans_model = new FansModel();
$result = $wechat_model->selectUser($page_fans_openid_list);
if ($result[ 'data' ] && $result[ 'data' ][ 'user_info_list' ]) {
foreach ($result[ 'data' ][ 'user_info_list' ] as $k => $v) {
$nickname_decode = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $v[ 'nickname' ]);
$nickname = preg_replace_callback('/./u',
function(array $match) {
return strlen($match[ 0 ]) >= 4 ? '' : $match[ 0 ];
},
$v[ 'nickname' ]);
$add_data = [
'site_id' => $this->site_id,
'nickname' => $nickname,
'nickname_decode' => $nickname_decode,
'headimgurl' => $v[ 'headimgurl' ],
'sex' => $v[ 'sex' ],
'language' => $v[ 'language' ],
'country' => $v[ 'country' ],
'province' => $v[ 'province' ],
'city' => $v[ 'city' ],
'openid' => $v[ 'openid' ],
'unionid' => $v[ 'unionid' ] ?? '',
'groupid' => '',
'is_subscribe' => 1,
'remark' => $v[ 'remark' ],
'subscribe_time' => $v[ 'subscribe_time' ] ?? 0,
'subscribe_scene' => $v[ 'subscribe_scene' ] ?? 0,
'unsubscribe_time' => $v[ 'unsubscribe_time' ] ?? 0,
'update_date' => time()
];
$info = $fans_model->getFansInfo([ 'openid' => $v[ 'openid' ], 'site_id' => $this->site_id ], 'openid');
if (!empty($info[ 'data' ])) {
$fans_model->editFans($add_data, [ [ 'openid', '=', $v[ 'openid' ] ], [ 'site_id', '=', $this->site_id ] ]);
} else {
$fans_model->addFans($add_data);
}
}
}
return $result;
}
}
/**
* 微信粉丝标签
*/
public function fansTagList()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$page = input('page', 1);
$limit = input('limit', PAGE_LIST_ROWS);
$condition = [];
$list = $fans_model->getFansTagPageList($condition, $page, $limit);
return $list;
} else {
return $this->fetch('fans/fans_tag_list');
}
}
/**
* 为微信粉丝批量打标签
*/
public function fansBatchTagging()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$tagids = input('tag_id', '');
$openids = input('openid', '');
if (!empty($openids)) {
$tag_id_list = explode(',', $tagids);
$openid_list = explode(',', $openids);
$data = [
'tag_id_list' => $tag_id_list,
'openid_list' => $openid_list
];
$res = $fans_model->fansBatchTagging($data);
return $res;
}
}
}
/**
* 为微信粉丝打标签
*/
public function fansTagging()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$openid = input('openid', '');
$tagid_list = input('tagid_list', '');
$cancel_tagid_list = input('cancel_tagid_list', '');
if (!empty($openid)) {
$tagid_list_arr = !empty($tagid_list) ? explode(',', $tagid_list) : [];
$cancel_tagid_list_arr = !empty($cancel_tagid_list) ? explode(',', $cancel_tagid_list) : [];
$data = [
'tag_id_list' => $tagid_list_arr,
'openid_list' => [ $openid ]
];
$res = $fans_model->fansBatchTagging($data);//批量增加标签
$data[ 'tag_id_list' ] = $cancel_tagid_list_arr;
$fans_model->batchUnTagging($data);//批量减少标签
return $res;
}
}
}
/**
* 添加标签
* @return array
*/
public function addFansTag()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$tag_name = input('tag_name', '');
if (!empty($tag_name)) {
$data = [
'tag_name' => $tag_name,
];
$data[ "tags" ] = time();
$data[ "tag_id" ] = time();
$res = $fans_model->addFansTag($data);
return $res;
}
}
}
/**
* 编辑标签
*/
public function editFansTag()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$id = input('id', '');
$tag_name = input('tag_name', '');
if (!empty($tag_name)) {
$data = [
'tag_name' => $tag_name,
];
$condition = array (
[ "id", "=", $id ]
);
$res = $fans_model->editFansTag($data, $condition);
return $res;
} else {
return error("", "标签名称不可为空!");
}
}
}
/**
* 删除标签
*/
public function deleteFansTag()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$id = input('id', '');
$condition = [
[ 'id', "=", $id ],
];
$res = $fans_model->deleteFansTag($condition);
return $res;
}
}
/**
* 同步粉丝标签
*/
public function syncFansTag()
{
if (request()->isJson()) {
$fans_model = new FansModel();
$res = $fans_model->syncFansTag();
return $res;
}
}
}

View File

@@ -0,0 +1,312 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Material as MaterialModel;
use addon\wechat\model\Wechat as WechatModel;
/**
* 微信素材控制器
*/
class Material extends BaseWechat
{
/**
* 素材列表--图文消息
*/
public function lists()
{
if (request()->isJson()) {
$type = input('type', '');
$name = input('name', '');
$page_index = input('page', 1);
$page_size = input('limit', 9);
if (!empty($type)) {
$condition[] = [ 'type', "=", $type ];
}
if (!empty($name)) {
$condition[] = array (
'value', 'like', '%"name":"%' . $name . '%","url"%'
);
}
$condition[] = [ 'site_id', '=', $this->site_id ];
$material_model = new MaterialModel();
$material_list = $material_model->getMaterialPageList($condition, $page_index, $page_size, 'type asc,create_time desc');
if (!empty($material_list[ 'data' ][ 'list' ]) && is_array($material_list[ 'data' ][ 'list' ])) {
foreach ($material_list[ 'data' ][ 'list' ] as $k => $v) {
if (!empty($v[ 'value' ]) && json_decode($v[ 'value' ])) {
$material_list[ 'data' ][ 'list' ][ $k ][ 'value' ] = json_decode($v[ 'value' ], true);
}
}
}
return $material_list;
} else {
return $this->fetch('material/lists');
}
}
/**
* 添加图文消息
*/
public function add()
{
if (request()->isJson()) {
$type = input('type', 1);
$param[ 'value' ] = input('value', '');
if ($type != 1) {
// 图片、音频、视频、缩略图素材
$file_path = input('path', '');
$res = $this->uploadApi($type, [ 'path' => $file_path ]);
if ($res[ 'code' ] != 0) {
return $res;
}
$value[ 'file_path' ] = $file_path;
$value[ 'url' ] = $res[ 'data' ][ 'url' ];
$param[ 'value' ] = json_encode($value);
$param[ 'media_id' ] = $res[ 'data' ][ 'media_id' ];
} else {
$param[ 'media_id' ] = time() . 'GRAPHIC' . 'MESSAGE' . rand(1, 1000);
}
$param[ 'type' ] = $type;
$param[ 'create_time' ] = time();
$param[ 'update_time' ] = time();
$param[ 'site_id' ] = $this->site_id;
$material_model = new MaterialModel();
$res = $material_model->addMaterial($param);
return $res;
} else {
$this->assign('material_id', '0');
$this->assign('flag', false);
return $this->fetch('material/edit');
}
}
/**
* 修改图文消息
*/
public function edit()
{
if (request()->isJson()) {
$condition = [];
$condition[ 'id' ] = input('id', '');
$data[ 'value' ] = input('value', '');
$data[ 'update_time' ] = time();
$material_model = new MaterialModel();
$res = $material_model->editMaterial($data, $condition);
return $res;
} else {
$material_id = input('id', '');
$this->assign('material_id', $material_id);
$this->assign('flag', true);
return $this->fetch('material/edit');
}
}
/**
* 添加文本素材
*/
public function addTextMaterial()
{
if (request()->isJson()) {
$type = input('type', 1);
$param[ 'value' ] = input('value', '');
$param[ 'type' ] = $type;
$param[ 'create_time' ] = time();
$param[ 'update_time' ] = time();
$param[ 'site_id' ] = $this->site_id;
$material_model = new MaterialModel();
$res = $material_model->addMaterial($param);
return $res;
} else {
return $this->fetch('material/add_text');
}
}
/**
* 修改文本素材
*/
public function editTextMaterial()
{
$material_model = new MaterialModel();
if (request()->isJson()) {
$media_id = input("media_id", "");
$media_id = str_replace("MATERIAL_TEXT_MESSAGE_", "", $media_id);
$content = input("content", "");
$content = [ "content" => $content ];
$content = json_encode($content, JSON_UNESCAPED_UNICODE);
$condition[ 'id' ] = $media_id;
$data[ 'value' ] = $content;
$data[ 'update_time' ] = time();
$res = $material_model->editMaterial($data, $condition);
return $res;
} else {
$material_id = input('id', '');
$data = $material_model->getMaterialInfo([ [ 'id', '=', $material_id ], [ 'site_id', '=', $this->site_id ] ]);
if (!empty($data[ 'data' ])) {
$data[ 'data' ][ 'value' ] = json_decode($data[ 'data' ][ 'value' ], true);
}
$this->assign('material_data', $data[ 'data' ]);
return $this->fetch('material/edit_text');
}
}
/**
* 预览图文
*/
public function previewGraphicMessage()
{
$id = input('id', '');
$index = input('i', '');
$material_model = new MaterialModel();
$info = $material_model->getMaterialInfo([ 'id' => $id ]);
if (!empty($info[ 'data' ][ 'value' ]) && json_decode($info[ 'data' ][ 'value' ], true)) {
$info[ 'data' ][ 'value' ] = json_decode($info[ 'data' ][ 'value' ], true);
}
$this->assign('info', $info[ 'data' ]);
$this->assign('index', $index);
return $this->fetch('material/preview_material');
}
/**
* 预览文本
*/
public function previewTextMessage()
{
$id = input('id', '');
$material_model = new MaterialModel();
$info = $material_model->getMaterialInfo([ 'id' => $id ]);
if (!empty($info[ 'data' ][ 'value' ]) && json_decode($info[ 'data' ][ 'value' ], true)) {
$info[ 'data' ][ 'value' ] = json_decode($info[ 'data' ][ 'value' ], true);
}
$this->assign('info', $info[ 'data' ]);
return $this->fetch('material/preview_text');
}
/**
* 上传永久素材
* @param $type
* @param $data
* @return array
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function uploadApi($type, $data)
{
$wechat_model = new WechatModel();
if ($type == 1) {
$res = $wechat_model->uploadArticle($data);
} else {
if ($type == 2) {
$type = 'image';
$res = $wechat_model->uploadImage($data[ 'path' ]);
} else if ($type == 3) {
$type = 'voice';
$res = $wechat_model->uploadVoice($data[ 'path' ]);
} else if ($type == 4) {
$type = 'video';
$res = $wechat_model->uploadVideo($data[ 'path' ]);
} else if ($type == 6) {
$res = $wechat_model->uploadVideo($data[ 'path' ]);
$type = 'thumb';
}
}
return $res;
}
/**
* 删除微信素材
*/
public function delete()
{
if (request()->isJson()) {
$id = input('id', 0);
$material_model = new MaterialModel();
$condition = array (
[ "id", "=", $id ]
);
$res = $material_model->deleteMaterial($condition);
return $res;
}
}
/**
* 获取素材详情
* @return mixed
*/
public function getMaterialInfo()
{
if (request()->isJson()) {
$material_model = new MaterialModel();
$condition = array (
[ 'id', '=', input('id', '') ]
);
$material_info = $material_model->getMaterialInfo($condition);
if (json_decode($material_info[ 'data' ][ 'value' ])) {
$material_info[ 'data' ][ 'value' ] = json_decode($material_info[ 'data' ][ 'value' ]);
}
return $material_info;
}
}
/**
* 图文素材
*/
public function articleList()
{
$material_model = new MaterialModel();
$condition = array (
[ 'type', '=', 1 ]
);
$material_list = $material_model->getMaterialList($condition, '*', 'update_time desc');
if (!empty($material_list[ 'data' ]) && is_array($material_list[ 'data' ])) {
foreach ($material_list[ 'data' ] as $k => $v) {
if (!empty($v[ 'value' ]) && json_decode($v[ 'value' ])) {
$material_list[ 'data' ][ $k ][ 'value' ] = json_decode($v[ 'value' ], true);
}
}
}
$this->assign('material_list', $material_list);
return $this->fetch('material/index');
}
/**
* 素材管理
*/
public function material()
{
//这这里的常量要与base中的区分如果一致界面将无法渲染
$type = input("type", 1);
$this->assign("type", $type);
// return array( 'shop/material/material' );
return $this->fetch('material/material');
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Menu as MenuModel;
use addon\wechat\model\Wechat as WechatModel;
/**
* 微信菜单控制器
*/
class Menu extends BaseWechat
{
/**
* 微信自定义菜单配置
*/
public function menu()
{
if (request()->isJson()) {
$menu_model = new MenuModel();
$menu_info = $menu_model->getWechatMenuConfig($this->site_id);
return $menu_info;
} else {
return $this->fetch('menu/menu');
}
}
/**
* 修改微信自定义菜单
*/
public function edit()
{
if (request()->isJson()) {
$menu_value = input('value', '');
$menu_json = input('json_data', '');
$menu_model = new MenuModel();
$data = json_decode($menu_value, true);
$res = $menu_model->setWechatMenuConfig($data, $this->site_id);
if ($res[ 'code' ] != 0) {
return $res;
}
$res = $this->sendWeixinMenu($menu_json);
return $res;
}
}
/**
* 公众号同步更新微信菜单
*/
public function sendWeixinMenu($menu_json)
{
$wechat_model = new WechatModel($this->site_id);
$menu_arr = json_decode($menu_json, true);
$res = $wechat_model->menu($menu_arr[ 'button' ]);
return $res;
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Config;
use app\model\message\Message as MessageModel;
use app\model\message\MessageTemplate as MessageTemplateModel;
/**
* 微信公众号模板消息
*/
class Message extends BaseWechat
{
/**
* 编辑模板消息
* @return array|mixed|string
*/
public function edit()
{
$message_model = new MessageModel();
$keywords = input("keywords", "");
$info = $message_model->getMessageInfo($this->site_id, $keywords)[ 'data' ];
if (empty($info))
$this->error("不存在的模板信息!");
$wechat_json_array = $info[ "wechat_json_array" ];
if (request()->isJson()) {
$wechat_is_open = input('wechat_is_open', 0);
// $bottomtext = input("bottomtext", "");
// $headtext = input("headtext", "");
// $bottomtextcolor = input("bottomtextcolor", "");
// $headtextcolor = input("headtextcolor", "");
//// $wechat_json_array[ 'headtext' ] = $headtext;//头部标题
// $wechat_json_array[ 'headtextcolor' ] = $headtextcolor;//头部标题颜色
// $wechat_json_array[ 'bottomtext' ] = $bottomtext;//尾部描述
// $wechat_json_array[ 'bottomtextcolor' ] = $bottomtextcolor;//尾部描述颜色
$data = array (
'wechat_json' => json_encode($wechat_json_array),
);
$condition = array (
[ "keywords", "=", $keywords ]
);
$template_model = new MessageTemplateModel();
$res = $template_model->editMessageTemplate($data, $condition);
if ($res[ 'code' ] == 0) {
$res = $message_model->editMessage([ 'wechat_is_open' => $wechat_is_open, 'site_id' => $this->site_id, 'keywords' => $keywords ], [
[ "keywords", "=", $keywords ],
[ 'site_id', '=', $this->site_id ],
]);
}
return $res;
} else {
$this->assign("keywords", $keywords);
if (isset($wechat_json_array[ 'keyword_name_list' ])) {
$wechat_json_array[ 'keyword_name_list' ] = implode(',', $wechat_json_array[ 'keyword_name_list' ]);
}
$this->assign("info", $wechat_json_array);
$this->assign('wechat_is_open', $info[ 'wechat_is_open' ]);
$this->assign('message_title', $info[ 'title' ]);
return $this->fetch('message/edit');
}
}
/**
* 模板消息设置
* @return array|mixed
*/
public function config()
{
$message_model = new MessageModel();
if (request()->isJson()) {
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$condition = array (
[ "support_type", "like", '%wechat%' ],
);
$list = $message_model->getMessagePageList($condition, $this->site_id, $page, $page_size);
return $list;
} else {
$config_model = new Config();
$config = $config_model->getTemplateMessageConfig($this->site_id)[ 'data' ][ 'value' ];
$this->assign('config', $config);
return $this->fetch('message/config');
}
}
/**
* 微信模板消息状态设置
*/
public function setWechatStatus()
{
$message_model = new MessageModel();
if (request()->isJson()) {
$keywords = input("keywords", "");
$wechat_is_open = input('wechat_is_open', 0);
$res = $message_model->getWechatTemplateNo($keywords, $this->site_id, $wechat_is_open);
return $res;
}
}
/**
* 获取模板编号
*/
public function getWechatTemplateNo()
{
if (request()->isJson()) {
$keywords = input("keywords", "");
$message_model = new MessageModel();
$res = $message_model->getWechatTemplateNo($keywords, $this->site_id, -1);
return $res;
}
}
/**
* 设置模板消息配置
* @return array
*/
public function messageConfig()
{
if (request()->isJson()) {
$is_jump_weapp = input("is_jump_weapp", 0);
$config_model = new Config();
$res = $config_model->setTemplateMessageConfig([ 'is_jump_weapp' => $is_jump_weapp ], 1, $this->site_id);
return $res;
}
}
}

View File

@@ -0,0 +1,353 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Replay as ReplayModel;
/**
* 微信回复控制器
*/
class Replay extends BaseWechat
{
/**
* 回复设置--关键字自动回复
*/
public function replay()
{
if (request()->isJson()) {
$page = input('page', 1);
$limit = input('limit', PAGE_LIST_ROWS);
$rule_type = input('rule_type', '');
$search_text = input('search_text', '');
$condition = array (
[ 'rule_type', "=", $rule_type ],
[ 'site_id', '=', $this->site_id ]
);
$condition[] = [
'rule_name', 'like', '%' . $search_text . '%'
];
$order = 'create_time desc';
$replay_model = new ReplayModel();
$list = $replay_model->getReplayPageList($condition, $page, $limit, $order);
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
$list[ 'data' ][ 'list' ][ $k ][ 'key_list' ] = $v['keywords_json'] ? json_decode($v[ 'keywords_json' ]) : [];
$list[ 'data' ][ 'list' ][ $k ][ 'replay_list' ] = $v['replay_json'] ? json_decode($v[ 'replay_json' ]) : [];
}
return $list;
} else {
$this->assign('link_list', []);
return $this->fetch('replay/replay');
}
}
/**
* 添加关键字回复
*/
public function addOrEditRule()
{
$replay_model = new ReplayModel();
if (request()->isJson()) {
$rule_name = input('rule_name', '');
$rule_id = input('rule_id', 0);
if ($rule_id > 0) {
$data = [
'rule_name' => $rule_name,
'modify_time' => time()
];
$res = $replay_model->editRule($data, [ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
} else {
$data = [
'rule_name' => $rule_name,
'rule_type' => 'KEYWORDS',
'keywords_json' => '',
'replay_json' => '',
'create_time' => time(),
'site_id' => $this->site_id
];
$res = $replay_model->addRule($data);
return $res;
}
}
}
/**
* 添加关键词回复
*/
public function editKeywords()
{
$replay_model = new ReplayModel();
if (request()->isJson()) {
$rule_id = input('rule_id', '');
$keywords_name = input('keywords_name', '');
$keywords_type = input('keywords_type', 0);
$key_id = input('key_id', -1);
$info = $replay_model->getRuleInfo([ [ 'rule_id', "=", $rule_id ] ])[ 'data' ];
if ($info[ 'keywords_json' ]) {
$data = json_decode($info[ 'keywords_json' ]);
if ($key_id > -1) {
$data[ $key_id ] = [
'keywords_name' => $keywords_name,
'keywords_type' => $keywords_type
];
} else {
$data[] = [
'keywords_name' => $keywords_name,
'keywords_type' => $keywords_type
];
}
$data = json_encode($data);
} else {
$data = [
[
'keywords_name' => $keywords_name,
'keywords_type' => $keywords_type
]
];
$data = json_encode($data);
}
$data = [
'keywords_json' => $data,
'modify_time' => time()
];
$res = $replay_model->editRule($data, [ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
}
}
/**
* 删除关键字回复
*/
public function deleteRule()
{
if (request()->isJson()) {
$rule_id = input('rule_id', 0);
$replay_model = new ReplayModel();
$res = $replay_model->deleteRule([ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
}
}
/**
* 删除关键词数据
*/
public function deleteKeywords()
{
$replay_model = new ReplayModel();
if (request()->isJson()) {
$rule_id = input('rule_id', '');
$key_id = input('key_id', '');
$info_result = $replay_model->getRuleInfo([ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
$info = $info_result[ "data" ];
$keywords_json = '';
if ($info[ 'keywords_json' ]) {
$keywords_json = json_decode($info[ 'keywords_json' ]);
array_splice($keywords_json, $key_id, 1);
$keywords_json = json_encode($keywords_json);
}
$data = [
'keywords_json' => $keywords_json,
];
$res = $replay_model->editRule($data, [ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
}
}
/**
* 修改回复数据
* @return mixed
*/
public function editReplays()
{
$replay_model = new ReplayModel();
if (request()->isJson()) {
$rule_id = input('rule_id', '');
$reply_content = input('reply_content', '');
$media_id = input('media_id', '');
$key_id = input('key_id', -1);
$type = input('type', '');
$replay_type = input('replay_type', '');
$info_result = $replay_model->getRuleInfo([ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
$info = $info_result[ "data" ];
if (!empty($rule_id)) {
if ($info[ 'replay_json' ]) {
$data = json_decode($info[ 'replay_json' ]);
if ($key_id > -1) {
$data[ $key_id ] = [
'reply_content' => $reply_content,
'type' => $type,
];
if (!empty($media_id)) {
$data[ $key_id ][ 'media_id' ] = $media_id;
}
} else {
if (!empty($media_id)) {
$data[] = [
'reply_content' => $reply_content,
'type' => $type,
'media_id' => $media_id
];
} else {
$data[] = [
'reply_content' => $reply_content,
'type' => $type,
];
}
}
} else {
$data = [
[
'reply_content' => $reply_content,
'type' => $type,
]
];
if (!empty($media_id)) {
$data[ 0 ][ 'media_id' ] = $media_id;
}
}
$data = json_encode($data);
$data = [
'replay_json' => $data,
'modify_time' => time()
];
$res = $replay_model->editRule($data, [ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
} else {
$rule_type = '';
$rule_name = '';
if ($replay_type == "default") {
$rule_type = 'DEFAULT';
$rule_name = '默认回复';
} else if ($replay_type == "follow") {
$rule_type = 'AFTER';
$rule_name = '关注后回复';
}
$data = [
[
'reply_content' => $reply_content,
'type' => $type,
]
];
if (!empty($media_id)) {
$data[ 0 ][ 'media_id' ] = $media_id;
}
$data = json_encode($data);
$data = [
'replay_json' => $data,
'modify_time' => time(),
'rule_name' => $rule_name,
'rule_type' => $rule_type,
'site_id' => $this->site_id,
];
$res = $replay_model->addRule($data);
return $res;
}
}
}
/**
* 删除回复数据
*/
public function deleteReply()
{
$replay_model = new ReplayModel();
if (request()->isJson()) {
$rule_id = input('rule_id', '');
$key_id = input('key_id', '');
$info = $replay_model->getRuleInfo([ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
$info = $info[ 'data' ];
$replay_json = '';
if ($info[ 'replay_json' ]) {
$replay_json = json_decode($info[ 'replay_json' ]);
array_splice($replay_json, $key_id, 1);
$replay_json = json_encode($replay_json);
}
$data = [
'replay_json' => $replay_json,
];
$res = $replay_model->editRule($data, [ [ 'rule_id', "=", $rule_id ], [ 'site_id', "=", $this->site_id ] ]);
return $res;
}
}
/**
* 关注后回复设置
*/
public function afterAttention()
{
return $this->fetch('replay/aterAttention');
}
/**
* 回复设置--关注后自动回复
*/
public function follow()
{
if (request()->isJson()) {
$page = input('page', 1);
$pagesize = input('limit', PAGE_LIST_ROWS);
$rule_type = input('rule_type', '');
$condition = array (
'rule_type' => $rule_type,
'site_id' => $this->site_id
);
$order = 'create_time desc';
$replay_model = new ReplayModel();
$list = $replay_model->getReplayPageList($condition, $page, $pagesize, $order);
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
$list[ 'data' ][ 'list' ][ $k ][ 'key_list' ] = $v['keywords_json'] ? json_decode($v[ 'keywords_json' ]) : [];
$list[ 'data' ][ 'list' ][ $k ][ 'replay_list' ] = $v['replay_json'] ? json_decode($v[ 'replay_json' ]) : [];
}
return $list;
} else {
$this->assign('link_list', []);//链接
return $this->fetch('replay/follow');
}
}
public function default()
{
if (request()->isJson()) {
$page = input('page', 1);
$limit = input('limit', PAGE_LIST_ROWS);
// $rule_type = input('rule_type', '');
$search_text = input('search_text', '');
$condition = array (
[ 'rule_type', "=", 'DEFAULT' ], //只获取默认的
[ 'site_id', '=', $this->site_id ]
);
$condition[] = [
'rule_name', 'like', '%' . $search_text . '%'
];
$order = 'create_time desc';
$replay_model = new ReplayModel();
$list = $replay_model->getReplayPageList($condition, $page, $limit, $order);
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
$list[ 'data' ][ 'list' ][ $k ][ 'key_list' ] = $v['keywords_json'] ? json_decode($v[ 'keywords_json' ]) : [];
$list[ 'data' ][ 'list' ][ $k ][ 'replay_list' ] = $v['replay_json'] ? json_decode($v[ 'replay_json' ]) : [];
}
return $list;
} else {
$this->assign('link_list', []);//链接
return $this->fetch('replay/default');
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Stat as StatModel;
/**
* 微信公众号基础功能
*/
class Stat extends BaseWechat
{
/**
* 访问统计
*/
public function stat()
{
$stat_model = new StatModel();
$yesterday = date('Y-m-d', strtotime('-1 day'));
//昨天的用户分析数据
$wechat_fans_result = $stat_model->fans($yesterday, $yesterday);
$this->assign('yesterday_user_data', $wechat_fans_result[ 'data' ][ 0 ] ?? []);
//昨天的接口分析数据
$wechat_interface_result = $stat_model->interfaceSummary($yesterday, $yesterday);
$this->assign('yesterday_interface_data', $wechat_interface_result[ 'data' ][ 0 ] ?? []);
return $this->fetch('stat/stat');
}
/**
* 接口调用统计
* @return array
*/
public function interfaceSummaryStatistics()
{
$date_type = input("date_type", "week");
$stat_model = new StatModel();
$result = $stat_model->interfaceSummaryStatistics($date_type);
return $result;
}
/**
* 用户访问统计
* @return array
*/
public function userSummaryStatistics()
{
$date_type = input("date_type", "week");
$stat_model = new StatModel();
$result = $stat_model->userSummaryStatistics($date_type);
return $result;
}
}

View File

@@ -0,0 +1,323 @@
<?php
/**
* Niushop商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.niushop.com
* =========================================================
*/
namespace addon\wechat\shop\controller;
use addon\wechat\model\Config as ConfigModel;
use addon\wechat\model\Qrcode;
use app\model\share\WchatShareBase as ShareModel;
use app\model\system\User;
/**
* 微信公众号基础功能
*/
class Wechat extends BaseWechat
{
/**
* 功能设置
*/
public function setting()
{
$replay_url = 'wechat://shop/replay/replay';
if(!($this->user_info['is_admin'] == 1 || $this->group_info['is_system'] == 1)){
$user_model = new User();
$check_res = $user_model->checkAndGetRedirectUrl(['url' => $replay_url, 'app_module' => $this->app_module], $this->group_info);
if($check_res['redirect_url']){
$replay_url = $check_res[ 'redirect_url' ];
}
}
$setting_arr = [
[
'url' => href_url('wechat://shop/wechat/config'),
'img' => 'config_wechat_icon.png',
'title' => '公众号管理',
'content' => '公众号管理',
],
[
'url' => href_url('wechat://shop/material/lists'),
'img' => 'config_material_icon.png',
'title' => '消息素材',
'content' => '消息素材',
],
// [
// 'url' => href_url('wechat://shop/fans/lists'),
// 'img' => 'config_material_icon.png',
// 'title' => '粉丝列表',
// 'content' => '粉丝列表',
// ],
[
'url' => href_url('wechat://shop/menu/menu'),
'img' => 'config_menu_icon.png',
'title' => '菜单管理',
'content' => '菜单管理',
],
// [
// 'url' => href_url('wechat://shop/wechat/qrcode'),
// 'img' => 'config_qrcode_icon.png',
// 'title' => '推广二维码',
// 'content' => '推广二维码管理',
// ],
[
'url' => href_url('wechat://shop/wechat/share'),
'img' => 'config_share_icon.png',
'title' => '分享内容设置',
'content' => '分享内容设置',
],
[
'url' => href_url($replay_url),
'img' => 'config_replay_icon.png',
'title' => '回复设置',
'content' => '回复设置',
],
[
'url' => href_url('wechat://shop/message/config'),
'img' => 'config_message_icon.png',
'title' => '模板消息',
'content' => '模板消息设置',
],
];
$this->assign('setting_arr', $setting_arr);
return $this->fetch('wechat/setting');
}
/**
* 公众号配置
*/
public function config()
{
$config_model = new ConfigModel();
if (request()->isJson()) {
$wechat_name = input('wechat_name', '');//公众号名称 (备注: 公众号名称,尽量与公众号平台保持一致)
$wechat_original = input('wechat_original', '');//公众号原始id (备注: 公众号原始id,如gh_111111111111)
$appid = input('appid', '');//gh_845581623321AppID (备注: AppID 请注意需要与微信公众号平台保持一致,且注意信息安全,不要随意透露给第三方)
$appsecret = input('appsecret', '');//AppSecret (备注: AppSecret密钥需要与微信公众号平台保持一致没有特别原因不要随意修改也不要随意透露给第三方)
$token = input('token', 'TOKEN');//Token (备注: 自定义的Token值、确保后台与公众号平台填写的一致)
$encodingaeskey = input('encodingaeskey', '');//EncodingAESKey (备注: 由开发者手动填写或随机生成,将用作消息体加解密密钥)
$is_use = input('is_use', 1);//是否启用
$qrcode = input('qrcode', '');//二维码
$headimg = input('headimg', '');//头像
$data = array (
"wechat_name" => $wechat_name,
"wechat_original" => $wechat_original,
"appid" => $appid,
"appsecret" => $appsecret,
"token" => $token,
"encodingaeskey" => $encodingaeskey,
'qrcode' => $qrcode,
'headimg' => $headimg,
);
$res = $config_model->setWechatConfig($data, $is_use, $this->site_id);
return $res;
} else {
$config_result = $config_model->getWechatConfig($this->site_id);
$config = $config_result[ "data" ];
$is_authopen = $config_result[ 'data' ][ 'value' ][ 'is_authopen' ] ?? 0;
if ($is_authopen == 1) {
$config[ 'value' ] = [];
}
$this->assign("config", $config);
// 获取当前域名
$url = __ROOT__;
// 去除链接的http://头部
$url_top = str_replace("https://", "", $url);
$url_top = str_replace("http://", "", $url_top);
// 去除链接的尾部/?s=
$url_top = str_replace('/?s=', '', $url_top);
$call_back_url = addon_url("wechat://api/auth/relateweixin");
$this->assign("url", $url_top);
$this->assign("call_back_url", $call_back_url);
return $this->fetch('wechat/config');
}
}
/**
* 推广二维码模板
*/
public function qrcode()
{
$qrcode_model = new Qrcode();
$template_list = $qrcode_model->getQrcodePageList([ 'is_remove' => 0 ]);
$this->assign("template_list", $template_list[ 'data' ]);
return $this->fetch('wechat/qrcode');
}
/**
* 推广二维码
*/
public function addQrcode()
{
if (request()->isJson()) {
$data = array (
'background' => input("background", ''),
'nick_font_color' => input("nick_font_color", '#000'),
'nick_font_size' => input("nick_font_size", '12'),
'is_logo_show' => input("is_logo_show", '1'),
'header_left' => input("header_left", '59') . 'px',
'header_top' => input("header_top", '15') . 'px',
'name_left' => input("name_left", '128') . 'px',
'name_top' => input("name_top", '23') . 'px',
'logo_left' => input("logo_left", '60') . 'px',
'logo_top' => input("logo_top", '200') . 'px',
'code_left' => input("code_left", '70') . 'px',
'code_top' => input("code_top", '300') . 'px',
);
$qrcode_model = new Qrcode();
$result = $qrcode_model->addQrcode($data);
return $result;
} else {
return $this->fetch('wechat/add_qrcode');
}
}
/**
* 编辑二维码模板
* @return mixed
*/
public function editQrcode()
{
$id = input("id", 0);
$qrcode_model = new Qrcode();
$condition = array (
"id" => $id
);
if (request()->isJson()) {
$data = array (
'background' => input("background", ''),
'nick_font_color' => input("nick_font_color", '#000'),
'nick_font_size' => input("nick_font_size", '12'),
'is_logo_show' => input("is_logo_show", '1'),
'header_left' => input("header_left", '59') . 'px',
'header_top' => input("header_top", '15') . 'px',
'name_left' => input("name_left", '128') . 'px',
'name_top' => input("name_top", '23') . 'px',
'logo_left' => input("logo_left", '60') . 'px',
'logo_top' => input("logo_top", '200') . 'px',
'code_left' => input("code_left", '70') . 'px',
'code_top' => input("code_top", '300') . 'px',
);
$result = $qrcode_model->editQrcode($data, $condition);
return $result;
} else {
$info = $qrcode_model->getQrcodeInfo($condition)[ "data" ];
$this->assign("info", $info);
return $this->fetch('wechat/edit_qrcode');
}
}
/**
* 设置默认推广二维码
*/
public function qrcodeDefault()
{
if (request()->isJson()) {
$id = input('id', 0);
$qrcode_model = new Qrcode();
$result = $qrcode_model->modifyQrcodeDefault([ 'id' => $id ]);
return $result;
}
}
/**
* 删除默认推广二维码
*/
public function deleteQrcode()
{
if (request()->isJson()) {
$id = input('id', 0);
$qrcode_model = new Qrcode();
$result = $qrcode_model->deleteQrcode([ 'id' => $id ]);
return $result;
}
}
/**
* 分享内容设置
*/
public function shareBack()
{
$config_model = new ConfigModel();
if (request()->isJson()) {
$qrcode_param_1 = input('qrcode_param_1', '');
$qrcode_param_2 = input('qrcode_param_2', '');
$goods_param_1 = input('goods_param_1', '');
$goods_param_2 = input('goods_param_2', '');
$shop_param_1 = input('shop_param_1', '');
$shop_param_2 = input('shop_param_2', '');
$shop_param_3 = input('shop_param_3', '');
$data = array (
'qrcode_param_1' => $qrcode_param_1,
'qrcode_param_2' => $qrcode_param_2,
'goods_param_1' => $goods_param_1,
'goods_param_2' => $goods_param_2,
'shop_param_1' => $shop_param_1,
'shop_param_2' => $shop_param_2,
'shop_param_3' => $shop_param_3,
);
$res = $config_model->setShareConfig($data, 1, $this->site_id);
return $res;
} else {
$config_result = $config_model->getShareConfig($this->site_id);
$this->assign("info", $config_result[ "data" ][ 'value' ]);
return $this->fetch('wechat/share_back');
}
}
/**
* 分享内容设置
*/
public function share()
{
if (request()->isJson()) {
$data_json = input('data_json', '');
$data = json_decode($data_json, true);
$share_model = new ShareModel();
return $share_model->setShareConfig($this->site_id, $data);
} else {
$share_config = event('WchatShareConfig', [ 'site_id' => $this->site_id ]);
$config_list = [];
foreach ($share_config as $data) {
foreach ($data[ 'data' ] as $val) {
$config_list[] = $val;
}
}
$this->assign('config_list', $config_list);
return $this->fetch('wechat/share');
}
}
/**
* 公众号设置
*/
public function configSetting()
{
$config_model = new ConfigModel();
$config_result = $config_model->getWechatConfig($this->site_id);
$config = $config_result[ "data" ];
if (!empty($config[ "value" ])) {
//是否是开放平台授权
$is_authopen = $config_result[ 'data' ][ 'value' ][ 'is_authopen' ] ?? 0;
if ($is_authopen > 0) {
$this->redirect(addon_url("wxoplatform://shop/oplatform/wechat"));
} else {
$this->redirect(addon_url("wechat://shop/wechat/config"));
}
} else {
$this->redirect(addon_url("wxoplatform://shop/oplatform/wechatsettled"));
}
}
}