get_param(); $ret['time_out'] = bonus\manager::grab_period_timeout; if($type->binded_over()) { $ret['binded_over'] = 1; } else { $ret['binded_over'] = 0; } if($type->isEnd()) { $ret['is_end'] = 1; } else { $ret['is_end'] = 0; } $type_sn = $type->getType_sn(); $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}"; $ret['url'] = $url; $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}"; $ret['detail_url'] = $detail_url; return $ret; } static public function filter_bonus($bonus_info) { if(empty($bonus_info['user_name'])) { $bonus_info['user_name'] = substr_replace($bonus_info['user_mobile'], '****', 3, 4); } return $bonus_info; } static public function isFixed($send_type) { return ($send_type == bonus\type::SendType_Fixed); } static public function isRandom($send_type) { return ($send_type == bonus\type::SendType_Random); } static public function create_type_input($param) { return bonus\type::create_by_input($param); } static public function create_by_paramer($param) { return bonus\type::create_by_paramer($param); } static public function create_type_sn($type_sn) { return bonus\type::create_by_sn($type_sn); } static public function make_bonus($param, $rate_moneys) { $ret = bonus\factory::make_bonus($param,$rate_moneys); return $ret; } static public function make_vote_type($param, $rate_moneys) { $ret = bonus\factory::make_vote_type($param,$rate_moneys); return $ret; } static public function last_invite_type($member_id) { $mod = Model('bonus_type'); $items = $mod->get(['relayer_id' => $member_id, 'make_type' => bonus\type::MakeInviteType]); if(empty($items)) { return null; } else { return $items[0]; } } static public function get_typeinfo($type_sn) { $manager = new bonus\manager(); return $manager->get_typeinfo($type_sn); } static public function get_mine_by_typesn($type_sn) { $manager = new bonus\manager(); return $manager->get_mine_by_typesn($type_sn); } static public function get_mine_by_bonussn($bonus_sn) { $manager = new bonus\manager(); return $manager->get_mine_by_bonussn($bonus_sn); } static public function grab_bonus($type_sn) { $manager = new bonus\manager(); return $manager->grab_bonus($type_sn); } static public function onBinded($bonus_sn,$mobile,$userid) { try { $bonus = bonus\user_bonus::create_by_sn($bonus_sn); $type_sn = $bonus->type_sn(); $type = bonus\type::create_by_sn($type_sn); if($type->grab_type() != bonus\type::GrabType_Invite) return true; if($userid > 0) { $member_id = $userid; } elseif(!empty($mobile)) { $loginner = new login\mobile_log($mobile); if($loginner->ismember() == false) return false; $member_id = $loginner->memberid(); } else { $member_id = 0; } if($member_id > 0) { $mod_member = Model('member'); $mod_member->editMember(['member_id' => $member_id],['invited_bonus' => 1]); } return true; } catch (Exception $ex) { Log::record(__METHOD__ . " " . $ex->getMessage(),Log::ERR); } } static public function bind_bonus($bonus_sn,$session_id,$mobile,$userid,&$new_bonus_sn) { try { $manager = new bonus\manager(); $ret = $manager->bind_bonus($bonus_sn,$session_id,$mobile,$userid,$new_bonus_sn); if($ret) self::onBinded($bonus_sn,$mobile,$userid); return $ret; } catch (Exception $ex) { return array($ex->getCode(),$ex->getMessage()); } } static public function shake($bonus_sn,$strength,$direction) { $manager = new bonus\manager(); return $manager->shake($bonus_sn,$strength,$direction); } static public function comment($bonus_sn,$comment) { try { $manager = new bonus\manager(); return $manager->comment($bonus_sn,$comment); } catch (Exception $ex) { return false; } } static public function direct_asc() { return bonus\shaker::direct_asc; } static public function direct_dec() { return bonus\shaker::direct_dec; } static public function get_direction($first) { if($first) { return self::direct_asc(); } else { $direct = mt_rand(1,100); if($direct % 2 == 0) { return self::direct_asc(); } else { return self::direct_dec(); } } } static public function check_shake($bonus_sn,&$first) { static $shake_expire = 5; static $shake_maxcount = 5; if(!isset($_SESSION['bonus_shake'])) { $_SESSION['bonus_shake'] = []; } if(isset($_SESSION['bonus_shake'][$bonus_sn])) { $first = false; $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn]; $tmout = time() - $bonus_shake['time']; if($tmout <= $shake_expire) { return array('code' => errcode::ErrBonus, 'msg' => '请不要摇得太快~'); } elseif($bonus_shake['count'] > $shake_maxcount) { ++$bonus_shake['count']; return array('code' => errcode::ErrBonus, 'msg' => '该红包只允许被摇' . $shake_maxcount .'次~'); } else { return true; } } else { $_SESSION['bonus_shake'][$bonus_sn] = []; $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn]; $bonus_shake['count'] = 1; $bonus_shake['time'] = time(); $first = true; return true; } } static public function withold($member_id,$rates,$used_type) { $fsuccess = true; $total = 0.00; $holder = self::create_holder($member_id,$used_type); foreach ($rates as $rate => $money) { if($holder->withold($rate,$money) == true) { $total += $money; } else { $fsuccess = false; } } if($fsuccess) { return true; } else { return $total; } } static public function withold_money($member_id,$rate,$money,$used_type) { $holder = self::create_holder($member_id,$used_type); if($holder->withold($rate,$money) == false) { Log::record("withold user member_id={$member_id} money={$money}.",Log::ERR); } return true; } static public function withold_bonus($member_id,$bonus_sn,$rate,$money,$used_type) { $holder = self::create_holder($member_id,$used_type); return $holder->withold_bonus($rate,$bonus_sn,$money); } static public function send($type_sn,$member_ids) { try { $manager = new bonus\manager(); return $manager->send($type_sn,$member_ids); } catch (Exception $ex) { return false; } } static public function send_mobile($type_sn, $mobiles,$status) { try { $manager = new bonus\manager(); return $manager->send_mobile($type_sn,$mobiles,$status); } catch (Exception $ex) { return false; } } static public function get_share($share_id = 0) { return bonus\open_sharer::instance()->get($share_id); } static public function can_grab(bonus\type $type,$member_id,$mobile) { $grab_type = $type->grab_type(); if($grab_type == bonus\type::GrabType_All) { return true; } elseif($grab_type == bonus\type::GrabType_ExSender) { if($type->sender_id() == $member_id) { return false; } if($type->sender_mobile() == $mobile) { return false; } return true; } elseif($grab_type == bonus\type::GrabType_Invite) { $member_id = intval($member_id); if($member_id <= 0 && empty($mobile)) return true; if($member_id > 0) { $loginner = new login\memberid_log($member_id); if(!$loginner->ismember()) return true; $mInfo = $loginner->member_info(); } else { $loginner = new login\mobile_log($mobile); if(!$loginner->ismember()) return true; $mInfo = $loginner->member_info(); } return ($mInfo->invited_bonus() == false); } elseif ($grab_type == bonus\type::GrabType_ExMember) { $member_id = intval($member_id); if($member_id > 0 && !empty($mobile)) { $cond['member_id|member_mobile'] = ['_multi'=>true,$member_id,$mobile]; } elseif($member_id > 0) { $cond['member_id'] = $member_id; } elseif(!empty($mobile)) { $cond['member_mobile'] = $mobile; $cond['member_mobile_bind'] = 1; } else { return true; } $items = Model('member')->getMemberInfo($cond); return (empty($items) == true); } else { return false; } } static public function match_price($rate_moneys) { if(empty($rate_moneys)) return false; $scaler = new bonus\scaler($rate_moneys); return $scaler->calc(); } static private function create_holder($member_id,$used_type) { if(usedBonusRate()) { return new bonus\witholder($member_id,$used_type); } else { return new bonus\norate_holder($member_id,$used_type); } } static public function bonus_refund($bonus_type) { $types = bonus\type::create_by_paramer($bonus_type); QueueClient::push('onBonusChange', ['change_type' => 'bonus_refund', 'buyer_id' => $types->sender_id(), 'order_sn' => $types->getType_sn()]); } }