You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
768 lines
33 KiB
768 lines
33 KiB
<?php
|
|
defined('IN_IA') or exit('Access Denied');
|
|
|
|
class Pocket {
|
|
/**
|
|
* 从数据库获取幻灯片数据
|
|
*/
|
|
static function getslides($uniacid) {
|
|
global $_W, $_GPC;
|
|
$psize = 25;
|
|
$pindex = max(1, $_GPC['page']);
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_slide', array('uniacid' => $uniacid,'aid' => $_W['aid']), 'sort desc', $pindex, $psize);
|
|
// if ($data) {
|
|
// foreach ($data[0] as $k => $v) {
|
|
// if ($v['aid']) {
|
|
// if ($v['aid'] != $_W['aid']) {
|
|
// unset($data[0][$k]);
|
|
// }
|
|
// }
|
|
// }
|
|
// return $data;
|
|
// }
|
|
return $data;
|
|
}
|
|
//创建订单
|
|
static function saveFightOrder($data, $param = array()) {
|
|
global $_W;
|
|
if (!is_array($data))
|
|
return FALSE;
|
|
if (empty($param)) {
|
|
pdo_insert(PDO_NAME . 'order', $data);
|
|
return pdo_insertid();
|
|
}
|
|
return FALSE;
|
|
}
|
|
/**
|
|
* 获取分类
|
|
*/
|
|
static function gettypes($flag = 0) {
|
|
global $_W, $_GPC;
|
|
$uniacid = $_W['uniacid'];
|
|
if ($flag == 'all') {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_type', array('uniacid' => $uniacid,'aid'=>$_W['aid'] ,'type' => 0), 'sort desc', 0, 0);
|
|
} else {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_type', array('uniacid' => $uniacid,'aid'=>$_W['aid'] ,'type' => 0, 'isnav' => 0), 'sort desc', 0, 0);
|
|
}
|
|
if (!empty($data)) {
|
|
$data = $data[0];
|
|
foreach ($data as $key => &$value) {
|
|
//$value['httitle'] = urlencode($value['title']);
|
|
$value['httitle'] = $value['title'];
|
|
if ($value['aid']) {
|
|
if ($value['aid'] != $_W['aid']) {
|
|
unset($data[$key]);
|
|
} else {
|
|
$temp = Util::getNumData("*", PDO_NAME . 'pocket_type', array('type' => $value['id']), 'sort desc');
|
|
$temp = $temp[0];
|
|
foreach($temp as &$te){
|
|
//$te['httitle'] = urlencode($te['title']);
|
|
$te['httitle'] = $te['title'];
|
|
}
|
|
$data[$key]['children'] = $temp;
|
|
}
|
|
} else {
|
|
$temp = Util::getNumData("*", PDO_NAME . 'pocket_type', array('type' => $value['id']), 'sort desc');
|
|
$data[$key]['children'] = $temp[0];
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* 根据id检查某一级分类是否含有二级分类
|
|
*/
|
|
static function checkFType($id) {
|
|
global $_W, $_GPC;
|
|
|
|
$uniacid = $_W['uniacid'];
|
|
$data = null;
|
|
if ($id) {
|
|
$data = Util::getSingelData("*", PDO_NAME . 'pocket_type', array('uniacid' => $uniacid, 'type' => $id));
|
|
if ($data) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* 获取发帖信息
|
|
*/
|
|
static function getInformations($id = 0) {
|
|
global $_W, $_GPC;
|
|
|
|
$uniacid = $_W['uniacid'];
|
|
|
|
if (!$id) {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_informations', array('uniacid' => $uniacid));
|
|
} else {
|
|
$data = Util::getSingelData("*", PDO_NAME . 'pocket_informations', array('uniacid' => $uniacid, 'id' => $id));
|
|
}
|
|
|
|
if ($data) {
|
|
return $data;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/**
|
|
* 根据帖子id获取评论
|
|
*/
|
|
static function getcomments($id) {
|
|
global $_W, $_GPC;
|
|
|
|
$uniacid = $_W['uniacid'];
|
|
|
|
if ($id) {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_comment', array('uniacid' => $uniacid, 'tid' => $id));
|
|
}
|
|
|
|
if ($data) {
|
|
return $data;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/**
|
|
* 根据评论id获取回复
|
|
*/
|
|
static function getreplys($id) {
|
|
global $_W, $_GPC;
|
|
|
|
$uniacid = $_W['uniacid'];
|
|
|
|
if ($id) {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_reply', array('uniacid' => $uniacid, 'cid' => $id));
|
|
}
|
|
|
|
if ($data) {
|
|
return $data;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/**
|
|
* 根据类型获得帖子
|
|
*/
|
|
static function getInfoByType($id) {
|
|
global $_W, $_GPC;
|
|
|
|
$uniacid = $_W['uniacid'];
|
|
$data = null;
|
|
if ($id) {
|
|
$data = Util::getNumData("*", PDO_NAME . 'pocket_informations', array('type' => $id));
|
|
}
|
|
if ($data) {
|
|
return $data;
|
|
}
|
|
return null;
|
|
}
|
|
//异步支付结果回调 ,处理业务逻辑
|
|
static function payPocketshargeNotify($params) {
|
|
global $_W;
|
|
Util::wl_log('payResult_notify', PATH_PLUGIN . "pocket/data/", $params); //写入异步日志记录
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('id','fightstatus','mid', 'num', 'price', 'orderno', 'fkid', 'aid', 'status','uniacid'));
|
|
$_W['uniacid'] = $order['uniacid'];
|
|
if ($order['id']) {
|
|
$inform = self::getInformations($order['fkid']);
|
|
$type = pdo_get('wlmerchant_pocket_type',array('id' => $inform['type']),array('isdistri','onedismoney','twodismoney'));
|
|
//处理分销
|
|
if (p('distribution')) {
|
|
$_W['aid'] = $order['aid'];
|
|
if ($inform['redpack'] > 0) {
|
|
$disprice = sprintf("%.2f", $order['price'] - $inform['redpack']);
|
|
} else {
|
|
$disprice = $order['price'];
|
|
}
|
|
if ($disprice > 0 && empty($type['isdistri'])) {
|
|
$disorderid = Distribution::disCore($order['mid'], $disprice, $type['onedismoney'], $type['twodismoney'], 0, $order['id'], 'pocket', 1);
|
|
}
|
|
}
|
|
if(empty($disorderid)){
|
|
$disorderid = 0;
|
|
}
|
|
$data['disorderid'] = $disorderid;
|
|
$data['status'] = 3;
|
|
$data['paytime'] = time();
|
|
//$paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 3, 'delivery' => 4, 'wxapp' => 5);
|
|
$data['paytype'] = $params['type'];
|
|
if ($params['tag']['transaction_id']) $data['transid'] = $params['tag']['transaction_id'];
|
|
if($order['fightstatus'] == 3){
|
|
$data['issettlement'] = 1;
|
|
}
|
|
$res = pdo_update('wlmerchant_order', $data, array('id' => $order['id']));
|
|
if ($res && $order['fightstatus'] != 3) {
|
|
Store::ordersettlement($order['id']);
|
|
}
|
|
if ($inform['endtime'] > time()) {
|
|
$endtime = $inform['endtime'] + $order['num'] * 24 * 3600;
|
|
} else {
|
|
$endtime = time() + $order['num'] * 24 * 3600;
|
|
}
|
|
$data = array(
|
|
'top' => 1,
|
|
'endtime' => $endtime
|
|
);
|
|
if ($inform['redpack'] > 0) {
|
|
$data['redpackstatus'] = 1;
|
|
}
|
|
pdo_update('wlmerchant_pocket_informations', $data, array('id' => $order['fkid']));
|
|
|
|
|
|
}
|
|
|
|
}
|
|
//异步支付结果回调 处理用户界面
|
|
static function payPocketshargeReturn($params) {
|
|
$res = $params['result'] == 'success' ? 1 : 0;
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('fkid'));
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',['id'=>$order['fkid']]);
|
|
if ($res) {
|
|
wl_message('支付成功', $url, 'success');
|
|
} else {
|
|
wl_message('您已支付该订单', $url, 'error');
|
|
}
|
|
|
|
}
|
|
static function payPocketfabushargeNotify($params) {
|
|
global $_W;
|
|
Util::wl_log('payResult_notify', PATH_PLUGIN . "pocket/data/", $params); //写入异步日志记录
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('id','uniacid','fightstatus','mid', 'num', 'price', 'orderno', 'fkid', 'aid', 'status'));
|
|
$_W['uniacid'] = $order['uniacid'];
|
|
$tiezi = pdo_get('wlmerchant_pocket_informations',array('id' => $order['fkid']),array('status','endtime','type','mid','aid'));
|
|
if ($order['id']) {
|
|
$inform = self::getInformations($order['fkid']);
|
|
if (empty($_W['aid'])) {
|
|
$_W['aid'] = $order['aid'];
|
|
}
|
|
$set = Setting::agentsetting_read('pocket');
|
|
$inf = array();
|
|
if($order['fightstatus'] == 1){
|
|
if($inform['status'] == 5){
|
|
if ($set['passstatus']) {
|
|
$inf['status'] = 0;
|
|
} else {
|
|
$inf['status'] = 1;
|
|
}
|
|
}
|
|
$type = pdo_get('wlmerchant_pocket_type',array('id' => $inform['type']),array('isdistri','onedismoney','twodismoney'));
|
|
$onedismoney = $type['onedismoney'];
|
|
$twodismoney = $type['twodismoney'];
|
|
if (p('distribution') && empty($type['isdistri'])) {
|
|
$disorderid = Distribution::disCore($order['mid'], $order['price'], $onedismoney, $twodismoney, 0, $order['id'], 'pocket', 1);
|
|
}
|
|
}else if($order['fightstatus'] == 2){
|
|
$day = $order['num'];
|
|
$inf['top'] = 1;
|
|
if($tiezi['endtime']>time()){
|
|
$inf['endtime'] = $tiezi['endtime'] + $day * 24 * 3600;
|
|
}else{
|
|
$inf['endtime'] = time() + $day * 24 * 3600;
|
|
}
|
|
$inf['refreshtime'] = time();
|
|
$onedismoney = 0;
|
|
$twodismoney = 0;
|
|
if (p('distribution')) {
|
|
$disorderid = Distribution::disCore($order['mid'], $order['price'],$onedismoney,$twodismoney,0,$order['id'],'pocket',1);
|
|
}
|
|
}else if($order['fightstatus'] == 3){
|
|
$inf['redpackstatus'] = 1;
|
|
$inf['redpack'] = $inf['sredpack'] = $order['price'];
|
|
$inf['package'] = $order['num'];
|
|
}else if($order['fightstatus'] == 4){
|
|
$inf['refreshtime'] = time();
|
|
$onedismoney = 0;
|
|
$twodismoney = 0;
|
|
if (p('distribution')) {
|
|
$disorderid = Distribution::disCore($order['mid'], $order['price'],$onedismoney,$twodismoney,0,$order['id'],'pocket',1);
|
|
}
|
|
}else if($order['fightstatus'] == 5){
|
|
$payinfo = [
|
|
'pocketid' => $order['fkid'],
|
|
'mid' => $order['mid'],
|
|
'createtime' => time()
|
|
];
|
|
pdo_insert(PDO_NAME . 'pocket_payvideo', $payinfo);
|
|
}else if($order['fightstatus'] == 6){
|
|
$inf['fullchnnel'] = 1;
|
|
}
|
|
pdo_update('wlmerchant_pocket_informations', $inf, array('id' => $order['fkid']));
|
|
if(empty($disorderid)){
|
|
$disorderid = 0;
|
|
}
|
|
$data = array(
|
|
'status' => 3,
|
|
'disorderid' => $disorderid,
|
|
'paytime' => time()
|
|
);
|
|
//$paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 3, 'delivery' => 4, 'wxapp' => 5);
|
|
$data['paytype'] = $params['type'];
|
|
if ($params['tag']['transaction_id']) $data['transid'] = $params['tag']['transaction_id'];
|
|
if($order['fightstatus'] == 3){
|
|
$data['issettlement'] = 1;
|
|
}
|
|
$res = pdo_update('wlmerchant_order', $data, array('id' => $order['id']));
|
|
if ($res && $order['fightstatus'] != 3) {
|
|
Store::ordersettlement($order['id']);
|
|
}
|
|
if($order['fightstatus'] == 1){
|
|
if ($inf['status']) {
|
|
self::examinenotice($order['fkid']);
|
|
} else {
|
|
self::examinenotice($order['fkid'], 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
static function payPocketfabushargeReturn($params) {
|
|
$res = $params['result'] == 'success' ? 1 : 0;
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('fkid'));
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',['id'=>$order['fkid']]);
|
|
if ($res) {
|
|
wl_message('支付成功', $url, 'success');
|
|
} else {
|
|
wl_message('您已支付该订单', $url, 'error');
|
|
}
|
|
|
|
}
|
|
static function payPocketredpackNotify($params) {
|
|
global $_W;
|
|
Util::wl_log('payResult_notify', PATH_PLUGIN . "pocket/data/", $params); //写入异步日志记录
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('id', 'mid', 'num', 'price','fightstatus','orderno', 'fkid', 'aid', 'status', 'package','uniacid'));
|
|
$_W['uniacid'] = $order['uniacid'];
|
|
if ($order['status'] == 0) {
|
|
$inform = self::getInformations($order['fkid']);
|
|
if (empty($_W['aid'])) {
|
|
$_W['aid'] = $order['aid'];
|
|
}
|
|
pdo_update('wlmerchant_pocket_informations', array('redpackstatus' => 1), array('id' => $order['fkid']));
|
|
$data = array('status' => 3, 'paytime' => time());
|
|
//$paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 3, 'delivery' => 4, 'wxapp' => 5);
|
|
$data['paytype'] = $params['type'];
|
|
if ($params['tag']['transaction_id']) {
|
|
$data['transid'] = $params['tag']['transaction_id'];
|
|
}
|
|
if($order['fightstatus'] == 3){
|
|
$data['issettlement'] = 1;
|
|
}
|
|
$res = pdo_update('wlmerchant_order', $data, array('id' => $order['id']));
|
|
if ($res && $order['fightstatus'] != 3) {
|
|
Store::ordersettlement($order['id']);
|
|
}
|
|
}
|
|
}
|
|
static function payPocketredpackReturn($params) {
|
|
$res = $params['result'] == 'success' ? 1 : 0;
|
|
$order = pdo_get('wlmerchant_order', array('orderno' => $params['tid']), array('fkid'));
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',['id'=>$order['fkid']]);
|
|
if ($res) {
|
|
wl_message('支付成功', $url, 'success');
|
|
} else {
|
|
wl_message('您已支付该订单', $url, 'error');
|
|
}
|
|
|
|
|
|
}
|
|
//获取所有帖子
|
|
static function getNumTiezi($select, $where, $order, $pindex, $psize, $ifpage) {
|
|
$goodsInfo = Util::getNumData($select, PDO_NAME . 'pocket_informations', $where, $order, $pindex, $psize, $ifpage);
|
|
return $goodsInfo;
|
|
}
|
|
//获取所有订单
|
|
static function getNumOrder($select, $where, $order, $pindex, $psize, $ifpage) {
|
|
$goodsInfo = Util::getNumData($select, PDO_NAME . 'order', $where, $order, $pindex, $psize, $ifpage);
|
|
return $goodsInfo;
|
|
}
|
|
static function commentnotice($commentid, $comment, $mid) {
|
|
global $_W;
|
|
$amid = pdo_getcolumn(PDO_NAME . 'pocket_informations', array('id' => $commentid), 'mid');
|
|
$openid = pdo_getcolumn(PDO_NAME . 'member', array('id' => $amid), 'openid');
|
|
$smnane = pdo_getcolumn(PDO_NAME . 'member', array('id' => $mid), 'nickname');
|
|
$msg = $smnane . '对您的帖子评论道:' . "\n";
|
|
$msg .= $comment . "\n";
|
|
$msg .= '快去看看吧!' . "\n";
|
|
|
|
$time = pdo_getcolumn(PDO_NAME."pocket_comment",['id'=>$commentid],'createtime');
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',['id'=>$commentid]);
|
|
$modelData = [
|
|
'first' => $smnane . '对您的帖子进行了评论',
|
|
'type' => '评论提醒' ,//业务类型
|
|
'content' => $comment,//业务内容
|
|
'status' => '等待回复' ,//处理结果
|
|
'time' => date("Y-m-d H:i:s",$time) ,//操作时间
|
|
'remark' => '快去看看吧!'
|
|
];
|
|
TempModel::sendInit('service',$amid,$modelData,$_W['source'],$url);
|
|
}
|
|
static function replaynotice($amid, $comment, $mid, $cid) {
|
|
global $_W;
|
|
$smnane = pdo_getcolumn(PDO_NAME . 'member', array('id' => $mid), 'nickname');
|
|
$tid = pdo_getcolumn(PDO_NAME . 'pocket_comment', array('id' => $cid), 'tid');
|
|
$replyData = [
|
|
'first' => '用户'.$smnane.'回复您的帖子',
|
|
'type' => '帖子回复' ,//业务类型
|
|
'content' => $comment,//业务内容
|
|
'status' => '已回复',//处理结果
|
|
'time' => date('Y-m-d H:i:s', time()),//操作时间
|
|
'remark' => '点击查看帖子'
|
|
];
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',array('id'=>$tid));
|
|
TempModel::sendInit('service',$amid,$replyData,$_W['source'],$url);
|
|
}
|
|
static function examinenotice($commentid, $flag = 0) {
|
|
global $_W;
|
|
$comment = pdo_get(PDO_NAME . 'pocket_informations', array('id' => $commentid), array('nickname', 'type', 'createtime'));
|
|
$typename = pdo_getcolumn(PDO_NAME . 'pocket_type', array('id' => $comment['type']), 'title');
|
|
//给代理商管理员发送模板消息通知
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',array('id'=>$commentid,'examine' => 1));
|
|
if(empty($_W['areaname'])){
|
|
$areaid = pdo_getcolumn(PDO_NAME.'oparea',array('aid'=>$_W['aid']),'areaid');
|
|
$_W['areaname'] = pdo_getcolumn(PDO_NAME.'area',array('id'=>$areaid),'name');
|
|
}
|
|
$first = '您好,用户['.$comment['nickname'].']在[' .$_W['areaname'].']发布了一个同城信息';//消息头部
|
|
$type = "帖子发布";//业务类型
|
|
$content = '帖子分类:'.$typename;//业务内容
|
|
$status = $flag ? '已发布' : '待审核';//处理结果
|
|
$remark = "请尽快处理!";//备注信息
|
|
$time = $comment['createtime'];//操作时间
|
|
News::noticeAgent('pocketfabu',$_W['aid'],$first,$type,$content,$status,$remark,$time,$url);
|
|
}
|
|
|
|
static function passnotice($informationsid) {
|
|
global $_W;
|
|
$informations = pdo_get('wlmerchant_pocket_informations', array('id' => $informationsid), array('mid', 'type', 'nickname', 'status', 'reason', 'createtime'));
|
|
$typename = pdo_getcolumn(PDO_NAME . 'pocket_type', array('id' => $informations['type']), 'title');
|
|
if ($informations['status']) {
|
|
$result = '已驳回';
|
|
$remark = '您发布的信息已被驳回,驳回原因是:' . $informations['reason'] . ',请您重新发布';
|
|
$url = h5_url('pages/subPages/myPost/myPost', array('status' => 2));
|
|
} else {
|
|
$result = '已通过';
|
|
$remark = '您发布的信息已通过审核,点击查看帖子';
|
|
$url = h5_url('pages/subPages/postDetails/postDetails',array('id'=>$informationsid));
|
|
}
|
|
$replyData = [
|
|
'first' => '您好,您发布的帖子已审核',
|
|
'type' => '帖子审核' ,//业务类型
|
|
'content' => '帖子分类:'.$typename,//业务内容
|
|
'status' => $result,//处理结果
|
|
'time' => date('Y-m-d H:i:s', time()),//操作时间
|
|
'remark' => $remark
|
|
];
|
|
TempModel::sendInit('service',$informations['mid'],$replyData,$_W['source'],$url);
|
|
}
|
|
//计划任务
|
|
static function doTask() {
|
|
global $_W;
|
|
//置顶时间过期,自动下线
|
|
$tops = pdo_getall('wlmerchant_pocket_informations', array('top' => 1));
|
|
foreach ($tops as $key => $v) {
|
|
if ($v['endtime'] < time()) {
|
|
pdo_update('wlmerchant_pocket_informations', array('top' => 0), array('id' => $v['id']));
|
|
}
|
|
}
|
|
//添加回复时间
|
|
$noreplytime = pdo_fetchall("SELECT createtime,id FROM ".tablename('wlmerchant_pocket_informations')."WHERE replytime = 0 LIMIT 20 ");
|
|
if(!empty($noreplytime)){
|
|
foreach($noreplytime as $time){
|
|
$colltime = pdo_getcolumn(PDO_NAME.'pocket_comment',array('tid'=>$time['id'],'status' => 1),'createtime');
|
|
$retime = pdo_getcolumn(PDO_NAME.'pocket_reply',array('tid'=>$time['id'],'status' => 1),'createtime');
|
|
$createtime = $time['createtime'];
|
|
$newtime = max($colltime,$retime,$createtime);
|
|
pdo_update('wlmerchant_pocket_informations',array('replytime' => $newtime),array('id' => $time['id']));
|
|
}
|
|
}
|
|
//删除未支付订单
|
|
// $config = Setting::agentsetting_read('pocket');
|
|
// if ($config['delete'] > 0) {
|
|
// $deletetime = time() - $config['delete'] * 3600;
|
|
// $tiezis = pdo_fetchall("SELECT id FROM " . tablename('wlmerchant_pocket_informations') . "WHERE uniacid = {$_W['uniacid']} AND status = 5 AND createtime < {$deletetime}");
|
|
// if ($tiezis) {
|
|
// foreach ($tiezis as $key => &$tie) {
|
|
// $res = pdo_delete('wlmerchant_order', array('fkid' => $tie['id'], 'plugin' => 'pocket'));
|
|
// if ($res) {
|
|
// pdo_delete('wlmerchant_pocket_informations', array('id' => $tie['id']));
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//重新统计回复帖子id
|
|
$replys = pdo_fetchall("SELECT cid,id FROM " . tablename('wlmerchant_pocket_reply') . "WHERE tid = 0 ORDER BY id DESC LIMIT 20");
|
|
if ($replys) {
|
|
foreach ($replys as $key => $va) {
|
|
$tid = pdo_getcolumn(PDO_NAME . 'pocket_comment', array('id' => $va['cid']), 'tid');
|
|
pdo_update('wlmerchant_pocket_reply', array('tid' => $tid), array('id' => $va['id']));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Comment: 判断是否为黑名单用户
|
|
* Author: zzw
|
|
* Date: 2019/8/22 10:30
|
|
* @param $id int 帖子id
|
|
* @return bool
|
|
*/
|
|
public static function is_black($id){
|
|
global $_W;
|
|
$is_black = pdo_get(PDO_NAME."pocket_blacklist" ,['mid'=>$_W['mid'],'inid'=>$id]);
|
|
if($is_black) return true;//是黑名单用户
|
|
else return false;//不是黑名单用户
|
|
}
|
|
/**
|
|
* Comment: 获取掌上信息评论信息
|
|
* Author: zzw
|
|
* Date: 2019/8/29 14:38
|
|
* @param $page
|
|
* @param $pageIndex
|
|
* @param $id
|
|
* @return array|bool
|
|
*/
|
|
public static function getComment($page,$pageIndex,$id){
|
|
global $_W;
|
|
$pageStart = $page * $pageIndex - $pageIndex;
|
|
#2、获取评论信息列表
|
|
$total_sql = "SELECT count(*) FROM "
|
|
.tablename(PDO_NAME."pocket_comment") ." as a JOIN ".tablename(PDO_NAME."member")
|
|
." as b ON a.mid = b.id WHERE a.tid = {$id} ";
|
|
$total_sql .= $_W['mid'] ? " AND (a.status = 1 or (a.status = 0 and a.mid = {$_W['mid']}))" : " AND a.status = 1";
|
|
$total = pdo_fetchcolumn($total_sql);
|
|
|
|
$list_sql = "SELECT a.id,a.content,a.mid,a.createtime,a.likenum,b.nickname,b.avatar,b.encodename FROM "
|
|
.tablename(PDO_NAME."pocket_comment") ." as a JOIN ".tablename(PDO_NAME."member")
|
|
." as b ON a.mid = b.id WHERE a.tid = {$id} ";
|
|
$list_sql .= $_W['mid'] ? " AND (a.status = 1 or (a.status = 0 and a.mid = {$_W['mid']}))" : " AND a.status = 1";
|
|
$list_sql .= " ORDER BY a.createtime DESC LIMIT {$pageStart},{$pageIndex}";
|
|
$list = pdo_fetchall($list_sql);
|
|
|
|
#3、获取回复信息
|
|
if(is_array($list) && count($list) > 0){
|
|
foreach($list as $key => &$val){
|
|
if (is_base64($val['content'])) $val['content'] = base64_decode($val['content']);
|
|
$val['createtime'] = date("Y-m-d H:i",$val['createtime']);
|
|
$likeids = unserialize($val['likeids']);
|
|
$val['is_fabulous'] = in_array($_W['mid'],$likeids) ?:false;
|
|
$val['nickname'] = base64_decode($val['encodename']);
|
|
|
|
$sql = "SELECT a.id,a.smid,a.createtime,b.nickname as reply_name,b.encodename as b_encodename,m.nickname as name,m.encodename as m_encodename,a.content FROM ".tablename(PDO_NAME."pocket_reply")
|
|
." as a JOIN ".tablename(PDO_NAME."member")
|
|
." as b ON a.smid = b.id JOIN ".tablename(PDO_NAME."member")
|
|
." as m ON a.amid = m.id WHERE a.tid = {$id} AND a.cid = {$val['id']} ";
|
|
$sql .= $_W['mid'] ? " AND (a.status = 1 or (a.status = 0 and a.smid = {$_W['mid']}))" : " AND a.status = 1";
|
|
$sql .= " ORDER BY a.createtime ASC ";
|
|
$val['list'] = pdo_fetchall($sql);
|
|
|
|
foreach ($val['list'] as $k => $v) {
|
|
if (is_base64($val['list'][$k]['content'])) $val['list'][$k]['content'] = base64_decode($val['list'][$k]['content']);
|
|
$val['list'][$k]['createtime'] = date("Y-m-d H:i",$v['createtime']);
|
|
$val['list'][$k]['name'] = base64_decode($v['m_encodename']);
|
|
$val['list'][$k]['reply_name'] = base64_decode($v['b_encodename']);
|
|
unset($val['list'][$k]['m_encodename'],$val['list'][$k]['b_encodename']);
|
|
}
|
|
unset($val['encodename']);
|
|
}
|
|
}
|
|
|
|
|
|
return ['total'=>$total,'list'=>$list];
|
|
}
|
|
/**
|
|
* Comment: 红包算法
|
|
* Author: zzw
|
|
* Date: 2019/8/29 17:03
|
|
* @param $balance float 红包余额
|
|
* @param $surplus float 剩余的包
|
|
* @return string float 返回一个红包中拥有的金额
|
|
*/
|
|
public static function redEnvelopeAlgorithm($balance, $surplus) {
|
|
if ($surplus > 1) {
|
|
//根据红包算法获取当前用户应该领取的红包
|
|
$total = 0;//循环获取的随机数的总和
|
|
$frequency = 5;//循环的次数
|
|
$maxMoney = 0;//随机数的最大值
|
|
//通过循环获取平均值 让红包的金额不会太大也不会太小
|
|
$meanValue = $balance / $surplus * 2;//在每个包的平均值浮动两倍中取随机值 保证每个红包的金额差距不大
|
|
for ($i = 0; $i < $frequency; $i++) {
|
|
$rand = mt_rand() / mt_getrandmax();
|
|
$value = sprintf("%0.2f", $rand * $meanValue);
|
|
$total += $value;
|
|
if ($value > $maxMoney) {
|
|
$maxMoney = $value;
|
|
}
|
|
}
|
|
//去掉最大值 让数字比较平均 出现领取红包的金额数量依次递减的情况减少
|
|
$total = sprintf("%0.2f", $total - $maxMoney);
|
|
//通过平均数 获取红包的具体金额
|
|
$money = sprintf("%0.2f", $total / 4);
|
|
//判断:当红包金额等于小于0或者等于大于余额时 从新获取红包金额
|
|
$currentBalance = $balance - $money;
|
|
$minBalance = 0.01 * ($surplus - 1);
|
|
if($money <= 0){
|
|
$money = 0.01;
|
|
}
|
|
if ($money > $balance || $currentBalance < $minBalance) {
|
|
self::redEnvelopeAlgorithm($balance, $surplus);
|
|
}
|
|
} else {
|
|
//只剩下一个包 则当前用户获得剩下的所有金额
|
|
$money = $balance;
|
|
}
|
|
return $money;
|
|
}
|
|
/**
|
|
* Comment: 红包领取列表
|
|
* Author: zzw
|
|
* Date: 2019/8/29 18:32
|
|
* @param $id
|
|
* @param int $page
|
|
* @param int $pageIndex
|
|
* @return mixed
|
|
*/
|
|
public static function getGetList($id,$page = 1,$pageIndex = 10){
|
|
global $_W,$_GPC;
|
|
$data['total'] = 0;
|
|
$data['list'] = [];
|
|
#1、获取开始查询的位置
|
|
$pageStart = $page * $pageIndex - $pageIndex;
|
|
#2、条件生成
|
|
$where = " WHERE a.uniacid = {$_W['uniacid']} AND a.pid = {$id} ORDER BY a.gettime DESC ";
|
|
#3、获取手气最佳领取的金额
|
|
$max = pdo_fetchcolumn( "SELECT MAX(money) FROM ".tablename(PDO_NAME."red_envelope")." as a ".$where);
|
|
if($max > 0){
|
|
#4、获取总数量
|
|
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename(PDO_NAME."red_envelope")
|
|
." as a LEFT JOIN ".tablename(PDO_NAME."member")
|
|
." as b ON a.mid = b.id ".$where);
|
|
$data['total'] = ceil($total / $pageIndex);//总页数
|
|
#5、获取红包基本信息
|
|
$info = pdo_get(PDO_NAME."pocket_informations",['id'=>$id],['package']);
|
|
$info['surplus'] = ($info['package'] - $total) > 0 ? ($info['package'] - $total) : 0;
|
|
$data['info'] = $info;//基本信息
|
|
#6、获取领取列表
|
|
$sql = "SELECT a.money,b.nickname,b.avatar,FROM_UNIXTIME(a.gettime,'%Y-%m-%d %H:%i:%S') as gettime,
|
|
CASE WHEN a.money = {$max} THEN 1
|
|
ELSE 0
|
|
END as is_optimum FROM ".tablename(PDO_NAME."red_envelope")
|
|
." as a LEFT JOIN ".tablename(PDO_NAME."member")
|
|
." as b ON a.mid = b.id ".$where." LIMIT {$pageStart},{$pageIndex}";
|
|
$data['list'] = pdo_fetchall($sql);//信息列表
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
/**
|
|
* Comment: 将数转为带单位的字符串
|
|
* Author: zzw
|
|
* Date: 2019/10/29 14:35
|
|
* @param int $num 要转换的数
|
|
* @param int $limit 转换限制,当数大于该限制时才会进行转换
|
|
* @param int $hierarchy 返回的层级(例如转换111111,限制10000。返回层级1时返回10万,2时返回10万1千,3时返回10万1千1百)
|
|
* @return string
|
|
*/
|
|
public static function rounding($num,$limit,$hierarchy = 1){
|
|
//定义基本信息
|
|
$content = [];
|
|
$lv_1 = 100000000;//亿
|
|
$lv_2 = 10000000;//千万
|
|
$lv_3 = 10000;//万
|
|
$lv_4 = 1000;//千
|
|
$lv_5 = 100;//百
|
|
$lv_6 = 10;//十
|
|
if($num > $limit){
|
|
# 亿
|
|
if($num > $lv_1 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_1).'亿';
|
|
$num = intval($num % $lv_1);
|
|
}
|
|
# 千万
|
|
if($num > $lv_2 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_2).'千万';
|
|
$num = intval($num % $lv_2);
|
|
}
|
|
# 万
|
|
if($num > $lv_3 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_3).'万';
|
|
$num = intval($num % $lv_3);
|
|
}
|
|
# 千
|
|
if($num > $lv_4 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_4).'千';
|
|
$num = intval($num % $lv_4);
|
|
}
|
|
# 百
|
|
if($num > $lv_5 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_5).'百';
|
|
$num = intval($num % $lv_5);
|
|
}
|
|
# 十
|
|
if($num > $lv_6 && $hierarchy > count($content)){
|
|
$content[] = floor($num / $lv_6).'十';
|
|
$num = intval($num % $lv_6);
|
|
}
|
|
# 个
|
|
if($num > 0 && $hierarchy > count($content)){
|
|
$content[] = $num;
|
|
}
|
|
}
|
|
|
|
return implode($content);
|
|
}
|
|
/**
|
|
* Comment: 发送评论信息模板消息通知
|
|
* Author: zzw
|
|
* Date: 2020/3/16 14:09
|
|
* @param int $id 帖子id
|
|
* @param int $cid 评论id
|
|
* @param int $source 渠道信息
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
public static function setModelInfo($id,$cid,$source = 1){
|
|
#1、基本信息获取
|
|
$sendMid = pdo_getcolumn(PDO_NAME."pocket_informations",['id'=>$id],'mid');//获取发帖人id
|
|
$comment = pdo_get(PDO_NAME."pocket_comment",['id'=>$cid],['mid','createtime']);//获取评论人id
|
|
$nickname = pdo_getcolumn(PDO_NAME."member",['id'=>$comment['mid']],'nickname');//获取评论人昵称
|
|
#2、发送模板消息通知用户
|
|
$modelData = [
|
|
'first' => '' ,
|
|
'type' => '评论提醒' ,//业务类型
|
|
'content' => '用户['.$nickname.']对您的帖子进行了评论!' ,//业务内容
|
|
'status' => '待回复' ,//处理结果
|
|
'time' => date("Y-m-d H:i:s",$comment['createtime']) ,//操作时间
|
|
'remark' => ''
|
|
];
|
|
$link = h5_url('pagesA/pictureTextDetails/pictureTextDetails',['id'=>$id]);
|
|
TempModel::sendInit('service',$sendMid,$modelData,$source,$link);
|
|
}
|
|
/**
|
|
* Comment: 发送回复信息模板消息通知
|
|
* Author: zzw
|
|
* Date: 2020/3/16 14:41
|
|
* @param int $tid 帖子id
|
|
* @param int $rid 回复信息id
|
|
* @param int $smid 回复人id(发布回复信息的用户的id)
|
|
* @param int $amid 被回复人id(接收回复信息的用户的id)
|
|
* @param int $source 渠道信息
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
public static function setReplyModelInfo($tid,$rid,$smid,$amid,$source = 1){
|
|
#1、基本信息获取
|
|
$nickname = pdo_getcolumn(PDO_NAME."member",['id'=>$smid],'nickname');//获取回复人昵称
|
|
$time = pdo_getcolumn(PDO_NAME."pocket_reply",['id'=>$rid],'createtime');//回复时间
|
|
#2、发送模板消息通知用户
|
|
$modelData = [
|
|
'first' => '您的评论被回复了' ,
|
|
'type' => '评论回复提醒' ,//业务类型
|
|
'content' => '用户['.$nickname.']对您的评论进行了回复!' ,//业务内容
|
|
'status' => '待回复' ,//处理结果
|
|
'time' => date("Y-m-d H:i:s",$time) ,//操作时间
|
|
'remark' => ''
|
|
];
|
|
$link = h5_url('pages/subPages/postDetails/postDetails',['id'=>$tid]);
|
|
TempModel::sendInit('service',$amid,$modelData,$source,$link);
|
|
}
|
|
}
|
|
|
|
|