Merge branch 'fea#bobing2021_2' into dev
This commit is contained in:
@@ -268,6 +268,65 @@ class Hd extends CI_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 博饼入口
|
||||
*/
|
||||
public function bobing()
|
||||
{
|
||||
define('WXAPP_ITEMS', 1);
|
||||
//加载输入参数
|
||||
$this->input_param();
|
||||
$app_id = $this->input_param('app_id');
|
||||
!$app_id && $app_id = $this->input_param('vipcard_id');
|
||||
$version = $this->input_param('version');
|
||||
$sversion = $this->input_param('sversion');
|
||||
|
||||
$this->log_file = get_class($this) . "_{$app_id}.log";
|
||||
|
||||
//应用ID为空
|
||||
if (!$app_id) {
|
||||
debug_log("[fail]" . __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file);
|
||||
return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '请求丢失'));
|
||||
}
|
||||
//签名不正确
|
||||
if (!$this->vaild_sign()) {
|
||||
debug_log("[fail]" . __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:" . json_encode($this->inputs), $this->log_file);
|
||||
return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '非法请求'));
|
||||
}
|
||||
$app = self::$apps[$app_id];
|
||||
$class_name = ucfirst($this->uri->segment(3));
|
||||
if ($this->uri->segment(4)) {
|
||||
$method = $this->request . "_" . $this->uri->segment(4);
|
||||
} else {
|
||||
$method = $this->request;
|
||||
}
|
||||
//app定制ct
|
||||
$file_name = APPPATH . "controllers/wxapp/bobing/{$app}/{$class_name}.php";
|
||||
//ct不存在
|
||||
if (file_exists($file_name)) {
|
||||
require_once $file_name;
|
||||
} else {
|
||||
//app定制ct不存在,使用公共ct
|
||||
$file_name = APPPATH . "controllers/wxapp/bobing/{$class_name}.php";
|
||||
if (file_exists($file_name)) {
|
||||
require_once $file_name;
|
||||
} else {
|
||||
debug_log("[fail]" . __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:" . $app_id, $this->log_file);
|
||||
return $this->print_return($this->return_error(API_CODE_NONE, '非法请求'));
|
||||
}
|
||||
}
|
||||
try {
|
||||
$class = new $class_name($this->inputs, $app);
|
||||
$result = $class->$method($version, $sversion);
|
||||
if (!$result) {
|
||||
throw new Exception('', ERR_SYS_FAIL);
|
||||
}
|
||||
return $this->print_return($result);
|
||||
} catch (Exception $e) {
|
||||
return $this->print_return($this->return_error($e->getCode(), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试签名(开发环境)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Notes:博饼任务
|
||||
* Created on: 2021/8/20 17:15
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Bobing extends HD_Controller
|
||||
{
|
||||
|
||||
private $log_file;
|
||||
private $appConfig;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->log_file = 'bobing.log';
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
$this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit');
|
||||
$this->appConfig = $this->mdBobingUser->appConfig();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:设置每日中奖
|
||||
* Created on: 2021/8/27 17:20
|
||||
* Created by: dengbw
|
||||
* https://liche-api-dev.xiaoyu.com/plan/bobing/lottery
|
||||
* https://api.liche.cn/plan/bobing/lottery
|
||||
*/
|
||||
public function lottery()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$hour = date('H');
|
||||
if ($hour != '00' && !$params['sd']) {
|
||||
echo '[0]点过后才会开奖昨天的中奖用户[' . $hour . ']';
|
||||
return;
|
||||
}
|
||||
if ($this->appConfig['game_start_date'] > date('Y-m-d')) {
|
||||
echo '博饼未开始';
|
||||
return;
|
||||
}
|
||||
$date = date('Y-m-d', strtotime('+1 day'));
|
||||
if ($this->appConfig['game_end_date'] < $date) {
|
||||
echo '博饼已结束';
|
||||
return;
|
||||
}
|
||||
$date = date('Y-m-d', strtotime('-1 day'));//中奖用户
|
||||
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'bo_date' => $date, 'lottery' => 1);
|
||||
$re = $this->mdBobingUserCredit->get($where);
|
||||
if ($re) {
|
||||
echo '[' . $date . ']已执行过中奖了';
|
||||
return;
|
||||
}
|
||||
$where['lottery'] = 0;
|
||||
$where['uid not in(select uid from lc_bobing_user_credit where app_id = ' . $this->appConfig['app_id']
|
||||
. ' and act_key = ' . $this->appConfig['act_key'] . ' and lottery= 1)'] = null;
|
||||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', 1, $this->appConfig['lottery_nums'], 'id,uid,credit');
|
||||
if ($res_c) {//设置中奖用户
|
||||
$ids = implode(',', array_column($res_c, 'id'));//中奖用户
|
||||
$this->mdBobingUserCredit->update(array('lottery' => 1), array('id in (' . $ids . ')' => null));
|
||||
$lottery = json_encode($res_c, JSON_UNESCAPED_UNICODE);
|
||||
debug_log('lottery:' . $lottery, $this->log_file);
|
||||
echo json_encode($lottery, JSON_UNESCAPED_UNICODE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ class Plan extends CI_Controller
|
||||
|
||||
//执行失败的plan重跑
|
||||
$plan[] = array('url' => base_url(array('plan', 'plan', 'replan')), 'interval' => 1);
|
||||
$plan[] = array('url' => base_url(array('plan', 'bobing', 'lottery')), 'interval' => 30);
|
||||
|
||||
$this->plan = $plan;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
ini_set('display_errors', 'on');
|
||||
|
||||
Class Liche extends HD_Controller
|
||||
{
|
||||
static $app_id = 1;//小程序id
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$target_class = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
|
||||
$this->log_file = "wechat_{$target_class}.log";
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'index';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业微信接收事件
|
||||
* https://liche-api-dev.xiaoyu.com/wechat/liche/get_qymsg
|
||||
* https://api.liche.cn/wechat/liche/get_qymsg
|
||||
* https://open.work.weixin.qq.com/wwopen/devtool/interface?doc_id=14961 测试回调模式
|
||||
* Created on: 2021/5/7 17:23
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function get_qymsg()
|
||||
{
|
||||
$param = $this->input->get();
|
||||
debug_log('<br>--->qymsg_param:' . json_encode($param), $this->log_file);
|
||||
require_once(COMMPATH . '/third_party/WXqy/WXBizMsgCrypt.php');
|
||||
$encodingAesKey = "VISnPl8WvttxHkAhrENTnADEjeWBc7cvU8qiCj9jH4S";
|
||||
$token = "PMJbt5kIoE7LTf0kWkwTf";
|
||||
$corpId = "wwc2caba960d202087";
|
||||
|
||||
$sVerifyMsgSig = $param['msg_signature'];
|
||||
$sVerifyTimeStamp = $param['timestamp'];
|
||||
$sVerifyNonce = $param['nonce'];
|
||||
$sVerifyEchoStr = $param['echostr'];
|
||||
// 需要返回的明文
|
||||
$sEchoStr = "";
|
||||
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
|
||||
if ($sVerifyEchoStr) {//验证回调URL
|
||||
$errCode = $wxcpt->VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
|
||||
debug_log('qymsg_errCode:' . $errCode, $this->log_file);
|
||||
if ($errCode == 0) {
|
||||
// 验证URL成功,将sEchoStr返回
|
||||
debug_log('qymsg_sEchoStr:' . $sEchoStr . '&sEchoStrurldecode=' . urldecode($sEchoStr), $this->log_file);
|
||||
echo urldecode($sEchoStr);
|
||||
} else {
|
||||
echo $errCode;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
// $sVerifyMsgSig = '08eb02c5d7fefaa29e2bd6a63acb8dfcc902ccf4';
|
||||
// $sVerifyTimeStamp = '1620713245';
|
||||
// $sVerifyNonce = '1620719758';
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$sReqData = file_get_contents("php://input");
|
||||
//$sReqData = "<xml><ToUserName><![CDATA[wwecac3c2b60c31b1b]]></ToUserName><Encrypt><![CDATA[1zKOzPaVNdUO6ytHYfs1IDaNL3E8RKFmh7bjtyyOHraGnVBnSNCo5q/InAY+GJzh1lyhh7L/Ch94uKSu2nf+zvPiKSOZD3xKv2pgbWXLqOcYAv8pvCYatQJx40a4zEq5qk/Ue+Fmt0AeOGBHmi59Y397t3vyLtpNdcePLcUrbfYCmbHUSWAybaNMmCVW//YJYGFmVJOjKmudTjD7nG1Ok7mpDyw7oETCpP8FY91EqC0DNeF4D5G1/OV4Fh+GNl++/kPpOTxTlsMM0HkjqmWKVE3nXG7elWXVjjRrabURvyDzs7MBAkjw53I7dud5y6ao53oXEsvw9wD+utISca4iZqL+0/mjP+JUylZbQB74jya5kQHR/zN6FaxcxImWLRFWY16SC8losLjkwdDfhke+3BCoa7JavKAIzjOTlLvc0CCEGSQMen9At6ktVFJhPBMAmKO1hF0nrT044zia82PQQa9T6Z9lDck4qttFiW5817uZwweHZ5enjwDaeGf+I8Kq5I4/EAFq1UeYYkl+LBVtATMbAZGKu2VSrO75DgQYPW7tP7XE/A1Eamnyb+PAarvD2PxzSoEtIGv/tI/Jv4I/gw==]]></Encrypt><AgentID><![CDATA[2000003]]></AgentID></xml>";
|
||||
//$log = '---';
|
||||
//if (is_array($sReqData)) $log = print_r($sReqData, true);
|
||||
//debug_log('qymsg_sReqData:' . json_encode($log, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
$sMsg = ""; // 解析之后的明文
|
||||
$errCode = $wxcpt->DecryptMsg($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sReqData, $sMsg);
|
||||
debug_log('qymsg_errCode:' . $errCode, $this->log_file);
|
||||
if ($errCode == 0) {
|
||||
$this->load->model('app/app_wechatqy_model', 'mdWechatqy');
|
||||
$re_msg = (array)simplexml_load_string($sMsg, 'SimpleXMLElement', LIBXML_NOCDATA);//xml转json
|
||||
$ExternalUserID = $re_msg['ExternalUserID'];
|
||||
$ChangeType = $re_msg['ChangeType'];
|
||||
debug_log('qymsg_ChangeType:' . $ChangeType, $this->log_file);
|
||||
$this->load->library('wx_qyapi', array());
|
||||
if ($ChangeType == 'add_external_contact') {//添加企业客户事件
|
||||
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $ExternalUserID));
|
||||
//debug_log('qymsg_external_errcode:' . $re['errcode'] . '&external_userid=' . $re['external_contact']['external_userid'], $this->log_file);
|
||||
if ($re['errcode'] == 0) {
|
||||
$external_userid = $re['external_contact']['external_userid'];
|
||||
if ($external_userid) {
|
||||
$re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid, 'app_id' => self::$app_id));
|
||||
$jsondata['external_contact'] = $re['external_contact'] ? $re['external_contact'] : '';
|
||||
$jsondata['follow_user'] = $re['follow_user'] ? $re['follow_user'] : '';
|
||||
$tags_ary = $re['follow_user'][0]['tags'];
|
||||
$tags = '';
|
||||
if ($tags_ary && $tags_ary != '[]' && is_array($tags_ary)) {
|
||||
$tags = implode(',', array_column($tags_ary, 'tag_id'));
|
||||
}
|
||||
$addData = array(
|
||||
'app_id' => self::$app_id,
|
||||
'external_userid' => $re['external_contact']['external_userid'],
|
||||
'name' => $re['external_contact']['name'],
|
||||
'avatar' => $re['external_contact']['avatar'],
|
||||
'unionid' => $re['external_contact']['unionid'] ? $re['external_contact']['unionid'] : '',
|
||||
'userid' => $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '',
|
||||
'remark' => $re['follow_user'][0]['remark'] ? $re['follow_user'][0]['remark'] : '',
|
||||
'tags' => $tags,
|
||||
'c_time' => $re['follow_user'][0]['createtime'] ? $re['follow_user'][0]['createtime'] : time(),
|
||||
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
|
||||
'status' => 1,
|
||||
);
|
||||
if (!$re_qy) {
|
||||
$this->mdWechatqy->add($addData);
|
||||
} else {
|
||||
$this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
|
||||
}
|
||||
//修改企业微信审请通过
|
||||
$this->load->service("app/user_service", array("app_id" => self::$app_id));
|
||||
$re_u = $this->user_service->get(array('unionid' => $addData['unionid']));
|
||||
if ($re_u['id']) {
|
||||
$this->user_service->update(array('wxqy' => 1), array('id' => $re_u['id']));
|
||||
//添加企业微信加分
|
||||
$this->load->library('bobing/bo');
|
||||
$this->bo->uid = $re_u['id'];
|
||||
$result = $this->bo->wxqy_credit();
|
||||
debug_log('wxqy:' . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
}
|
||||
//debug_log('qymsg_addData:' . json_encode($addData, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
}
|
||||
}
|
||||
debug_log('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
} else if ($ChangeType == 'update') {//修改企业客户事件
|
||||
debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
// $re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $ExternalUserID));
|
||||
// debug_log('qymsg_external_errcode:' . $re['errcode'] . '&external_userid=' . $re['external_contact']['external_userid'], $this->log_file);
|
||||
// debug_log('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
} else if ($ChangeType == 'del_follow_user') {//删除企业客户事件
|
||||
if ($ExternalUserID) {
|
||||
$re_qy = $this->mdWechatqy->get(array('external_userid' => $ExternalUserID, 'app_id' => self::$app_id));
|
||||
if ($re_qy) {
|
||||
$this->mdWechatqy->update(array('status' => -1), array('id' => $re_qy['id']));
|
||||
$this->load->service("app/user_service", array("app_id" => self::$app_id));
|
||||
$re_u = $this->user_service->get(array('unionid' => $re_qy['unionid']));
|
||||
if ($re_u['id']) {
|
||||
$this->user_service->update(array('wxqy' => -1), array('id' => $re_u['id']));
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
$this->mdBobingUser->update(array('wxqy' => -1), array('uid' => $re_u['id'], 'app_id' => self::$app_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//debug_log('qymsg_sMsg:' . json_encode($re_msg, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:添加企业客户事件
|
||||
* https://hd-api-dev.xiaoyu.com/wechat/xmcard/add_wechatqy
|
||||
* https://api.haodian.cn/wechat/xmcard/add_wechatqy
|
||||
* Created on: 2021/5/14 17:23
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function add_wechatqy()
|
||||
{
|
||||
$param = $this->input->get();
|
||||
$external_userid = $param['external_userid'];
|
||||
if (!$external_userid) {
|
||||
return false;
|
||||
}
|
||||
$this->load->model('app/app_wechatqy_model', 'mdWechatqy');
|
||||
$this->load->library('wx_qyapi', array());
|
||||
$re = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $external_userid));
|
||||
print_r('qymsg_external_errcode:' . $re['errcode'] . '=' . $re['external_contact']['external_userid']);
|
||||
if ($re['errcode'] == 0) {
|
||||
$external_userid = $re['external_contact']['external_userid'];
|
||||
if ($external_userid) {
|
||||
$re_qy = $this->mdWechatqy->get(array('external_userid' => $external_userid));
|
||||
$jsondata['external_contact'] = $re['external_contact'] ? $re['external_contact'] : '';
|
||||
$jsondata['follow_user'] = $re['follow_user'] ? $re['follow_user'] : '';
|
||||
$addData = array(
|
||||
'app_id' => self::$app_id,
|
||||
'external_userid' => $re['external_contact']['external_userid'],
|
||||
'name' => $re['external_contact']['name'],
|
||||
'avatar' => $re['external_contact']['avatar'],
|
||||
'unionid' => $re['external_contact']['unionid'] ? $re['external_contact']['unionid'] : '',
|
||||
'userid' => $re['follow_user'][0]['userid'] ? $re['follow_user'][0]['userid'] : '',
|
||||
'remark' => $re['follow_user'][0]['remark'] ? $re['follow_user'][0]['remark'] : '',
|
||||
'tags' => $re['follow_user'][0]['tags'] ? $re['follow_user'][0]['tags'] : '',
|
||||
'c_time' => $re['follow_user'][0]['createtime'] ? $re['follow_user'][0]['createtime'] : time(),
|
||||
'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE),
|
||||
'status' => 1,
|
||||
);
|
||||
if (!$re_qy) {
|
||||
$this->mdWechatqy->add($addData);
|
||||
} else {
|
||||
$this->mdWechatqy->update($addData, array('external_userid' => $external_userid));
|
||||
}
|
||||
print_r('qymsg_addData:' . json_encode($addData, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
print_r('qymsg_get:' . json_encode($re, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ defined('WXAPP_APP') OR exit('No direct script access allowed');
|
||||
* Desc: 支付接口
|
||||
* Date: 2021/06/29
|
||||
* Time: 19:47
|
||||
*/
|
||||
*/
|
||||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||||
class Payment extends Wxapp{
|
||||
|
||||
@@ -38,7 +38,7 @@ class Payment extends Wxapp{
|
||||
$row['total_price'] = 0.01;
|
||||
}
|
||||
|
||||
$this->config->load('wxpay');
|
||||
$this->config->load('wxpay');
|
||||
$wx_config = $this->config->item('default');
|
||||
$this->load->library('WechatPayV3');
|
||||
$params = [
|
||||
@@ -48,7 +48,7 @@ class Payment extends Wxapp{
|
||||
'wechatpayCertificate' => $wx_config['wechatpayCertificate'],
|
||||
];
|
||||
$WechatPayV3 = new WechatPayV3($params);
|
||||
$n_time = time();
|
||||
$n_time = time();
|
||||
$json = [
|
||||
'sp_appid' => $wx_config['appid'],
|
||||
'sp_mchid' => $wx_config['mchid'],
|
||||
@@ -81,4 +81,74 @@ class Payment extends Wxapp{
|
||||
return $result;
|
||||
}
|
||||
|
||||
//好店支付方式
|
||||
public function put_hd(){
|
||||
$sid = $this->input_param('sid');
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
$this->app_id = $this->mdBobingUser->appConfig()['act_key'];
|
||||
$row = $this->order_purchase_model->get(['sid'=>$sid,'app_id'=>$this->app_id,'app_uid'=>$this->session['uid']]);
|
||||
if(!$row){
|
||||
throw new Exception('订单不存在', API_CODE_FAIL);
|
||||
}
|
||||
if($row['status']>1){
|
||||
throw new Exception('订单已支付', API_CODE_FAIL);
|
||||
}
|
||||
if($row['total_price']>0){
|
||||
$url = http_host_com('api');
|
||||
$notify_url = $url."/wxapp/liche/wxnotify";
|
||||
$result = $this->pay($sid, $row['total_price'], $this->session['openid'], $row['item_title'], $notify_url);
|
||||
}else{
|
||||
$this->load->service('apporder/payhd_service', array('app_id' => $this->app_id));
|
||||
$result = $this->payhd_service->after_pay($sid);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付方法
|
||||
* @param $trade_no
|
||||
* @param $price
|
||||
* @param $openid
|
||||
* @param $body
|
||||
* @param $notify_url
|
||||
* @param $attach
|
||||
* @param $detail
|
||||
* @return bool|json数据,可直接填入js函数作为参数|mixed
|
||||
* @throws WxPayException
|
||||
*/
|
||||
private function pay($trade_no,$price,$openid,$body,$notify_url,$attach = '',$detail = ''){
|
||||
if(!$body){return false;}
|
||||
require_once APPPATH."third_party/WXconfig/liche_WxPay.Config.php";
|
||||
require_once APPPATH."third_party/WXpay/WxPay.Api.php";
|
||||
$config = new WxPayConfig();
|
||||
$wxpay = new WxPayUnifiedOrder();
|
||||
$wxpay->SetVersion('1.0');
|
||||
$wxpay->SetBody($body); //简单描述
|
||||
$attach && $wxpay->SetAttach($attach); //附加信息
|
||||
$wxpay->SetNotify_url($notify_url);
|
||||
$wxpay->SetOut_trade_no($trade_no); //订单号
|
||||
$wxpay->SetTotal_fee($price * 100); //支付价格
|
||||
$wxpay->SetTime_start(date("YmdHis")); //交易起始时间
|
||||
$redis = & load_cache('redis');
|
||||
$out_time_key = 'WX_TRADE_NO_OUT_'.$trade_no;
|
||||
$out_time = $redis->get($out_time_key);
|
||||
if(!$out_time){
|
||||
$out_time = date("YmdHis",time() + 29*60*60);
|
||||
$redis->save($out_time_key,$out_time,30*60*60);
|
||||
}
|
||||
$wxpay->SetTime_expire($out_time); //交易结束时间
|
||||
$wxpay->SetTrade_type("JSAPI"); //设置交易类型
|
||||
$wxpay->SetOpenid($openid); //openid
|
||||
$detail && $wxpay->SetDetail($detail);
|
||||
$return = WxPayApi::unifiedOrder($config, $wxpay); //统一支付
|
||||
if($return['result_code'] == 'SUCCESS') {
|
||||
$wxpay_api = new WxPayJsApiPay();
|
||||
$jsApiParameters = WxPayApi::GetJsApiParameters($return, $config, $wxpay_api);
|
||||
$jsApiParameters = json_decode($jsApiParameters, true);
|
||||
return $jsApiParameters;
|
||||
}else{
|
||||
throw new Exception($return['return_msg']?$return['return_msg'].$return['err_code_des']:$return['return_msg'], API_CODE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
||||
ini_set('display_errors', 'On');
|
||||
error_reporting(E_ERROR);
|
||||
|
||||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||||
|
||||
/**
|
||||
* Notes:博饼页
|
||||
* Created on: 2021/8/10 15:16
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Bobing extends Wxapp
|
||||
{
|
||||
private $uid;
|
||||
private $appConfig;
|
||||
|
||||
function __construct($inputs, $app_key)
|
||||
{
|
||||
parent::__construct($inputs, $app_key);
|
||||
$this->login_white = '';//
|
||||
$this->check_status = array();//用户状态校验
|
||||
$this->check_mobile = array();//需要手机号
|
||||
$this->check_headimg = array();//授权微信信息
|
||||
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
||||
$this->uid = $this->session['uid'];
|
||||
//$this->uid = 4;
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
$this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit');
|
||||
$this->load->model('bobing/bobing_logs_model', 'mdBobingLogs');
|
||||
$this->appConfig = $this->mdBobingUser->appConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:首页
|
||||
* Created on: 2020/8/10 11:47
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function get()
|
||||
{
|
||||
$cf_uid = intval($this->input_param('cf_uid'));//要助力id
|
||||
$this->uid == $cf_uid && $cf_uid = 0;
|
||||
//$cf_uid = 14;
|
||||
$where = array('act_key' => $this->appConfig['act_key'], 'app_id' => $this->app_id, 'uid' => $this->uid);
|
||||
$re_u = $this->mdBobingUser->get($where);
|
||||
if ($re_u) {
|
||||
if (!$cf_uid && $re_u['if_kz'] == 0) {//更新开桌
|
||||
$this->mdBobingUser->update(array("if_kz" => 1), $where);
|
||||
}
|
||||
} else {
|
||||
$if_kz = $cf_uid ? 0 : 1;
|
||||
$addUser = array_merge($where, array('if_kz' => $if_kz, 'c_time' => time()));
|
||||
$idu = $this->mdBobingUser->add($addUser);
|
||||
if (!$idu && $if_kz == 1) {
|
||||
throw new Hd_exception('开桌失败,请重试', API_CODE_FAIL);
|
||||
}
|
||||
}
|
||||
$share = array('title' => '狸车分享标题', 'content' => '<div>目前累计***幸运分,打败全闽南<span style="color:#fff10a">97.77%</span>的用户,</div>
|
||||
<div>继续邀请好友助力博饼,</div><div>冲刺购物卡、苹果手机、汽车大奖~</div><div>添加小狸微信,还可立即获得<span style="color:#fff10a">288</span>幸运分!</div>'
|
||||
, 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/share-tip.jpg', 'posters' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/posterbg.jpg');
|
||||
$result['valid_nums'] = $this->get_valid_nums($cf_uid);
|
||||
$result['top_title'] = $this->get_top_title($cf_uid);
|
||||
$result['users'] = $this->pr_users(true, array('cf_uid' => $cf_uid));
|
||||
$result['logs'] = $this->pr_logs($cf_uid);
|
||||
$result['share'] = $share;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:博一把
|
||||
* Created on: 2021/8/10 15:18
|
||||
* Created by: dengbw
|
||||
*/
|
||||
protected function put_bo()
|
||||
{
|
||||
$this->check_game_date();
|
||||
$cf_uid = intval($this->input_param('cf_uid'));//要助力id
|
||||
$this->uid == $cf_uid && $cf_uid = 0;
|
||||
//$cf_uid = 14;
|
||||
$this->load->library('bobing/bo');
|
||||
$this->bo->uid = $this->uid;
|
||||
$valid_nums = $this->get_valid_nums($cf_uid);//获取博饼剩余数
|
||||
$this->bo->valid_nums = $valid_nums['value'];
|
||||
$nickname = '';
|
||||
if ($cf_uid) {//助力博
|
||||
$this->bo->cf_uid = $cf_uid;
|
||||
$result = $this->bo->zl_bo();
|
||||
$reU = $this->app_user_model->get(array('id' => $this->uid));
|
||||
$reU['nickname'] && $nickname = $reU['nickname'];
|
||||
} else {//开桌博
|
||||
$result = $this->bo->kz_bo();
|
||||
}
|
||||
//status 1开桌博饼次数用完2助力数用完
|
||||
if ($result['status']) {//返回错误信息
|
||||
if ($result['status'] == API_CODE_FAIL) {
|
||||
throw new Hd_exception($result['content'], $result['status']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
$status = 0;
|
||||
$data['title'] = $result['title'];
|
||||
$data['content'] = $result['content'];
|
||||
//status 3抽到购车金4抽到红包
|
||||
$log = $cf_uid ? $nickname . "为桌长博到{$result['credit']}幸运分" : "桌长博到{$result['credit']}幸运分";
|
||||
if ($result['car_gold'] > 0) {
|
||||
$status = 3;
|
||||
$data['car_gold'] = $result['car_gold'];
|
||||
$log .= $cf_uid ? "和{$result['car_gold']}元购车金" : ",额外幸运地博到{$result['car_gold']}元购车金";
|
||||
} else if ($result['hong_bao'] > 0) {
|
||||
$status = 4;
|
||||
$data['hong_bao_url'] = http_host_com('home') . "/h5/hongbao?id={$result['lid']}&uid={$this->uid}";
|
||||
$log .= ",额外幸运地博到一个现金红包";
|
||||
}
|
||||
$data['log'] = $log;
|
||||
$data['status'] = $status;
|
||||
$valid_nums['value'] = $this->bo->valid_nums <= 0 ? 0 : $this->bo->valid_nums - 1;
|
||||
$data['dices'] = $result['dices'];
|
||||
$data['level'] = $result['level'];
|
||||
$data['bo_title'] = $result['level_name'] . ' + ' . $result['credit'];
|
||||
$data['valid_nums'] = $valid_nums;
|
||||
$data['top_title'] = $this->get_top_title($cf_uid);
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function get_users()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$this->data['users'] = $this->pr_users(false, $params);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes:获取博饼剩余数
|
||||
* Created on: 2021/8/17 10:24
|
||||
* Created by: dengbw
|
||||
* @param $cf_uid
|
||||
* @return array
|
||||
*/
|
||||
private function get_valid_nums($cf_uid)
|
||||
{
|
||||
if ($cf_uid) {
|
||||
$zl_nums = $this->mdBobingLogs->count(array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key']
|
||||
, 'cf_uid' => $this->uid, 'type' => 1));
|
||||
$zl_nums = intval($this->appConfig['zl_nums'] - $zl_nums);//剩下助力博饼数
|
||||
$valid_nums = array('title' => '剩余助力次数:', 'value' => $zl_nums <= 0 ? 0 : $zl_nums);
|
||||
} else {
|
||||
$kz_nums = $this->mdBobingLogs->count(array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key']
|
||||
, 'uid' => $this->uid, 'type' => 0));
|
||||
$kz_nums = intval($this->appConfig['kz_nums'] - $kz_nums);//剩下开桌博饼数
|
||||
$valid_nums = array('title' => '剩余博饼次数:', 'value' => $kz_nums <= 0 ? 0 : $kz_nums);
|
||||
}
|
||||
return $valid_nums;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:博饼顶部标题
|
||||
* Created on: 2021/8/17 10:14
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
private function get_top_title($cf_uid)
|
||||
{
|
||||
if ($cf_uid) {
|
||||
$reU = $this->app_user_model->get(array('id' => $cf_uid));
|
||||
$top_title = $reU['nickname'] ? $reU['nickname'] . '的桌子' : '未知用户的桌子';
|
||||
} else {
|
||||
$credit = $ranking = 0;
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'bo_date' => date('Y-m-d'));
|
||||
$re_c = $this->mdBobingUserCredit->get(array_merge($where, array('uid' => $this->uid)));
|
||||
$re_c && $credit = $re_c['credit'];
|
||||
$ranking = $this->mdBobingUserCredit->count(array_merge($where, array('credit>=' => $credit, 'uid<>' => $this->uid))) + 1;//排名
|
||||
$ranking > 100 && $ranking = '100名外';
|
||||
$top_title = "今日博饼分:{$credit} | 今日排名:{$ranking}";
|
||||
}
|
||||
return $top_title;
|
||||
}
|
||||
|
||||
private function pr_users($return_array = false, $params = array())
|
||||
{
|
||||
$page = $params['page'] ? intval($params['page']) : 1;
|
||||
$size = $params['size'] ? intval($params['size']) : 7;
|
||||
$cf_uid = intval($params['cf_uid']);
|
||||
//$cf_uid = 14;
|
||||
$list = array();
|
||||
if ($cf_uid) {
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'uid' => $cf_uid, 'type' => 1);
|
||||
} else {
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'uid' => $this->uid, 'type' => 1);
|
||||
}
|
||||
$total = $this->mdBobingLogs->count($where, 'distinct(cf_uid)');
|
||||
if ($total) {
|
||||
$res_u = $this->mdBobingLogs->select($where, 'id DESC', $page, $size, 'distinct(cf_uid)');
|
||||
if ($res_u) {
|
||||
$uids = implode(',', array_column($res_u, 'cf_uid'));
|
||||
$list = $this->app_user_model->select(array('id in (' . $uids . ')' => null), 'id DESC', 0, 0, 'nickname,headimg');
|
||||
}
|
||||
}
|
||||
if ($return_array) {
|
||||
return $list;
|
||||
}
|
||||
return array('list' => $list, 'total' => $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取博饼记录
|
||||
* Created on: 2021/8/19 11:16
|
||||
* Created by: dengbw
|
||||
* @param $cf_uid
|
||||
* @return array
|
||||
*/
|
||||
private function pr_logs($cf_uid)
|
||||
{
|
||||
//$cf_uid = 14;
|
||||
$logs = array();
|
||||
if ($cf_uid) {
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'uid' => $cf_uid);
|
||||
} else {
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'uid' => $this->uid);
|
||||
}
|
||||
$res_l = $this->mdBobingLogs->select($where, 'id DESC', 1, 7, 'credit,hong_bao,car_gold,type,uid,cf_uid');
|
||||
if ($res_l) {
|
||||
$uids = array_column($res_l, 'cf_uid');
|
||||
array_unique($uids);
|
||||
$users2 = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname');
|
||||
$nicknames = array();//微信昵称
|
||||
foreach ($users2 as $key => $value) {
|
||||
$nicknames[$value['id']] = $value['nickname'] ? $value['nickname'] : '****';
|
||||
}
|
||||
foreach ($res_l as $key => $value) {
|
||||
$content = '';
|
||||
if ($value['type'] == 0) {
|
||||
$content = "桌长博到{$value['credit']}幸运分";
|
||||
$value['car_gold'] > 0 && $content .= "和{$value['car_gold']}元购车金";
|
||||
} else if ($value['type'] == 1) {
|
||||
$content = $nicknames[$value['cf_uid']] . "为桌长博到{$value['credit']}幸运分";
|
||||
$value['car_gold'] > 0 && $content .= "和{$value['car_gold']}元购车金";
|
||||
$value['hong_bao'] > 0 && $content .= ",额外博到现金红包";
|
||||
} else if ($value['type'] == 2) {
|
||||
$content = "桌长加企业微信得到{$value['credit']}幸运分";
|
||||
}
|
||||
$logs[] = $content;
|
||||
}
|
||||
}
|
||||
return $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:检查博饼时间
|
||||
* Created on: 2021/8/27 14:25
|
||||
* Created by: dengbw
|
||||
* @throws Hd_exception
|
||||
*/
|
||||
protected function check_game_date()
|
||||
{
|
||||
if ($this->appConfig['game_start_date'] > date('Y-m-d')) {
|
||||
throw new Hd_exception('博饼未开始', API_CODE_FAIL);
|
||||
}
|
||||
if ($this->appConfig['game_end_date'] < date('Y-m-d')) {
|
||||
throw new Hd_exception('博饼已结束', API_CODE_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
||||
ini_set('display_errors', 'On');
|
||||
error_reporting(E_ERROR);
|
||||
|
||||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||||
|
||||
/**
|
||||
* Notes:博饼首页
|
||||
* Created on: 2021/8/10 15:16
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Home extends Wxapp
|
||||
{
|
||||
private $uid;
|
||||
private $appConfig;
|
||||
|
||||
function __construct($inputs, $app_key)
|
||||
{
|
||||
parent::__construct($inputs, $app_key);
|
||||
$this->login_white = '';//
|
||||
$this->check_status = array();//用户状态校验
|
||||
$this->check_mobile = array();//需要手机号
|
||||
$this->check_headimg = array();//授权微信信息
|
||||
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
||||
$this->uid = $this->session['uid'];
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
$this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit');
|
||||
$this->load->model('apporder/order_purchase_model', 'mdOrderPurchase');
|
||||
$this->appConfig = $this->mdBobingUser->appConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:首页
|
||||
* Created on: 2020/8/10 11:47
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function get()
|
||||
{
|
||||
$this->data['bodata'] = array('title' => "累计博饼次数", 'content' => $this->appConfig['content']
|
||||
, 'bo_nums' => $this->mdBobingUser->boNums($this->appConfig['act_key']));
|
||||
$lucky_car[] = array('title' => '雷丁芒果开回家', 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/index-tip.jpg'
|
||||
, 'url' => '/bobing/pages/game/index');
|
||||
$this->data['lucky_car'] = $lucky_car;
|
||||
$this->data['group'] = $this->appConfig['group'];
|
||||
$this->data['title'] = $this->appConfig['title'];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:排名
|
||||
* Created on: 2021/8/20 15:23
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
protected function get_ranking()
|
||||
{
|
||||
//日期列表-博饼
|
||||
$this->data['dates'] = $this->pr_dates(false);
|
||||
$this->data['rank'] = $this->pr_ranking_date(true);//今日幸运分
|
||||
$this->data['winners'] = $this->pr_winners(true);
|
||||
$this->data['title'] = $this->appConfig['title'];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:今日幸运分排名
|
||||
* Created on: 2021/8/20 15:23
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
public function get_ranking_date()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$this->data['rank'] = $this->pr_ranking_date(false, $params);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:总幸运分排名
|
||||
* Created on: 2021/8/20 15:24
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
public function get_ranking_all()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$this->data['rank'] = $this->pr_ranking_all(false, $params);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:中奖用户
|
||||
* Created on: 2021/8/20 15:38
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
public function get_winners()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
$this->data['winners'] = $this->pr_winners(false, $params);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
private function pr_ranking_date($return_array = false, $params = array())
|
||||
{
|
||||
$page = $params['page'] ? intval($params['page']) : 1;
|
||||
$size = $params['size'] ? intval($params['size']) : 100;
|
||||
$bo_date = date('Y-m-d');
|
||||
$list = array();
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'bo_date' => $bo_date);
|
||||
$total = $this->mdBobingUserCredit->count($where);
|
||||
if ($total) {
|
||||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', $page, $size, 'uid,credit');
|
||||
if ($res_c) {
|
||||
$users = array();//微信昵称
|
||||
$uids = array_column($res_c, 'uid');
|
||||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||||
foreach ($re_u as $key => $value) {
|
||||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||||
}
|
||||
foreach ($res_c as $key => $value) {
|
||||
$user = $users[$value['uid']];
|
||||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||||
, 'credit' => $value['credit'] . '分');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($return_array) {
|
||||
return $list;
|
||||
}
|
||||
return array('list' => $list, 'total' => $total);
|
||||
}
|
||||
|
||||
private function pr_ranking_all($return_array = false, $params = array())
|
||||
{
|
||||
$page = $params['page'] ? intval($params['page']) : 1;
|
||||
$size = $params['size'] ? intval($params['size']) : 100;
|
||||
$list = array();
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key']);
|
||||
$total = $this->mdBobingUser->count($where);
|
||||
if ($total) {
|
||||
$res_c = $this->mdBobingUser->select($where, 'credit desc,u_time asc', $page, $size, 'uid,credit');
|
||||
if ($res_c) {
|
||||
$users = array();//微信昵称
|
||||
$uids = array_column($res_c, 'uid');
|
||||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||||
foreach ($re_u as $key => $value) {
|
||||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||||
}
|
||||
foreach ($res_c as $key => $value) {
|
||||
$user = $users[$value['uid']];
|
||||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||||
, 'credit' => $value['credit'] . '分');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($return_array) {
|
||||
return $list;
|
||||
}
|
||||
return array('list' => $list, 'total' => $total);
|
||||
}
|
||||
|
||||
private function pr_winners($return_array = false, $params = array())
|
||||
{
|
||||
$dates = $this->pr_dates(false);
|
||||
$date_default = $dates ? $dates[0] : date('Y-m-d');
|
||||
$bo_date = $params['date'] ? $params['date'] : $date_default;
|
||||
//$bo_date = '2021-08-19';
|
||||
$list = array();
|
||||
$where = array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'bo_date' => $bo_date, 'lottery' => 1);
|
||||
$total = $this->mdBobingUserCredit->count($where);
|
||||
if ($total) {
|
||||
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', 1, 10, 'uid,credit');
|
||||
if ($res_c) {
|
||||
$users = array();//微信昵称
|
||||
$uids = array_column($res_c, 'uid');
|
||||
$re_u = $this->app_user_model->select(array('id in (' . implode(',', $uids) . ')' => null), 'id DESC', 0, 0, 'id,nickname,headimg');
|
||||
foreach ($re_u as $key => $value) {
|
||||
$users[$value['id']] = array('nickname' => $value['nickname'], 'headimg' => $value['headimg']);
|
||||
}
|
||||
foreach ($res_c as $key => $value) {
|
||||
$user = $users[$value['uid']];
|
||||
$list[] = array('id' => $key + 1, 'nickname' => $user['nickname'], 'headimg' => $user['headimg']
|
||||
, 'credit' => $value['credit'] . '分');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($return_array) {
|
||||
return $list;
|
||||
}
|
||||
return array('list' => $list, 'total' => $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:规则
|
||||
* Created on: 2021/8/19 17:08
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
protected function get_rule()
|
||||
{
|
||||
$this->data['rule'] = $this->appConfig['rule'];
|
||||
$this->data['title'] = $this->appConfig['title'];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:礼品
|
||||
* Created on: 2021/8/19 17:45
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
protected function get_gift()
|
||||
{
|
||||
$this->data['gift'] = $this->appConfig['gift'];
|
||||
$this->data['title'] = $this->appConfig['title'];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:我的
|
||||
* Created on: 2021/8/27 10:29
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
protected function get_mine()
|
||||
{
|
||||
$credit = $car_gold = 0;
|
||||
$re_u = $this->mdBobingUser->get(array('app_id' => $this->app_id, 'act_key' => $this->appConfig['act_key'], 'uid' => $this->uid));
|
||||
if ($re_u) {
|
||||
$credit = $re_u['credit'];
|
||||
$car_gold = $re_u['car_gold'] + $re_u['buy_car_gold'];
|
||||
}
|
||||
$img_url = 'https://qs.haodian.cn/wechat_app/liche';
|
||||
$menulist[] = array('title' => '9.9抢500购车金', 'url' => 'buy_car_gold', 'img' => $img_url . '/bobing/2021/icon-mine-1.png');
|
||||
$menulist[] = array('title' => '预约试驾', 'url' => '/pages/buyCar/detail/index?id=13', 'img' => $img_url . '/bobing/2021/icon-mine-4.png');
|
||||
$menulist[] = array('title' => '我的海报', 'url' => '/bobing/pages/game/invite/index', 'img' => $img_url . '/bobing/2021/icon-mine-2.png');
|
||||
$menulist[] = array('title' => '联系客服', 'url' => '/pages/', 'img' => $img_url . '/bobing/2021/icon-mine-3.png');
|
||||
$menulist[] = array('title' => '狸车首页', 'url' => 'lc://switchTab/pages/index/index', 'img' => $img_url . '/bobing/2021/icon-mine-5.png');
|
||||
$data = array(
|
||||
"title" => $this->appConfig['title'],
|
||||
"credit" => array('title' => '幸运分', 'value' => $credit),
|
||||
"car_gold" => array('title' => '购车金', 'value' => $car_gold),
|
||||
"tips" => '<div>您已打败全闽南<span style="color:#dd4223;">97.77%</span>的用户</div><div>继续邀请好友助力博饼,冲刺大奖吧~</div>',
|
||||
"menulist" => $menulist
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:购买购车金
|
||||
* Created on: 2021/8/31 9:57
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
protected function get_buy_car_gold()
|
||||
{
|
||||
$where = array('app_id' => $this->appConfig['act_key'], 'app_uid' => $this->uid, 'item_id' => 1);
|
||||
$re_p = $this->mdOrderPurchase->get($where);
|
||||
if (!$re_p) {
|
||||
$sid = create_order_no(350200);
|
||||
$add_data = [
|
||||
'app_id' => $this->appConfig['act_key'],
|
||||
'app_uid' => $this->uid,
|
||||
'sid' => $sid,
|
||||
'item_id' => 1,
|
||||
'item_title' => '9.9抢500购车金',
|
||||
'item_num' => 1,
|
||||
'type' => 3,
|
||||
'item_price' => 9.9,
|
||||
'total_price' => 0.01,//9.9
|
||||
'uname' => $this->session['nickname'],
|
||||
'mobile' => $this->session['mobile'],
|
||||
'payway' => 1,
|
||||
'status' => 1,
|
||||
'status_detail' => 11,
|
||||
'c_time' => time()
|
||||
];
|
||||
$order_id = $this->mdOrderPurchase->add($add_data);
|
||||
$date = array('sid' => $sid, 'tips' => $order_id ? '' : '购买失败请重试');
|
||||
} else {
|
||||
$date = array('sid' => $re_p['sid'], 'tips' => $re_p['status'] == 2 ? '您已经购买了' : '');
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取二维码
|
||||
* Created on: 2021/8/27 16:34
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
* @throws Hd_Exception
|
||||
*/
|
||||
protected function get_qrcode()
|
||||
{
|
||||
$scene = $this->input_param('scene');
|
||||
$page = $this->input_param('page');
|
||||
$width = $this->input_param('width');
|
||||
$fig = $this->input_param('fig');
|
||||
if (0 == strlen($scene)) {
|
||||
throw new Hd_Exception('二维码参数必填', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
return $this->qrcode($scene, $page, $width, $fig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取图片二维码
|
||||
* Created on: 2021/8/27 16:33
|
||||
* Created by: dengbw
|
||||
* @param $scene
|
||||
* @param string $page
|
||||
* @param int $width
|
||||
* @param string $fig
|
||||
* @return array
|
||||
* @throws Hd_Exception
|
||||
*/
|
||||
private function qrcode($scene, $page = '', $width = 0, $fig = 'liche')
|
||||
{
|
||||
$path = "{$page}?{$scene}";
|
||||
$width && $path .= "{$width}";
|
||||
if ($fig) {
|
||||
$this->config->load('app', true, true);
|
||||
$configs = $this->config->item('app');
|
||||
$config = $configs[$fig];
|
||||
if (!$config) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": config not exist;fig={$fig}", $this->log_file);
|
||||
throw new Hd_Exception('请求的小程序不存在', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
$wxconfig = $config['wx'];
|
||||
} else {
|
||||
$wxconfig = $this->wx_config;
|
||||
$fig = $this->app_key;
|
||||
}
|
||||
$filename = "{$fig}/" . substr(md5($path), 8, 16);
|
||||
$this->load->library('Hdwechat');
|
||||
$hdwechat = new Hdwechat($wxconfig);
|
||||
$ret = $hdwechat->qrcode($filename, $scene, $page, $width);
|
||||
if (!$ret) {
|
||||
throw new Hd_Exception('生成失败,稍后重试', API_CODE_FAIL);
|
||||
}
|
||||
$data = array('url' => $ret['url']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//日期列表
|
||||
private function pr_dates($include_today = true)
|
||||
{
|
||||
$ttl = 60;
|
||||
$mc = &load_cache();
|
||||
$key_dates = 'dates' . $this->appConfig['act_key'] . '_' . date('Y-m-d') . '_' . $include_today;
|
||||
$dates = $mc->get($key_dates);
|
||||
if (!$dates) {
|
||||
$date_end = $include_today ? strtotime(date('Y-m-d')) : strtotime(date('Y-m-d', strtotime('-1 day')));
|
||||
$game_start_date = strtotime($this->appConfig['game_start_date']);
|
||||
$game_start_end = strtotime($this->appConfig['game_end_date']);
|
||||
$dates = array();
|
||||
$do = true;
|
||||
while ($do) {
|
||||
if ($game_start_date <= $date_end && $game_start_date <= $game_start_end) {
|
||||
$dates[] = date('Y-m-d', $game_start_date);
|
||||
$game_start_date = strtotime('+1 day', $game_start_date);
|
||||
} else {
|
||||
$do = false;
|
||||
}
|
||||
}
|
||||
$dates = array_reverse($dates);
|
||||
$mc->save($key_dates, $dates, $ttl);
|
||||
}
|
||||
return $dates;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,74 +6,73 @@
|
||||
* Time: 20:17
|
||||
*/
|
||||
//微信支付回调
|
||||
require_once APPPATH."third_party/WXpay/WxPay.Api.php";
|
||||
require_once APPPATH . "third_party/WXpay/WxPay.Api.php";
|
||||
require_once APPPATH . "third_party/WXconfig/liche_WxPay.Config.php";
|
||||
|
||||
class Wxnotify extends CI_Controller{
|
||||
class Wxnotify extends CI_Controller
|
||||
{
|
||||
private $log_file = 'liche_pay.log';
|
||||
private $log_dir = "wxapp_liche_pay";
|
||||
private $app_id = 1;
|
||||
private $notify;
|
||||
public function __construct(){
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('app/app_wxpaylog_model', 'wxpaylog_model');
|
||||
$this->load->model('apporder/order_purchase_model','purchase_model');
|
||||
$input = file_get_contents("php://input");
|
||||
debug_log("[info] ". __FUNCTION__ . "# input:" . $input, $this->log_file);
|
||||
//xml 转数组
|
||||
$obj = simplexml_load_string($input,"SimpleXMLElement", LIBXML_NOCDATA);
|
||||
$obj_array = json_decode(json_encode($obj),true);
|
||||
$mch_id = $obj_array['mch_id'];
|
||||
$config_file = APPPATH."third_party/WXconfig/liche_WxPay.Config.php";
|
||||
if(!file_exists($config_file)){
|
||||
debug_log("[error] ". __FUNCTION__ . ":商户配置文件不存在", $this->log_file);
|
||||
exit();
|
||||
}
|
||||
try{
|
||||
try {
|
||||
//如果返回成功则验证签名
|
||||
$config = new WxPayConfig();
|
||||
$wxpay = new WxPayNotifyResults();
|
||||
$input = file_get_contents("php://input");
|
||||
$result = WxPayNotifyResults::Init($config, $input);
|
||||
$this->notify = $result->GetValues();
|
||||
}catch (WxPayException $e){
|
||||
debug_log("[error] ". __FUNCTION__ . ":".$e->getMessage(), $this->log_file);
|
||||
debug_log("[info] " . __FUNCTION__ . "# notify:" . json_encode($this->notify, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
$this->load->model('app/app_wxpaylog_model', 'wxpaylog_model');
|
||||
$this->load->model('apporder/order_purchase_model', 'purchase_model');
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
} catch (WxPayException $e) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":" . $e->getMessage(), $this->log_file);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
//支付回调
|
||||
public function index(){
|
||||
public function index()
|
||||
{
|
||||
$sid = $this->notify['out_trade_no'];
|
||||
if($sid&&$this->notify['out_trade_no']){
|
||||
debug_log("[start] ". __FUNCTION__ . ": out_trade_no:".$this->notify['out_trade_no'], $this->log_file);
|
||||
$order = $this->purchase_model->get(array('sid'=>$sid,'app_id'=>$this->app_id));
|
||||
if(!$order){
|
||||
debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file);
|
||||
if ($sid && $this->notify['out_trade_no']) {
|
||||
debug_log("[start] " . __FUNCTION__ . ": out_trade_no:" . $this->notify['out_trade_no'], $this->log_file);
|
||||
$this->app_id = $this->mdBobingUser->appConfig()['act_key'];
|
||||
$order = $this->purchase_model->get(array('sid' => $sid, 'app_id' => $this->app_id));
|
||||
if (!$order) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file);
|
||||
}
|
||||
//执行失败
|
||||
$add = array(
|
||||
'app_id' => $this->app_id,
|
||||
'sid' => $sid?$sid:0,
|
||||
'trade_no' => $this->notify['transaction_id'],
|
||||
'notify_param' => json_encode($this->notify,JSON_UNESCAPED_UNICODE)
|
||||
'sid' => $sid ? $sid : 0,
|
||||
'trade_no' => $this->notify['transaction_id'],
|
||||
'notify_param' => json_encode($this->notify, JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
$ret = $this->wxpaylog_model->add($add);
|
||||
if(!$ret){
|
||||
debug_log("[error] ". __FUNCTION__ . ": sql:".$this->wxpaylog_model->db->last_query(), $this->log_file);
|
||||
if (!$ret) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": sql:" . $this->wxpaylog_model->db->last_query(), $this->log_file);
|
||||
}
|
||||
if($this->notify['result_code'] != 'SUCCESS'){ //支付失败
|
||||
debug_log("[error] ". __FUNCTION__ . ":支付失败,sid={$sid},app_id=", $this->log_file);
|
||||
}else{ //支付成功
|
||||
$this->load->service('apporder/payment_service', array('app_id' => $this->app_id));
|
||||
$result = $this->payment_service->after_pay($sid,$this->notify['cash_fee']/100);
|
||||
if($result['code']){
|
||||
debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file);
|
||||
}else{
|
||||
debug_log("[error] ". __FUNCTION__ . ":".$result['msg'], $this->log_file);
|
||||
}
|
||||
if ($this->notify['result_code'] != 'SUCCESS') { //支付失败
|
||||
debug_log("[error] " . __FUNCTION__ . ":支付失败,sid={$sid},app_id=", $this->log_file);
|
||||
} else { //支付成功
|
||||
$this->load->service('apporder/payhd_service', array('app_id' => $this->app_id));
|
||||
$result = $this->payhd_service->after_pay($sid, $this->notify['cash_fee'] / 100);
|
||||
if ($result['code']) {
|
||||
debug_log("[success] " . __FUNCTION__ . ":操作成功", $this->log_file);
|
||||
} else {
|
||||
debug_log("[error] " . __FUNCTION__ . ":" . $result['msg'], $this->log_file);
|
||||
}
|
||||
}
|
||||
debug_log("[finish] ". __FUNCTION__ . ": out_trade_no:".$this->notify['out_trade_no'], $this->log_file);
|
||||
}else{
|
||||
debug_log("[finish] ". __FUNCTION__ . ": 参数错误:".json_encode($this->notify,JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
debug_log("[finish] " . __FUNCTION__ . ": out_trade_no:" . $this->notify['out_trade_no'], $this->log_file);
|
||||
} else {
|
||||
debug_log("[finish] " . __FUNCTION__ . ": 参数错误:" . json_encode($this->notify, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
}
|
||||
echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Base
|
||||
{
|
||||
public $ifcache = true;
|
||||
|
||||
public function __get($property_name)
|
||||
{
|
||||
$func = 'get_'.$property_name;
|
||||
if ($this->$property_name){
|
||||
return $this->$property_name;
|
||||
} elseif(method_exists($this, $func))
|
||||
{
|
||||
return $this->$property_name = $this->$func();
|
||||
} else {
|
||||
return $this->$property_name = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ci()
|
||||
{
|
||||
$ci = &get_instance();
|
||||
return $ci;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* Notes:博
|
||||
* Created on: 2021/8/10 17:41
|
||||
* Created by: dengbw
|
||||
*/
|
||||
require_once APPPATH . 'libraries/bobing/Base.class.php';
|
||||
|
||||
class Bo extends Base
|
||||
{
|
||||
private $appConfig = array();
|
||||
private $carGoldAry = array(1 => '100', 2 => '100', 3 => '150', 4 => '100', 5 => '150', 6 => '100', 7 => '150');
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ci->load->model('bobing/bobing_user_model');
|
||||
$this->ci->load->model('bobing/bobing_user_credit_model');
|
||||
$this->ci->load->model('bobing/bobing_logs_model');
|
||||
$this->appConfig = $this->ci->bobing_user_model->appConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:开桌博饼
|
||||
* Created on: 2021/8/10 17:41
|
||||
* Created by: dengbw
|
||||
* @return mixed
|
||||
*/
|
||||
public function kz_bo()
|
||||
{
|
||||
if ($this->valid_nums <= 0) {
|
||||
return array('status' => 1, 'title' => '邀请好友', 'content' => '<div>您的博饼次数已用完啦</div><div>立即邀请好友助力博饼,</div><div>冲刺购物卡、苹果手机、汽车大奖</div>');
|
||||
}
|
||||
$mc = &load_cache();
|
||||
$key = 'LiChe_bobing_' . $this->act_key . $this->app_id . $this->uid;
|
||||
$timeout = $mc->get($key);
|
||||
if ($timeout && (time() - $timeout) < 2) {
|
||||
return array('status' => API_CODE_FAIL, 'content' => '您操作太快了,速度越慢越能博到状元,刷新页面再试试');
|
||||
}
|
||||
$mc->save($key, time());
|
||||
$this->ci->load->library('bobing/dice');
|
||||
$this->ci->dice->init();
|
||||
$size_result = $this->ci->dice->getResultArr();
|
||||
$level = $this->ci->dice->getResultLevel();
|
||||
$data['app_id'] = $this->appConfig['app_id'];
|
||||
$data['act_key'] = $this->appConfig['act_key'];
|
||||
$data['uid'] = $this->uid;
|
||||
$data['dices'] = implode(',', $size_result);
|
||||
$data['level'] = $level;
|
||||
$data['credit'] = $this->ci->dice->getcredit($level);
|
||||
$data['bo_date'] = date('Y-m-d');
|
||||
$data['ip'] = get_client_ip();
|
||||
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$data['type'] = 0;
|
||||
$data['c_time'] = time();
|
||||
$content = $title = '';
|
||||
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $this->uid));
|
||||
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
|
||||
if ($this->appConfig['ratio_car_gold'] && $this->appConfig['ratio_car_gold'] >= rand(1, 100)) {//购车金概率
|
||||
$car_gold = $this->carGoldAry[rand(1, 7)];
|
||||
if (($car_gold + $re_u['car_gold']) > $this->appConfig['max_car_gold']) {//如果购车金大于设定值,那么本次增加到最大值
|
||||
$car_gold = $this->appConfig['max_car_gold'] - $re_u['car_gold'];
|
||||
}
|
||||
$data['car_gold'] = $car_gold;
|
||||
$content = '您博到购车金' . $car_gold . '元';
|
||||
$title = '恭喜您';
|
||||
}
|
||||
}
|
||||
$re_l = $this->add_log($data);
|
||||
if ($re_l['status'] == 1) {
|
||||
return array('status' => API_CODE_FAIL, 'content' => '博饼日志添加失败');
|
||||
}
|
||||
$data['level_name'] = $this->ci->dice->getResultName();
|
||||
$data['status'] = 0;
|
||||
$data['lid'] = $re_l['lid'];
|
||||
$data['title'] = $title;
|
||||
$data['content'] = $content;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:助力博饼
|
||||
* Created on: 2021/8/12 17:13
|
||||
* Created by: dengbw
|
||||
* @return mixed
|
||||
*/
|
||||
public function zl_bo()
|
||||
{
|
||||
$data['app_id'] = $this->appConfig['app_id'];
|
||||
$data['act_key'] = $this->appConfig['act_key'];
|
||||
if ($this->valid_nums <= 0) {
|
||||
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $this->uid));
|
||||
$credit = intval($re_u['credit']);
|
||||
return array('status' => 2, 'title' => '立即开桌', 'content' => '<div>您已获得' . $credit . '积分,</div><div>立即开桌获得更多幸运分,</div><div>冲刺购物卡、苹果手机、汽车大奖</div>');
|
||||
}
|
||||
$mc = &load_cache();
|
||||
$key = 'LiChe_bobing_' . $this->act_key . $this->app_id . $this->uid;
|
||||
$timeout = $mc->get($key);
|
||||
if ($timeout && (time() - $timeout) < 2) {
|
||||
return array('status' => API_CODE_FAIL, 'msg' => '您操作太快了,速度越慢越能博到状元,刷新页面再试试');
|
||||
}
|
||||
$mc->save($key, time());
|
||||
$this->ci->load->library('bobing/dice');
|
||||
$this->ci->dice->init();
|
||||
$size_result = $this->ci->dice->getResultArr();
|
||||
$level = $this->ci->dice->getResultLevel();
|
||||
|
||||
$data['uid'] = $this->cf_uid;
|
||||
$data['cf_uid'] = $this->uid;
|
||||
$data['dices'] = implode(',', $size_result);
|
||||
$data['level'] = $level;
|
||||
$data['credit'] = $this->ci->dice->getcredit($level);
|
||||
$data['bo_date'] = date('Y-m-d');
|
||||
$data['ip'] = get_client_ip();
|
||||
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$data['type'] = 1;
|
||||
$content = $title = '';
|
||||
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $data['uid']));
|
||||
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
|
||||
if ($this->appConfig['ratio_car_gold'] && $this->appConfig['ratio_car_gold'] >= rand(1, 100)) {//购车金概率
|
||||
$car_gold = $this->carGoldAry[rand(1, 7)];
|
||||
if (($car_gold + $re_u['car_gold']) > $this->appConfig['max_car_gold']) {//如果购车金大于设定值,那么本次增加到最大值
|
||||
$car_gold = $this->appConfig['max_car_gold'] - $re_u['car_gold'];
|
||||
}
|
||||
$data['car_gold'] = $car_gold;
|
||||
$content = '为桌长博到购车金' . $car_gold . '元';
|
||||
$title = '恭喜您';
|
||||
}
|
||||
}
|
||||
$hong_bao_day = $this->ci->bobing_user_model->hongBaoDay($data['act_key']);
|
||||
if (!$data['car_gold'] && ($hong_bao_day < $this->appConfig['hong_bao_day'])) {//无购车金时抽红包与红包小于每日设定值
|
||||
if ($this->appConfig['ratio_hong_bao'] && $this->appConfig['ratio_hong_bao'] >= rand(1, 100)) {//红包概率
|
||||
$re_l = $this->ci->bobing_logs_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $data['uid']
|
||||
, 'cf_uid' => $data['cf_uid']));
|
||||
if (!$re_l) {//帮博时只能在一个用户上中一次红包
|
||||
$hong_bao = '0.3'; //'0.' . rand(30, 68);//0.30到0.68红包
|
||||
$data['hong_bao'] = $hong_bao;
|
||||
$data['status'] = 1;
|
||||
$content = '您博到现金红包' . $data['hong_bao'] . '元';
|
||||
$title = '恭喜您';
|
||||
$this->ci->bobing_user_model->hongBaoDay($data['act_key'], $hong_bao);
|
||||
}
|
||||
}
|
||||
}
|
||||
$log = $this->add_log($data);
|
||||
if ($log['status'] == 1) {
|
||||
return array('status' => API_CODE_FAIL, 'content' => '博饼日志添加失败');
|
||||
}
|
||||
$data['level_name'] = $this->ci->dice->getResultName();
|
||||
$data['status'] = 0;
|
||||
$data['lid'] = $log['lid'];
|
||||
$data['title'] = $title;
|
||||
$data['content'] = $content;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:添加企业微信加分
|
||||
* Created on: 2021/8/25 10:04
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function wxqy_credit()
|
||||
{
|
||||
$re_l = $this->ci->bobing_logs_model->get(array('uid' => $this->uid, 'app_id' => $this->appConfig['app_id'], 'type' => 3));
|
||||
if ($re_l) {
|
||||
return array('status' => -1, 'content' => '已添过企业微信加分了');
|
||||
}
|
||||
$data['app_id'] = $this->appConfig['app_id'];
|
||||
$data['act_key'] = $this->appConfig['act_key'];
|
||||
$data['uid'] = $this->uid;
|
||||
$data['credit'] = $this->appConfig['wxqy_nums'];
|
||||
$data['bo_date'] = date('Y-m-d');
|
||||
$data['ip'] = get_client_ip();
|
||||
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
$data['type'] = 2;
|
||||
$data['c_time'] = time();
|
||||
$log = $this->add_log($data);
|
||||
if ($log['status'] == 1) {
|
||||
return array('status' => -1, 'content' => '博饼日志添加失败');
|
||||
}
|
||||
return array('status' => $log['lid'], 'content' => '企业微信加分成功');
|
||||
}
|
||||
|
||||
//博饼结果保存到数据库
|
||||
private function add_log($data)
|
||||
{
|
||||
$_data['status'] = 0;
|
||||
$this->ci->bobing_logs_model->db->trans_begin();
|
||||
try {
|
||||
$lid = $this->ci->bobing_logs_model->add($data);
|
||||
if ($lid) {
|
||||
$map = array('act_key' => $data['act_key'], 'app_id' => $data['app_id'], 'uid' => $data['uid']);
|
||||
$up_data["credit = credit+{$data['credit']}"] = null;//加积分
|
||||
$data['car_gold'] && $up_data["car_gold = car_gold+{$data['car_gold']}"] = null;//加购车金
|
||||
$data['type'] == 2 && $up_data["wxqy"] = 1;//加企业微信
|
||||
$this->ci->bobing_user_model->update($up_data, $map);
|
||||
$map['bo_date'] = $data['bo_date'];
|
||||
if ($this->ci->bobing_user_credit_model->cache('get', array($map, 'id'))) {
|
||||
$this->ci->bobing_user_credit_model->update(array("credit = credit+{$data['credit']}" => null), $map);
|
||||
} else {
|
||||
$map['credit'] = $data['credit'];
|
||||
$map['c_time'] = time();
|
||||
$this->ci->bobing_user_credit_model->add($map);
|
||||
}
|
||||
//助力加分
|
||||
if ($data['type'] == 1) {
|
||||
$map_my = array('act_key' => $data['act_key'], 'app_id' => $data['app_id'], 'uid' => $data['cf_uid']);
|
||||
$this->ci->bobing_user_model->update(array("credit = credit+{$data['credit']}" => null), $map_my);
|
||||
$map_my['bo_date'] = $data['bo_date'];
|
||||
if ($this->ci->bobing_user_credit_model->cache('get', array($map_my, 'id'))) {
|
||||
$this->ci->bobing_user_credit_model->update(array("credit = credit+{$data['credit']}" => null), $map_my);
|
||||
} else {
|
||||
$map_my['credit'] = $data['credit'];
|
||||
$map_my['c_time'] = time();
|
||||
$this->ci->bobing_user_credit_model->add($map_my);
|
||||
}
|
||||
}
|
||||
$this->ci->bobing_user_model->boNums($data['act_key'], 1);
|
||||
}
|
||||
$_data['lid'] = $lid;
|
||||
} catch (Exception $e) {
|
||||
$this->ci->bobing_logs_model->db->trans_rollback();
|
||||
$_data['status'] = 1;
|
||||
return $_data;
|
||||
}
|
||||
if ($this->ci->bobing_logs_model->db->trans_status() === FALSE) {
|
||||
$this->ci->bobing_logs_model->db->trans_rollback();
|
||||
$_data['status'] = 1;
|
||||
return $_data;
|
||||
}
|
||||
$this->ci->bobing_logs_model->db->trans_commit();
|
||||
return $_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Title: 骰子类
|
||||
* Description: 用于模拟投骰子,取得结果
|
||||
* @copyright: Copyright (c) 2005-2010 By SS
|
||||
* @author: pcq
|
||||
* @version: 2.0
|
||||
*/
|
||||
class Dice
|
||||
{
|
||||
|
||||
const RESULT_ZYCJH = 13; //状元插金花
|
||||
const RESULT_LBHONG = 12; //六勃红
|
||||
const RESULT_BDJ = 11; //遍地锦
|
||||
const RESULT_LBHEI = 10; //六勃黑
|
||||
const RESULT_WH = 9; //五红
|
||||
const RESULT_WZDYX = 8; //五子带一秀
|
||||
const RESULT_WZ = 7; //五子
|
||||
const RESULT_ZY = 6; //状元
|
||||
const RESULT_DT = 5; //对堂
|
||||
const RESULT_SH = 4; //三红
|
||||
const RESULT_SJ = 3; //四进
|
||||
const RESULT_EJ = 2; //二举
|
||||
const RESULT_YX = 1; //一秀
|
||||
const RESULT_FH = 0; //罚黑
|
||||
|
||||
//结果骰子点数数组
|
||||
|
||||
private $_resultArr = array(0, 0, 0, 0, 0, 0);
|
||||
//结果等级
|
||||
private $_resultLevel = 0;
|
||||
//结果值(附带点数)
|
||||
private $_resultVal = 0;
|
||||
|
||||
static public function getAllLevel()
|
||||
{
|
||||
$arr = array(
|
||||
self::RESULT_LBHONG => "六勃红",
|
||||
self::RESULT_BDJ => "遍地锦",
|
||||
self::RESULT_LBHEI => "六抔黑",
|
||||
self::RESULT_ZYCJH => "状元插金花",
|
||||
self::RESULT_WH => "五红",
|
||||
self::RESULT_WZDYX => "五子带一秀",
|
||||
self::RESULT_WZ => "五子",
|
||||
self::RESULT_ZY => "状元",
|
||||
self::RESULT_DT => "对堂",
|
||||
self::RESULT_SH => "三红",
|
||||
self::RESULT_SJ => "四进",
|
||||
self::RESULT_EJ => "二举",
|
||||
self::RESULT_YX => "一秀",
|
||||
self::RESULT_FH => "罚黑"
|
||||
);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 博小鱼币时,鱼币对应关系
|
||||
* @param $level
|
||||
* @return int
|
||||
*/
|
||||
static public function getyucoin($level)
|
||||
{
|
||||
$arr = array(
|
||||
self::RESULT_ZYCJH => 20, //状元插金花
|
||||
self::RESULT_LBHONG => 18, //六勃红
|
||||
//self::RESULT_BD => 13, //遍地锦
|
||||
self::RESULT_LBHEI => 16, //六勃黑
|
||||
self::RESULT_WH => 14, //五红
|
||||
self::RESULT_WZDYX => 12, //五子带一秀
|
||||
self::RESULT_WZ => 10, //五子
|
||||
self::RESULT_ZY => 8, //状元
|
||||
self::RESULT_DT => 5, //对堂
|
||||
self::RESULT_SH => 4, //三红
|
||||
self::RESULT_SJ => 3, //四进
|
||||
self::RESULT_EJ => 2, //二举
|
||||
self::RESULT_YX => 1, //一秀
|
||||
self::RESULT_FH => 0, //罚黑
|
||||
);
|
||||
return intval($arr[$level]);
|
||||
}
|
||||
|
||||
//结果名称
|
||||
static public function getName($flag)
|
||||
{
|
||||
$arr = self::getAllLevel();
|
||||
if (empty($arr[$flag])) {
|
||||
return $arr[self::RESULT_FH];
|
||||
} else {
|
||||
return $arr[$flag];
|
||||
}
|
||||
}
|
||||
|
||||
//输出结果
|
||||
static public function show_result_msg($resultlevel, &$resultname, &$istop)
|
||||
{
|
||||
if ($resultlevel == 0) {
|
||||
$resultname = "鱼鱼加油 再试一次";
|
||||
} else if ($resultlevel == Dice::RESULT_YX) {
|
||||
$resultname .= " 一马当先";
|
||||
} else if ($resultlevel == Dice::RESULT_EJ) {
|
||||
$resultname .= " 加把劲往前冲";
|
||||
} else if ($resultlevel == Dice::RESULT_SJ) {
|
||||
$resultname .= " 再博博找找灵感";
|
||||
} else if ($resultlevel == Dice::RESULT_SH) {
|
||||
$resultname .= " 有点能耐继续努力";
|
||||
} else if ($resultlevel == Dice::RESULT_DT) {
|
||||
$resultname .= " 胜利在望";
|
||||
} else if ($resultlevel >= Dice::RESULT_ZY) {
|
||||
$istop = 1;
|
||||
$resultname .= " 恭喜!";
|
||||
}
|
||||
return $resultname;
|
||||
}
|
||||
|
||||
//初始化,随便生成点数
|
||||
function init($resultStr = false)
|
||||
{
|
||||
if (!$resultStr) {
|
||||
$this->run();
|
||||
} else {
|
||||
$this->_resultArr = self::strToArr($resultStr);
|
||||
if (!$this->_resultArr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
//掷骰子
|
||||
private function run($resultStr = false)
|
||||
{
|
||||
if (!$resultStr) {
|
||||
$_DICE = array(
|
||||
array(1, 2, 3, 4, 5, 6),
|
||||
array(1, 2, 3, 4, 5, 6),
|
||||
array(1, 2, 3, 4, 5, 6),
|
||||
array(1, 2, 3, 4, 5, 6),
|
||||
array(1, 2, 3, 4, 5, 6),
|
||||
array(1, 2, 3, 4, 5, 6)
|
||||
);
|
||||
|
||||
//生成随机数组
|
||||
$dice_count = count($_DICE);
|
||||
for ($i = 0; $i < $dice_count; $i++) {
|
||||
$this->_resultArr[$i] = $_DICE[$i][rand(0, count($_DICE[$i]) - 1)];
|
||||
}
|
||||
} else {
|
||||
$this->_resultArr = self::strToArr($resultStr);
|
||||
if (!$this->_resultArr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//分析
|
||||
private function parse()
|
||||
{
|
||||
$sumVal = 0; //总点数
|
||||
//结果数量,用于统计哪个点有几个
|
||||
$nums = array(
|
||||
//点=>数量,
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => 0,
|
||||
4 => 0,
|
||||
5 => 0,
|
||||
6 => 0,
|
||||
);
|
||||
|
||||
//统计点数数量
|
||||
foreach ($this->_resultArr as $value) {
|
||||
$nums[$value]++;
|
||||
$sumVal += $value;
|
||||
}
|
||||
if ($nums[4] == 6) {
|
||||
$this->_resultLevel = self::RESULT_LBHONG; //六勃红
|
||||
} /*
|
||||
* else if($nums[1] == 6){
|
||||
$this->_resultLevel = self::RESULT_BDJ; //遍地锦
|
||||
}
|
||||
*/
|
||||
else if (($nums[2] == 6) || ($nums[3] == 6) || ($nums[5] == 6) || ($nums[6] == 6) || $nums[1] == 6) {
|
||||
$this->_resultLevel = self::RESULT_LBHEI; //六勃黑
|
||||
} else if (($nums[4] == 4) && ($nums[1] == 2)) {
|
||||
$this->_resultLevel = self::RESULT_ZYCJH; //状元插金花
|
||||
} else if ($nums[4] == 5) {
|
||||
$this->_resultLevel = self::RESULT_WH; //五红
|
||||
$this->_resultVal = $sumVal - 20; //附带点数
|
||||
} else if ((($nums[1] == 5) || ($nums[2] == 5) || ($nums[3] == 5) || ($nums[5] == 5) || ($nums[6] == 5)) && ($nums[4] == 1)) {
|
||||
$this->_resultLevel = self::RESULT_WZDYX; //五子带一秀
|
||||
} else if ((($nums[1] == 5) || ($nums[2] == 5) || ($nums[3] == 5) || ($nums[5] == 5) || ($nums[6] == 5))) {
|
||||
$this->_resultLevel = self::RESULT_WZ; //五子
|
||||
if ($nums[$this->_resultArr[0]] == 5) {
|
||||
$this->_resultVal = $sumVal - $this->_resultArr[0] * 5; //附带点数
|
||||
} else {
|
||||
$this->_resultVal = $this->_resultArr[0]; //附带点数
|
||||
}
|
||||
} else if (($nums[4] == 4)) {
|
||||
$this->_resultLevel = self::RESULT_ZY; //状元
|
||||
$this->_resultVal = $sumVal - 16; //附带点数
|
||||
} else if (($nums[1] == 1) && ($nums[2] == 1) && ($nums[3] == 1) && ($nums[4] == 1) && ($nums[5] == 1) && ($nums[6] == 1)) {
|
||||
$this->_resultLevel = self::RESULT_DT; //对堂
|
||||
} else if ($nums[4] == 3) {
|
||||
$this->_resultLevel = self::RESULT_SH; //三红
|
||||
} else if (($nums[1] == 4) || ($nums[2] == 4) || ($nums[3] == 4) || ($nums[5] == 4) || ($nums[6] == 4)) {
|
||||
$this->_resultLevel = self::RESULT_SJ; //四进
|
||||
} else if ($nums[4] == 2) {
|
||||
$this->_resultLevel = self::RESULT_EJ; //二举
|
||||
} else if ($nums[4] == 1) {
|
||||
$this->_resultLevel = self::RESULT_YX; //一秀
|
||||
} else {
|
||||
$this->_resultLevel = self::RESULT_FH; //罚黑
|
||||
}
|
||||
}
|
||||
|
||||
//重新掷骰子
|
||||
public function reRun($resultStr = false)
|
||||
{
|
||||
//清空数据
|
||||
$this->_resultLevel = 0;
|
||||
$this->_resultVal = 0;
|
||||
$this->_resultArr = array(0, 0, 0, 0, 0, 0);
|
||||
$this->run($resultStr);
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
//取得结果等级
|
||||
public function getResultLevel()
|
||||
{
|
||||
return $this->_resultLevel;
|
||||
}
|
||||
|
||||
//取得结果值(附带点数)
|
||||
public function getResultVal()
|
||||
{
|
||||
return $this->_resultVal;
|
||||
}
|
||||
|
||||
//取得结果名称
|
||||
public function getResultName()
|
||||
{
|
||||
$resultLevel = $this->_resultLevel;
|
||||
return $this->getName($resultLevel);
|
||||
}
|
||||
|
||||
//取得结果骰子点数数组
|
||||
public function getResultArr()
|
||||
{
|
||||
return $this->_resultArr;
|
||||
}
|
||||
|
||||
//取得结果骰子点数字符串代表结果(用于保存到数据库中如234123)
|
||||
public function getResultStr()
|
||||
{
|
||||
return implode($this->_resultArr);
|
||||
}
|
||||
|
||||
|
||||
public function getcredit($level = false)
|
||||
{
|
||||
$level = $level == false ? $this->_resultLevel : $level;
|
||||
$arr = array(
|
||||
self::RESULT_ZYCJH => 80, //状元插金花
|
||||
self::RESULT_LBHONG => 60, //六勃红
|
||||
//self::RESULT_BD => 13, //遍地锦
|
||||
self::RESULT_LBHEI => 50, //六勃黑
|
||||
self::RESULT_WH => 45, //五红
|
||||
self::RESULT_WZDYX => 40, //五子带一秀
|
||||
self::RESULT_WZ => 35, //五子
|
||||
self::RESULT_ZY => 30, //状元
|
||||
self::RESULT_DT => 15, //对堂
|
||||
self::RESULT_SH => 8, //三红
|
||||
self::RESULT_SJ => 4, //四进
|
||||
self::RESULT_EJ => 2, //二举
|
||||
self::RESULT_YX => 1, //一秀
|
||||
self::RESULT_FH => 0, //罚黑
|
||||
);
|
||||
return intval($arr[$level]);
|
||||
}
|
||||
|
||||
//把代表点数的字符串转化为点数数组
|
||||
static public function strToArr($str = "")
|
||||
{
|
||||
if ($str == "") {
|
||||
return false;
|
||||
}
|
||||
$arr = explode(',', $str);
|
||||
if (count($arr) != 6) { //非法字符串
|
||||
return false;
|
||||
}
|
||||
foreach ($arr as $value) {
|
||||
if (!($value >= 1 && $value <= 6)) { //非法字符
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//test
|
||||
//$dice = new Dice();
|
||||
//while($dice->getResultLevel() != 5)
|
||||
//{
|
||||
// $dice->reRun();
|
||||
//}
|
||||
//echo "<br/>result lever:".$dice->getResultLevel();
|
||||
//echo "<br/>result val:".$dice->getResultVal();
|
||||
//echo "<br/>result name:".$dice->getResultName();
|
||||
//echo "<br/>result string:".$dice->getResultStr();
|
||||
?>
|
||||
+1
-1
@@ -9,7 +9,7 @@ class WxPayConfig
|
||||
{
|
||||
const APPID = 'wx98e64c11aac45966';
|
||||
const APPSECRET = 'f8eec7be1c87a1c8e40213e144821ec3';
|
||||
const MCHID = '1611216095';
|
||||
const MCHID = '1612289137';
|
||||
const KEY = 'd1ddc03f6178767795dc283e68a80e81';
|
||||
const SIGN_TYPE = 'MD5';
|
||||
const NOTIFY_URL = '';
|
||||
|
||||
@@ -880,7 +880,7 @@ if (!function_exists('http_host_com')){
|
||||
if($type == 'api'){
|
||||
$url = 'https://liche-api-dev.xiaoyu.com';
|
||||
} else if($type == 'home'){
|
||||
$url = "https://liche-wxdev.xiaoyu.com";
|
||||
$url = "https://liche-dev.xiaoyu.com";
|
||||
} else if($type == 'admin'){
|
||||
$url = "http://liche-admin.dev.xiaoyu.com";
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ class Wx_qyapi
|
||||
function init($params)
|
||||
{
|
||||
$configs = array(
|
||||
//狸车
|
||||
'liche' => array(
|
||||
'corpid' => 'wwc2caba960d202087',//企业ID
|
||||
'corpsecret' => 'aQ2yhOBTXZnM0iwFtBzYIWbtyq4wFaIXBYTKg3xFxas',//企业密钥 R9fj_ocdb5p4Vr_qaQY54A4Z5SbyZBRWk4nfTMiPxgo
|
||||
),
|
||||
//星选家
|
||||
'xxj' => array(
|
||||
'corpid' => 'wwecac3c2b60c31b1b',//企业ID
|
||||
@@ -59,7 +64,7 @@ class Wx_qyapi
|
||||
$params['corpid'] && $this->corpid = $params['corpid'];
|
||||
$params['corpsecret'] && $this->corpsecret = $params['corpsecret'];
|
||||
|
||||
$app = $params['app'] ? $params['app'] : 'xxj';
|
||||
$app = $params['app'] ? $params['app'] : 'liche';
|
||||
if ($configs[$app]) {
|
||||
$config = $configs[$app];
|
||||
!$this->corpid && $config['corpid'] && $this->corpid = $config['corpid'];
|
||||
@@ -113,7 +118,7 @@ class Wx_qyapi
|
||||
|
||||
public function token()
|
||||
{
|
||||
$url = self::BASE_URL . sprintf(self::TOKEN_API, $this->corpid, "EFIev4j-0iv4Uy2vrDATzsL3aIW2IT_kRO4zx73I31g");
|
||||
$url = self::BASE_URL . sprintf(self::TOKEN_API, $this->corpid, $this->corpsecret);
|
||||
$res = $this->ci->mycurl->httpGet($url);
|
||||
$result = json_decode($res);
|
||||
return $result;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/**
|
||||
* Notes:企业微信用户表
|
||||
* Created on: 2021/8/24 14:52
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class App_wechatqy_model extends HD_Model{
|
||||
private $table_name = 'lc_app_wechatqy';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->table_name, 'default');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once COMMPATH . '/models/bobing/base_model.php';
|
||||
|
||||
/**
|
||||
* Notes:博饼记录
|
||||
* Created on: 2021/8/13 14:52
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Bobing_logs_model extends Base_model
|
||||
{
|
||||
public $table_name = 'lc_bobing_logs';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once COMMPATH . '/models/bobing/base_model.php';
|
||||
|
||||
/**
|
||||
* Notes:博饼用户每日积分
|
||||
* Created on: 2021/8/12 14:52
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Bobing_user_credit_model extends Base_model
|
||||
{
|
||||
public $table_name = 'lc_bobing_user_credit';
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once COMMPATH . '/models/bobing/base_model.php';
|
||||
|
||||
/**
|
||||
* Notes:博饼用户
|
||||
* Created on: 2021/8/12 14:52
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Bobing_user_model extends Base_model
|
||||
{
|
||||
public $table_name = 'lc_bobing_user';
|
||||
|
||||
/**
|
||||
* Notes:所有博饼活动id
|
||||
* Created on: 2021/8/12 15:11
|
||||
* Created by: dengbw
|
||||
* @return array
|
||||
*/
|
||||
public function actIds()
|
||||
{
|
||||
return array(2021);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:app配置
|
||||
* Created on: 2019/12/27 14:52
|
||||
* Created by: dengbw
|
||||
* @param $act_key
|
||||
* @return array
|
||||
*/
|
||||
public function appConfig($act_key = 2021)
|
||||
{
|
||||
$config = array();
|
||||
if ($act_key == 2021) {
|
||||
$config = array(
|
||||
'title' => 'LiChe博饼', 'content' => '2021闽南博饼嘉年华', 'game_start_date' => '2021-07-20', 'game_end_date' => '2021-09-31',
|
||||
'group' => array('title' => '添加小狸', 'btn' => '加小狸企业微信', 'tips' => '通过后送288幸运分'),
|
||||
'app_id' => 1, 'act_key' => $act_key, 'kz_nums' => 20, 'zl_nums' => 5, 'wxqy_nums' => 288, 'ratio_hong_bao' => 30, 'ratio_car_gold' => 50,
|
||||
'max_car_gold' => 500, 'buy_car_gold' => 500, 'hong_bao_day' => 1000, 'lottery_nums' => 10,
|
||||
'rule' => array('title' => '活动流程及规则', 'content' => '
|
||||
<div>1.通过投放、社群、经销商等渠道,获取种子用户,种子用户发起活动,通过汽车大奖、iPHONE大奖,吸引开桌用户;</div>
|
||||
<div>2.开桌用户可以直接获得5次博饼次数,博饼次数用完后,通过邀请助力用户为其博饼,双方可获得如下福利</div>
|
||||
<div>(1)开桌用户:</div>
|
||||
<div> ① 获得购车金:助力用户每次助力博饼,随机为开桌用户获得一定金额的购车金,购车金累计最高为500元;</div>
|
||||
<div> ② 获得幸运分: 助力用户每次助力博饼,根据博出的结果,为开桌用户获得不同的幸运分:一秀1分、二举2分、四进5分、三红10分、对堂20分、状元50分…</div>
|
||||
<div>(2)助力用户:</div>
|
||||
<div> ① 获得购车金:助力用户每次助力博饼,随机获得0.30元 - 0.68元不等现金红包,点击“立即开桌”后,即可到账(微信钱包);</div>
|
||||
<div> ② 获得幸运分: 助力用户每次助力博饼,根据博出的结果,同时为自己获得幸运分:一秀1分、二举2分、四进5分、三红10分、对堂20分、状元50分…</div>
|
||||
<div>3.所有用户添加小狸企业微信,即可获得288幸运分</div>
|
||||
<div>4.添加小狸后,自动获取微信小程序链接,9.9元换购500元购车金,与博饼开桌获得的购车金合并,形成1000元购车金</div>
|
||||
<div>5.每日博饼幸运分进入日排行榜,前10名可获得100元购物卡(每位用户活动期间只能获得一次);</div>
|
||||
<div>6.开桌用户活动期间累计博饼幸运分,进入总排行榜,前11名可获得大奖:</div>
|
||||
<div> ① 第1名获得雷丁芒果大奖</div>
|
||||
<div> ② 第2-11名获得iPHONE 13大奖</div>'),
|
||||
'gift' => array(
|
||||
array('id' => 1, 'title' => '第一名', 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/gift_box_tip_1.jpg'),
|
||||
array('id' => 2, 'title' => '第2`11名', 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/gift_box_tip_2.jpg'),
|
||||
array('id' => 3, 'title' => '购物金', 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/gift_box_tip_3.jpg'),
|
||||
array('id' => 4, 'title' => '现金红包', 'img' => 'https://qs.haodian.cn/wechat_app/liche/bobing/2021/gift_box_tip_4.jpg')),
|
||||
);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
//博饼总次数
|
||||
public function boNums($act_key = '', $add = 0)
|
||||
{
|
||||
$redis_key = $act_key . '_bo_nums';
|
||||
$redis = &load_cache('redis');
|
||||
$boNums = $redis->get($redis_key);
|
||||
if ($add) {
|
||||
$boNums = $boNums ? $boNums : 1;
|
||||
$boNums += mt_rand(3, 8);
|
||||
$redis->save($redis_key, $boNums);
|
||||
}
|
||||
return $boNums ? $boNums : 0;
|
||||
}
|
||||
|
||||
//每日红包发放数
|
||||
public function hongBaoDay($act_key = '', $amount = 0)
|
||||
{
|
||||
$redis_key = $act_key . '_hong_bao_day_' . date('Y-m-d');
|
||||
$redis = &load_cache('redis');
|
||||
$get_amount = $redis->get($redis_key);
|
||||
$get_amount = $get_amount ? $get_amount : 0;
|
||||
if ($amount) {
|
||||
$get_amount = $get_amount + $amount;
|
||||
$redis->save($redis_key, $get_amount);
|
||||
}
|
||||
return $amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Base_model extends HD_Model
|
||||
{
|
||||
protected $_cache_key_prefix = 'LiChe_bobing';
|
||||
public $mc_cache_expire = 600, $table_name;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct($this->table_name, 'default');
|
||||
}
|
||||
|
||||
protected function cache_key($params)
|
||||
{
|
||||
return $this->_cache_key_prefix . md5($this->table_name . $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对方法的某个结果集做缓存
|
||||
* @param $func
|
||||
* @param array $param
|
||||
* @param string $ttl
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function cache($func, $param = array(), $ttl = '', $type = 'mc')
|
||||
{
|
||||
$cache = &load_cache($type);
|
||||
$cache_key = $this->cache_key($type . $func . json_encode($param));
|
||||
$ttl > 0 && $this->mc_cache_expire = intval($ttl);
|
||||
if (!$rt = $cache->get($cache_key)) {
|
||||
$rt = call_user_func_array(array($this, $func), $param);
|
||||
$cache->save($cache_key, $rt, $this->mc_cache_expire);
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除某方法某个结果集的缓存
|
||||
* @param $func
|
||||
* @param array $param
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function un_cache($func, $param = array(), $type = 'mc')
|
||||
{
|
||||
$cache = &load_cache($type);
|
||||
$cache_key = $this->cache_key($type . $func . json_encode($param));
|
||||
return $cache->delete($cache_key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Notes:支付后操作
|
||||
* Created on: 2021/8/31 9:57
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Payhd_service extends HD_Service
|
||||
{
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct();
|
||||
if ($params['app_id']) {
|
||||
$this->app_id = $params['app_id'];
|
||||
}
|
||||
$this->log_file = __CLASS__ . "_app_id_" . $this->app_id . '.log';
|
||||
$this->load->model('apporder/order_purchase_model', 'mdOrderPurchase');
|
||||
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付后逻辑
|
||||
* @param string $sid
|
||||
* @param float $pay_price 订单真实支付金额
|
||||
*/
|
||||
public function after_pay($sid, $pay_price = '')
|
||||
{
|
||||
if ($sid) {
|
||||
debug_log("[start] " . __FUNCTION__ . ": sid:" . $sid, $this->log_file);
|
||||
$order = $this->mdOrderPurchase->get(array('sid' => $sid, 'app_id' => $this->app_id));
|
||||
if (!$order) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file);
|
||||
return array('code' => 0, 'msg' => '订单不存在');
|
||||
}
|
||||
if ($order['status'] > 1) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":{$sid}_订单已支付", $this->log_file);
|
||||
return array('code' => 0, 'msg' => '订单已支付');
|
||||
}
|
||||
switch ($order['type']) {
|
||||
case 1: //实物商品
|
||||
break;
|
||||
case 2: //虚拟物品
|
||||
break;
|
||||
case 3: //活动订单
|
||||
$upd = array('status' => 2, 'status_detail' => 21, 'pay_time' => date('Y-m-d H:i:s'));
|
||||
$pay_price && $upd['pay_price'] = $pay_price;
|
||||
$res = $this->mdOrderPurchase->update($upd, array('id' => $order['id']));
|
||||
if ($res) {
|
||||
//博饼加购车金
|
||||
$appConfig = $this->mdBobingUser->appConfig();
|
||||
$where = array('act_key' => $appConfig['act_key'], 'app_id' => $appConfig['app_id'], 'uid' => $order['app_uid']);
|
||||
$this->mdBobingUser->update(array("buy_car_gold" => $appConfig['buy_car_gold']), $where);
|
||||
return array('code' => 1, 'msg' => '操作成功');
|
||||
} else {
|
||||
return array('code' => 0, 'msg' => '更新失败');
|
||||
}
|
||||
break;
|
||||
case 4: //定金
|
||||
break;
|
||||
case 5: //委托服务费
|
||||
case 6: //首付或尾款
|
||||
break;
|
||||
default:
|
||||
debug_log("[error] " . __FUNCTION__ . ":{$order['type']}_未知商品类型", $this->log_file);
|
||||
return array('code' => 0, 'msg' => '未知商品类型');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Hongbao extends CI_Controller
|
||||
{
|
||||
private $uid = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('bobing/bobing_logs_model', 'mdBobingLogs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
* https://liche-dev.xiaoyu.com/h5/hongbao
|
||||
* https://www.liche.cn/h5/hongbao
|
||||
* Created on: 2021/8/26 11:19
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$params = $this->input->get();
|
||||
// $params['uid'] = 14;
|
||||
// $params['id'] = 828932;
|
||||
$data = array('code' => 400, 'title' => '领取失败', 'msg' => '');
|
||||
if (!$params['id'] || !$params['uid']) {
|
||||
$data['msg'] = '参数错误!';
|
||||
} else {
|
||||
$this->uid = intval($params['uid']);
|
||||
$id = intval($params['id']);
|
||||
$re_l = $this->mdBobingLogs->get(array('id' => $id));
|
||||
if (!$re_l || $re_l['status'] == 0 || $re_l['hong_bao'] <= 0) {
|
||||
$data['msg'] = '条件不符合!';
|
||||
}
|
||||
if ($re_l['status'] == 2) {
|
||||
$data['msg'] = '您已领取过了!';
|
||||
}
|
||||
if ($re_l['cf_uid'] != $params['uid']) {
|
||||
$data['msg'] = 'uid错误!';
|
||||
}
|
||||
if (!$data['msg']) {
|
||||
$url = http_host_com('home') . "/h5/hongbao?id={$id}&uid={$this->uid}";
|
||||
$params['app_id'] = $re_l['app_id'];
|
||||
$params['cf_uid'] = $re_l['cf_uid'];
|
||||
$user = $this->set_auth($url, $params);
|
||||
//小红榜发红包
|
||||
if ($user['openid_kzh']) {
|
||||
$sid = $this->create_order_no(350200);
|
||||
//企业付款到零钱
|
||||
//$re_l['hong_bao'] = 0.1;
|
||||
$this->load->library('Transfers', array('app_id' => 3));//小红榜支付
|
||||
$result = $this->transfers->sendMoney(array('partner_trade_no' => $sid, 'amount' => $re_l['hong_bao']
|
||||
, 'openid' => $user['openid_kzh'], 'desc' => '狸车博饼红包', 're_user_name' => $user['nickname']));
|
||||
$result['log_id'] = $id;
|
||||
$result['log_uid'] = $this->uid;
|
||||
debug_log("[info] " . __FUNCTION__ . "# result:" . json_encode($result, JSON_UNESCAPED_UNICODE), 'Hongbao.log');
|
||||
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {//转帐成功
|
||||
$this->mdBobingLogs->update(array('status' => 2), array('id' => $id));//设为已领取
|
||||
$data['title'] = '领取成功';
|
||||
$data['code'] = 200;
|
||||
$data['msg'] = '¥' . $re_l['hong_bao'] . '元';
|
||||
} else {
|
||||
$data['msg'] = '转帐失败!';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->load->view('/h5/hongbao/index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:授权获取openid
|
||||
* Created on: 2021/8/26 14:26
|
||||
* Created by: dengbw
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
*/
|
||||
private function set_auth($url = '', $params = array())
|
||||
{
|
||||
if ("wx" == checkua()) {
|
||||
$this->load->service("app/user_service", array("app_id" => $params['app_id']));
|
||||
$re = $this->user_service->get(array('id' => $params['cf_uid']));
|
||||
if ($re['openid_kzh']) {//已经授权获取openid了
|
||||
return array('openid_kzh' => $re['openid_kzh'], 'nickname' => $re['nickname']);
|
||||
}
|
||||
$this->load->helper('url');
|
||||
$config['appid'] = 'wx0d3d21aec5001a8e';//小红榜授权
|
||||
$config['appSecret'] = '41f0721c343e00f284a60332fff991a3';
|
||||
$code = $params['code'];
|
||||
$auth = $params['auth'];//是否信息授权
|
||||
$auth = 0;
|
||||
$auth && $url .= "&auth={$auth}";
|
||||
if ($code) {//授权码获取微信信息
|
||||
$auth_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$config['appid']}&secret={$config['appSecret']}&code={$code}&grant_type=authorization_code";
|
||||
$res = file_get_contents($auth_url);
|
||||
$ret = json_decode($res, true);
|
||||
$openid = $ret['openid'];
|
||||
$unionid = $ret['unionid'];
|
||||
if ($openid) {
|
||||
$this->user_service->update(array('openid_kzh' => $openid), array('id' => $params['cf_uid']));
|
||||
return array('openid_kzh' => $openid, 'nickname' => $re['nickname']);
|
||||
}
|
||||
} elseif ($auth) {//信息授权获取用户微信昵称/头像
|
||||
$redirect_uri = urlencode($url);
|
||||
$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
|
||||
redirect($auth_url);
|
||||
} else {//静默授权获取用户openid
|
||||
$redirect_uri = urlencode($url);
|
||||
$auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
|
||||
redirect($auth_url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function create_order_no($city_id = 350200, $source = '', $pay_type = 1, $order_type = 1)
|
||||
{
|
||||
$source_id = sprintf("%02d", 0);
|
||||
return $city_id . $source_id . $pay_type . $order_type . date('Ymd') . sprintf("%06d", rand(1, 999999));
|
||||
}
|
||||
|
||||
|
||||
private function show_json($code, $msg)
|
||||
{
|
||||
$data['code'] = $code;
|
||||
$data['msg'] = $msg;
|
||||
die(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -12,21 +12,25 @@ class Transfers
|
||||
|
||||
public function __construct($param = array())
|
||||
{
|
||||
$this->app_id = $param['app_id'] ? $param['app_id'] : 3; //默认飞鱼
|
||||
$this->app_id = $param['app_id'] ? $param['app_id'] : 1; //默认狸车
|
||||
switch ($this->app_id) {
|
||||
case 3://飞鱼
|
||||
case 1://狸车
|
||||
$this->wx_config_file = 'liche_WxPay.Config.php';
|
||||
break;
|
||||
case 3://小红榜
|
||||
$this->wx_config_file = 'fy_WxPay.Config.php';
|
||||
break;
|
||||
case 14://欧菲帮我美
|
||||
$this->wx_config_file = 'ofei_WxPay.Config.php';
|
||||
break;
|
||||
case 15://星盟卡
|
||||
$this->wx_config_file = 'xmcard_WxPay.Config.php';
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public function wxPayConfig()
|
||||
{
|
||||
require_once APPPATH . "../home/third_party/WXconfig/" . $this->wx_config_file;
|
||||
$config = new WxPayConfig();
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业付款到零钱
|
||||
* 接口介绍 https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
||||
@@ -37,7 +41,7 @@ class Transfers
|
||||
*/
|
||||
public function sendMoney($param = array())
|
||||
{
|
||||
require_once APPPATH . "../api/third_party/WXconfig/" . $this->wx_config_file;
|
||||
require_once APPPATH . "../home/third_party/WXconfig/" . $this->wx_config_file;
|
||||
$config = new WxPayConfig();
|
||||
$partner_trade_no = $param['partner_trade_no'] ? $param['partner_trade_no']
|
||||
: date('YmdHis') . rand(1000, 9999);//商户订单号
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 配置账号信息
|
||||
*/
|
||||
define('FY_APICLIENT_CERT',dirname(__FILE__).'/fy_cert/apiclient_cert.pem');
|
||||
define('FY_APICLIENT_KEY',dirname(__FILE__).'/fy_cert/apiclient_key.pem');
|
||||
|
||||
class WxPayConfig
|
||||
{
|
||||
const APPID = 'wx0d3d21aec5001a8e';
|
||||
const APPSECRET = '41f0721c343e00f284a60332fff991a3';
|
||||
const MCHID = '1531810641';
|
||||
const KEY = 'I1o32478lvhAlndo8030HUjer634BCWe';
|
||||
const SIGN_TYPE = 'MD5';
|
||||
const NOTIFY_URL = 'http://www.haodian.cn/wxapp/flyish/wxnotify/item';
|
||||
|
||||
//=======【证书路径设置】=====================================
|
||||
const SSLCERT_PATH = FY_APICLIENT_CERT;
|
||||
const SSLKEY_PATH = FY_APICLIENT_KEY;
|
||||
|
||||
//=======【curl代理设置】===================================
|
||||
const CURL_PROXY_HOST = "0.0.0.0";//"10.152.18.220";
|
||||
const CURL_PROXY_PORT = 0;//8080;
|
||||
|
||||
//=======【上报信息配置】===================================
|
||||
|
||||
const REPORT_LEVENL = 1;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>领取红包</title>
|
||||
<link rel="stylesheet" href="/css/h5/hongbao/red.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="red img-top-cover" style=" background-image:url('/img/h5/hongbao/bg.jpg');">
|
||||
<div class="pt120 color-fffcf4 text-center">
|
||||
<div class="pl40 font-60"><?= $title ?></div>
|
||||
<div class="pt20 font-80 text-bold"><?= $msg ?></div>
|
||||
</div>
|
||||
<? if ($msg == 200) { ?>
|
||||
<div class="absolute top-320 left-0 right-0">
|
||||
<img class="wp100" src="/img/h5/hongbao/title.png" alt=""/>
|
||||
</div>
|
||||
<? } ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
3988ab96f79da9ea105e464c123ac799
|
||||
@@ -0,0 +1 @@
|
||||
L9jPfjssZTbUBkyB
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
Reference in New Issue
Block a user