173 lines
4.8 KiB
PHP
173 lines
4.8 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\service;
|
||
|
||
use app\common\model\Member as MemberModel;
|
||
use app\common\model\MemberInfo as MemberInfoModel;
|
||
use app\common\model\Message as MessageModel;
|
||
use app\common\validate\Message as MessageValidate;
|
||
use cjango\Wechat;
|
||
use think\Cache;
|
||
use think\Config;
|
||
|
||
class Message extends _Init
|
||
{
|
||
public static function send($data, $uid)
|
||
{
|
||
if ($uid == $data['to_uid']) {
|
||
return '不能自己给自己留言';
|
||
}
|
||
|
||
$data['from_uid'] = $uid;
|
||
|
||
$validate = new MessageValidate();
|
||
if (!$validate->check($data)) {
|
||
return $validate->getError();
|
||
}
|
||
|
||
if (MessageModel::create($data)) {
|
||
return true;
|
||
} else {
|
||
return '添加失败';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 点赞
|
||
* @param [type] $uid [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public static function tags($uid)
|
||
{
|
||
$MemberInfo = MemberInfoModel::get($uid);
|
||
if (!$MemberInfo) {
|
||
return '没有这个人';
|
||
}
|
||
if ($MemberInfo->setInc('tags')) {
|
||
return true;
|
||
} else {
|
||
return '点赞失败';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取列表
|
||
* @param [type] $uid [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public static function getList($uid)
|
||
{
|
||
return MessageModel::where('to_uid', $uid)->select();
|
||
}
|
||
|
||
/**
|
||
* 删除留言
|
||
* @param [type] $id [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public static function del($id)
|
||
{
|
||
|
||
$info = MessageModel::get($id);
|
||
if (!$info) {
|
||
return '没有这条留言';
|
||
} elseif ($info->delete()) {
|
||
return true;
|
||
} else {
|
||
return '删除失败';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发送积分变更消息
|
||
* @param [type] $no
|
||
* @return [type] [description]
|
||
*/
|
||
public static function addScoreMessage($ruleInfo, $MemberInfo, $remark)
|
||
{
|
||
self::initWechat();
|
||
$Member = MemberModel::get($MemberInfo->uid);
|
||
$openid = $Member->openid;
|
||
if (empty($openid)) {
|
||
die();
|
||
}
|
||
//发送给客户
|
||
$msgdata = [
|
||
'first' => [
|
||
'value' => '您好,您的会员积分信息有了新的变更',
|
||
],
|
||
'keyword1' => [
|
||
'value' => $MemberInfo->nickname,
|
||
],
|
||
'keyword2' => [
|
||
'value' => $Member->username,
|
||
],
|
||
'keyword3' => [
|
||
'value' => $remark . $ruleInfo->score . ' 积分',
|
||
],
|
||
'keyword4' => [
|
||
'value' => $MemberInfo->score,
|
||
],
|
||
'remark' => [
|
||
'value' => '如有疑问请联系客服',
|
||
],
|
||
];
|
||
$res = Wechat\Template::send($openid, 'q4Hv3qfG7a_2sqOPXd99vc9Z5M33ri98Gp5pgUNEk-U', $msgdata);
|
||
}
|
||
|
||
/**
|
||
* 发送开通会员消息
|
||
* @param [type] $ruleInfo [description]
|
||
* @param [type] $MemberInfo [description]
|
||
* @param [type] $remark [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public static function openvip($MemberInfo)
|
||
{
|
||
self::initWechat();
|
||
//发送给客户
|
||
$msgdata = [
|
||
'first' => [
|
||
'value' => '您好,您开通会员成功.',
|
||
],
|
||
'keyword1' => [
|
||
'value' => date("Y-m-d H:i:s"),
|
||
],
|
||
'keyword2' => [
|
||
'value' => '点击查看详情',
|
||
],
|
||
'remark' => [
|
||
'value' => '如有疑问请联系客服',
|
||
],
|
||
];
|
||
$res = Wechat\Template::send($openid, 'frAafbX_CaZgtlGGleNHH6o8PdH3ESqMU05SaJPJa0c', $msgdata, url('vip/index'));
|
||
}
|
||
|
||
/**
|
||
* 初始化微信
|
||
* @param [type] $config [description]
|
||
* @return [type] [description]
|
||
*/
|
||
public static function initWechat()
|
||
{
|
||
$config = Config::get('wechat_config');
|
||
$token = Cache::get('wechat_access_token');
|
||
// 检测TOKEN是否过期
|
||
if (!$token) {
|
||
$token = Wechat\Token::get();
|
||
Cache::set('wechat_access_token', $token, 7000);
|
||
$config['access_token'] = $token;
|
||
} else {
|
||
$config['access_token'] = $token;
|
||
}
|
||
Wechat::instance($config, true);
|
||
}
|
||
|
||
}
|