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.
109 lines
3.2 KiB
109 lines
3.2 KiB
<?php
|
|
namespace apps\base\controllers;
|
|
|
|
abstract class PluginWechatController extends BaseController
|
|
{
|
|
protected $_data = array();
|
|
|
|
/**
|
|
* 数据显示返回
|
|
*/
|
|
abstract protected function show($fromusername, $info);
|
|
|
|
/**
|
|
* 积分赠送
|
|
*/
|
|
abstract protected function give_point($fromusername, $info);
|
|
|
|
/**
|
|
* 行为处理
|
|
*/
|
|
abstract protected function action();
|
|
|
|
/**
|
|
* 积分赠送处理
|
|
*/
|
|
public function do_point($fromusername, $info, $point_value)
|
|
{
|
|
$time = gmtime();
|
|
$user_id = model()->table('wechat_user')
|
|
->field('ect_uid')
|
|
->where(array('openid'=>$fromusername))
|
|
->one();
|
|
if($user_id){
|
|
// 增加积分
|
|
$point = 'rank_points = rank_points +' . intval($point_value);
|
|
$sql = "UPDATE {pre}users SET rank_points = rank_points + ".intval($point_value)." WHERE user_id = $user_id";
|
|
model()->query($sql);
|
|
// 积分记录
|
|
$data['user_id'] = $user_id;
|
|
$data['user_money'] = 0;
|
|
$data['frozen_money'] = 0;
|
|
$data['rank_points'] = $point_value;
|
|
$data['pay_points'] = 0;
|
|
$data['change_time'] = $time;
|
|
$data['change_desc'] = $info['name'] . '积分赠送';
|
|
$data['change_type'] = ACT_OTHER;
|
|
|
|
$log_id = model()->table('account_log')->data($data)->insert();
|
|
// 从表记录
|
|
$data1['log_id'] = $log_id;
|
|
$data1['openid'] = $fromusername;
|
|
$data1['keywords'] = $info['command'];
|
|
$data1['createtime'] = $time;
|
|
$log_id = model()->table('wechat_point')->data($data1)->insert();
|
|
}
|
|
|
|
}
|
|
|
|
public function plugin_display($tpl = '', $config = array())
|
|
{
|
|
$this->_data['config'] = $config;
|
|
L(require(ROOT_PATH . 'source/language/zh_cn/wechat.php'));
|
|
$this->_data['lang'] = array_change_key_case(L());
|
|
//插件视图目录
|
|
$this->assign($this->_data);
|
|
$tpl = 'plugins/wechat/'.$this->plugin_name.'/view/'.$tpl.C('TPL.TPL_SUFFIX');
|
|
$content = file_get_contents(ROOT_PATH . $tpl);
|
|
$content = str_replace('\\', '', $content);
|
|
$this->template_content = $this->display($content, true, false);
|
|
//layout目录
|
|
$tpl_l = 'source/apps/'.APP_NAME. '/views/wechat_layout';
|
|
|
|
$this->assign($this->_data);
|
|
return parent::display($tpl_l);
|
|
}
|
|
|
|
/**
|
|
* 中奖概率计算
|
|
*
|
|
* @param unknown $proArr
|
|
* @return Ambigous <string, unknown>
|
|
*/
|
|
function get_rand($proArr)
|
|
{
|
|
$result = '';
|
|
// 概率数组的总概率精度
|
|
$proSum = array_sum($proArr);
|
|
// 概率数组循环
|
|
foreach ($proArr as $key => $proCur) {
|
|
$randNum = mt_rand(1, $proSum);
|
|
if ($randNum <= $proCur) {
|
|
$result = $key;
|
|
break;
|
|
} else {
|
|
$proSum -= $proCur;
|
|
}
|
|
}
|
|
unset($proArr);
|
|
return $result;
|
|
}
|
|
|
|
public function __get($name) {
|
|
return isset($this->_data [$name]) ? $this->_data [$name] : NULL;
|
|
}
|
|
|
|
public function __set($name, $value) {
|
|
$this->_data [$name] = $value;
|
|
}
|
|
}
|
|
|