示例#1
0
    AND NOT EXISTS (SELECT 1 FROM ecs_user_bonus b WHERE u.user_id = b.user_id AND b.order_id = 0 AND b.expire_time < unix_timestamp())
    AND NOT EXISTS (SELECT 1 FROM ecs_order_info o WHERE u.user_id = o.user_id AND o.add_time > unix_timestamp() - 864000)'), array('name' => 'give_bonus_id', 'type' => 'text', 'value' => ''), array('name' => 'notice_message', 'type' => 'textarea', 'value' => ''));
    return;
}
$now = time();
$sql = "SELECT * FROM " . $ecs->table('bonus_type') . " WHERE send_type = 0 AND type_id = " . intval($cron['give_bonus_id']);
$bonus = $db->getRow($sql);
if (!empty($bonus) && $bonus['send_start_date'] <= $now && $bonus['send_end_date'] > $now) {
    $expire_time = get_expire_time($bonus);
    $ub = array('bonus_type_id' => $bonus['type_id'], 'amount' => $bonus['type_money'], 'add_time' => $now, 'expire_time' => $expire_time);
    include_once ROOT_PATH . '/includes/cls_wechat.php';
    $wechat = new WechatApi();
    $href = $_CFG['site_url'] . '/mobile/';
    $tmplid = 'FRYrwOR7gxcvFGU3a1_RIv87GamInBnW_3CrENj-sa0';
    $message = array('first' => array('color' => '#0000ff', 'value' => "您已获得一张{$bonus[type_money]}元水果优惠券。\n{$cron[notice_message]}"), 'keyword1' => array('color' => '#000000', 'value' => $bonus['type_name']), 'keyword2' => array('color' => '#000000', 'value' => '最鲜蜂水果订购'), 'keyword3' => array('color' => '#000000', 'value' => date('Y-m-d', $expire_time)), 'keyword4' => array('color' => '#000000', 'value' => '结算付款时选择优惠券即可使用'), "remark" => array('color' => '#000000', 'value' => "如有任何问题可致电客服咨询:{$_CFG[service_phone]}"));
    $query = $db->query($cron['mind_sql']);
    while ($rs = $db->fetch_array($query)) {
        $ub['user_id'] = $rs['user_id'];
        $db->autoExecute($ecs->table('user_bonus'), $ub);
        $wechat->send_template_msg($rs['wxid'], $tmplid, $message, $href);
    }
}
function get_expire_time($bonus)
{
    if (!empty($bonus['use_time_limit'])) {
        $expire_time = min(time() + intval($bonus['use_time_limit']), $bonus['use_end_date']);
    } else {
        $expire_time = intval($bonus['use_end_date']);
    }
    return $expire_time;
}
示例#2
0
    $modules[$i]['author'] = 'gy.wang';
    /* 网址 */
    $modules[$i]['website'] = '';
    /* 版本号 */
    $modules[$i]['version'] = '0.1.0';
    /* 配置信息 */
    $modules[$i]['config'] = array(array('name' => 'lead_days', 'type' => 'text', 'value' => '1'));
    return;
}
$lead_days = intval($cron['lead_days']);
$lead_days = $lead_days > 0 ?: 1;
// 计算到期时间点
$add_day_str = "+{$lead_days} days";
$t = strtotime($add_day_str);
$date = date('Y-m-d', $t);
$time = strtotime($date . ' 23:59:59');
$begin = strtotime($date);
$sql = "SELECT b.user_id, sum(b.amount) AS amount, count(b.bonus_id) as cnt, u.wxid FROM " . $ecs->table('user_bonus', b) . ", wxch_user AS u " . " WHERE b.user_id = u.uid AND b.order_id = 0 AND b.expire_time >= {$begin} AND b.expire_time < {$time} + 1" . " GROUP BY b.user_id ";
$query = $db->query($sql);
$link = $_CFG['site_url'] . '/mobile/user.php?act=bonus';
$tmplid = 'n3Pmjdmez5JmaEUCAHEHujfj8BgqMXNkO5FGfAhHACM';
$param = array('first' => array('color' => '#000000'), 'keynote1' => array('color' => '#000000'), 'keynote2' => array('color' => '#000000'), "remark" => array('color' => '#0000ff', 'value' => "\n点击查看我的优惠券。\n如有任何问题可致电客服咨询:{$_CFG[service_phone]}"));
include_once ROOT_PATH . '/includes/cls_wechat.php';
$wechat = new WechatApi();
while ($rs = $db->fetch_array($query)) {
    //if ($rs['user_id'] != 1) continue;
    $param['first']['value'] = "您有{$rs[cnt]}张优惠券明天即将过期,请在过期前使用。";
    $param['keynote1']['value'] = "共计{$rs[amount]}元优惠券";
    $param['keynote2']['value'] = date('Y年n月j日', $time);
    $result = $wechat->send_template_msg($rs['wxid'], $tmplid, $param, $link);
}
示例#3
0
 check_bonus_type($bonus_type);
 //$tpl = get_mail_template('send_bonus');
 //$today = local_date($_CFG['date_format']);
 $expire_time = min($bonus_type['use_end_date'], $now + $bonus_type['use_time_limit']);
 //模板消息配置
 include_once ROOT_PATH . '/includes/cls_wechat.php';
 $wechat = new WechatApi();
 $href = $_CFG['site_url'] . '/mobile/user.php?act=bonus';
 $tmplid = 'FRYrwOR7gxcvFGU3a1_RIv87GamInBnW_3CrENj-sa0';
 $param = array('first' => array('color' => '#000000', 'value' => '您有一张优惠券已到账'), 'keyword1' => array('color' => '#000000', 'value' => $bonus_type['type_name']), 'keyword2' => array('color' => '#000000', 'value' => '客服发放'), 'keyword3' => array('color' => '#000000', 'value' => date('Y-m-d H:i', $expire_time)), 'keyword4' => array('color' => '#000000', 'value' => '订单满' . $bonus_type['min_goods_amount'] . '元可用'), "remark" => array('color' => '#0000ff', 'value' => "点击查看详情"));
 foreach ($user_list as $key => $val) {
     $sql = "INSERT INTO " . $ecs->table('user_bonus') . " (bonus_type_id, bonus_sn, user_id, used_time, order_id, emailed,amount,add_time,expire_time) " . "VALUES ('{$_REQUEST['id']}', 0, '{$val['user_id']}', 0, 0, " . BONUS_NOT_SMS . ",{$bonus_type['type_money']},{$now},{$expire_time})";
     $db->query($sql);
     //发送微信模板消息通知
     if (!empty($val['wxid'])) {
         $wechat->send_template_msg($val['wxid'], $tmplid, $param, $href);
     }
     if ($loop >= $limit) {
         break;
     } else {
         $loop++;
     }
 }
 //admin_log(addslashes($_LANG['send_bonus']), 'add', 'bonustype');
 if ($send_count > $start + $limit) {
     $href = "bonus.php?act=send_by_user&start=" . ($start + $limit) . "&limit={$limit}&id={$_REQUEST['id']}&";
     if (isset($_REQUEST['send_rank'])) {
         $href .= "send_rank=1&rank_id={$rank_id}";
     }
     if (isset($_REQUEST['send_user'])) {
         $href .= "send_user=1&user=" . implode(',', $user_array);