123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/10/15
- * Time: 下午5:55
- */
- namespace bonus;
- use bonus_helper;
- use errcode;
- use Log;
- class activity_bonus
- {
- const admin_member_id = 36429;
- private $mErrMessage;
- public function err()
- {
- return $this->mErrMessage;
- }
- private function parse_rate($bonus_rate)
- {
- $params = explode('#', urldecode($bonus_rate));
- $result = [];
- foreach ($params as $val) {
- if (preg_match_all('/^(\d{1,3})\|(\d{1,7})\|(\d{1,4})$/', $val, $match)) {
- $item['rate'] = intval($match[1][0]);
- $item['amount'] = intval($match[2][0]);
- $item['num'] = intval($match[3][0]);
- $result[] = $item;
- }
- }
- if (empty($result)) {
- return false;
- } else {
- return $result;
- }
- }
- private function check_param($input, &$ret)
- {
- if (!isset($input['start_time'])) {
- $ret = array('code' => errcode::ErrParamter, 'msg' => "请输入活动开始和结束时间.");
- return false;
- }
- $start_tm = strtotime($input['start_time']);
- if ($start_tm == false || $start_tm < time()) {
- $start_tm = time();
- }
- if (isset($input['end_time'])) {
- $end_tm = strtotime($input['end_time']);
- } else {
- $end_tm = $start_tm + 24 * 3600;
- }
- if ($end_tm <= $start_tm) {
- $end_tm = $start_tm + 24 * 3600;
- }
- $param = [];
- $param['send_start_date'] = $start_tm;
- $param['send_end_date'] = $end_tm;
- return $param;
- }
- public function make($input)
- {
- if (empty($input['bonus_rate'])) {
- $this->mErrMessage = "bonus_rate 参数为空";
- return false;
- }
- $result = [];
- $result['type_name'] = $input['type_name'];
- $result['type_bless'] = $input['type_bless'];
- $result['sender_id'] = self::admin_member_id;
- $result['sender_name'] = "熊猫美妆";
- $result['send_type'] = $input['send_type'];
- $result['usable_days'] = $input['usable_days'];
- $rate_moneys = $this->parse_rate($input['bonus_rate']);
- if ($rate_moneys == false) {
- $this->mErrMessage = "bonus_rate 或者 send_type 参数错误";
- return false;
- } else {
- $result['rate_money'] = $rate_moneys;
- }
- $param = $this->check_param($input, $ret);
- if ($param == false) {
- $this->mErrMessage = $ret['msg'];
- return false;
- }
- $result = array_merge($param, $result);
- $ret = bonus_helper::make_bonus($result, $rate_moneys);
- if ($ret === false) {
- return false;
- } else {
- $type_sn = $ret['type_sn'];
- if (BASE_SITE_URL == 'https://manager.lrlz.com') {
- $url = "https://passport.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
- } else {
- $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
- }
- return array('type_sn' => $type_sn, 'url' => "{$url}");
- }
- }
- public static function daliy_bonus_url()
- {
- $url = rkcache('daliy_bonus_url');
- if (!empty($url)) {
- return $url;
- } else {
- return "";
- }
- }
- public static function gen_daily_bonus()
- {
- $now = time();
- $today = date('Y-m-d', $now);
- $maker = new activity_bonus();
- $input['bonus_rate'] = "30|200|100"; //红包参数
- $input['type_name'] = "每日签到红包"; //红包名称
- $input['type_bless'] = "每天10点 试试手气"; //红包祝福语
- $input['usable_days'] = 30; //使用时间
- $input['send_type'] = 1; //1:随机红包
- $input['start_time'] = $today . ' 10:00:00';
- $input['end_time'] = $today . ' 23:59:59';
- $input['can_share'] = 0;
- $ret = $maker->make($input);
- if ($ret == false) {
- Log::record("daliy_bonus_url failed", Log::DEBUG);
- return "";
- } else {
- $expire = strtotime($input['end_time']) - $now + 86400;
- wkcache('daliy_bonus_url', $ret['url'], $expire);
- return $ret['url'];
- }
- }
- }
|