108 行
4.1 KiB
PHP
可执行文件
108 行
4.1 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Api\Controller;
|
|
|
|
use Common\Model\PlugModel;
|
|
use Think\Controller;
|
|
|
|
//[1.5.52]
|
|
class VipController extends Controller
|
|
{
|
|
/**
|
|
* 公众号模板推送会员线下支付营销活动
|
|
* @param $openid
|
|
* @param $store_id
|
|
* @param $bill_id
|
|
* @param $money
|
|
*/
|
|
public function toMark($openid, $store_id, $bill_id, $money)
|
|
{
|
|
$user = D('RetailVip')->getFind(array('openid' => $openid));
|
|
if (!empty($user)) {
|
|
$merchant_id = $user['merchantid'];
|
|
$reward = getRewardActivity(2, $merchant_id, $store_id, $user['id'], '', $bill_id);//查询红包
|
|
|
|
//file_put_contents('./markActivity.txt', date('Y-m-d H:i:s') . ' ' . json_encode($reward) . "\r\n", FILE_APPEND);
|
|
if ($reward['status'] == 1) {
|
|
//红包
|
|
$activity = array(
|
|
'url' => "Vip/Reward/reward_pay/merchantid/{$merchant_id}/bill_order_id/{$bill_id}",
|
|
);
|
|
A('Vip/Mark')->activitySocket($merchant_id, $openid, $money, $activity);//推送红包
|
|
}
|
|
$res = $this->getTurntable($user['id'], $merchant_id, $money);//获取是否有大转盘,有就推送
|
|
if ($res) {
|
|
//大转盘
|
|
$activity = array(
|
|
'url' => "Vip/Activity/turntable_pay/merchantid/{$merchant_id}/bill_order_id/{$bill_id}",
|
|
);
|
|
A('Vip/Mark')->activitySocket($merchant_id, $openid, $money, $activity);//推送大转盘
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 判断是否有大转盘的机会
|
|
* @param $vid 会员ID
|
|
* @param $merchant_id 商户ID
|
|
* @param $money 支付金额
|
|
* @return int
|
|
* @throws \think\Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
private function getTurntable($vid, $merchant_id, $money)
|
|
{
|
|
$map['pm.merchant_id'] = $merchant_id;
|
|
$map['pm.m_status'] = 1;
|
|
$map['p.id'] = 36;
|
|
$turntable_plug = M('plug_merchant as pm')
|
|
->join("ls_plug as p on p.id=pm.plug_id")
|
|
->where($map)
|
|
->find();
|
|
if (!empty($turntable_plug)) {
|
|
$turntable = M('turntable')
|
|
->where(array('merchantid' => $merchant_id, 'status' => 1, 'type' => 2))
|
|
->find();
|
|
if ($turntable && $turntable['needmoney'] <= $money) {
|
|
$us['vid'] = $vid;
|
|
$us['turntableid'] = $turntable['id'];
|
|
$us['type'] = array('neq', 5);
|
|
if ($turntable['maxnum']) {
|
|
$user_max_num = M('turntable_use')->where($us)->count();//用户总中奖次数
|
|
if (intval($turntable['maxnum']) <= $user_max_num) {
|
|
return 0;
|
|
}
|
|
}
|
|
if ($turntable['playnum']) {
|
|
unset($us['type']);
|
|
$user_play_num = M('turntable_use')->where($us)->count();//用户已抽奖次数
|
|
if (intval($turntable['playnum']) <= $user_play_num) {
|
|
return 0;
|
|
}
|
|
}
|
|
if ($turntable['daymaxnum']) {
|
|
//限制每日中奖次数
|
|
$us['type'] = array('neq', 5);
|
|
$us['_string'] = 'addtime <' . time() . ' AND addtime >' . strtotime(date('Y-m-d'));
|
|
$turntable_number = M('turntable_use')->where($us)->count();
|
|
if ($turntable_number >= intval($turntable['daymaxnum'])) {
|
|
$where['type'] = 5;
|
|
$where['turntableid'] = $turntable['id'];
|
|
$prize = M('turntable_prize')->where($where)->find();
|
|
if (empty($prize)) {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
} |