bonus_helper.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/4/11
  6. * Time: 上午12:51
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/field_helper.php');
  9. require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
  10. require_once (BASE_ROOT_PATH . '/helper/ranklist_helper.php');
  11. require_once (BASE_ROOT_PATH . '/helper/text_filter.php');
  12. require_once (BASE_ROOT_PATH . '/helper/bonus/util.php');
  13. require_once (BASE_ROOT_PATH . '/helper/bonus/type.php');
  14. require_once (BASE_ROOT_PATH . '/helper/bonus/user_bonus.php');
  15. require_once (BASE_ROOT_PATH . '/helper/bonus/generator.php');
  16. require_once (BASE_ROOT_PATH . '/helper/bonus/grab.php');
  17. require_once (BASE_ROOT_PATH . '/helper/bonus/factory.php');
  18. require_once (BASE_ROOT_PATH . '/helper/bonus/manager.php');
  19. require_once (BASE_ROOT_PATH . '/helper/bonus/shaker.php');
  20. require_once (BASE_ROOT_PATH . '/helper/bonus/allocator.php');
  21. require_once (BASE_ROOT_PATH . '/helper/bonus/witholder.php');
  22. require_once (BASE_ROOT_PATH . '/helper/bonus/open_sharer.php');
  23. require_once (BASE_ROOT_PATH . '/helper/bonus/scaler.php');
  24. require_once (BASE_ROOT_PATH . '/helper/bonus/thief_vilator.php');
  25. class bonus_helper
  26. {
  27. const def_bless = '熊猫美妆与你分享美丽的秘密~';
  28. const send_bonus_withold = 1;
  29. const pay_order_withold = 2;
  30. static public function filter_type($type_info)
  31. {
  32. $type = \bonus\type::create_by_paramer($type_info);
  33. $ret = $type->get_param();
  34. $ret['time_out'] = \bonus\manager::grab_period_timeout;
  35. if($type->binded_over()) {
  36. $ret['binded_over'] = 1;
  37. } else {
  38. $ret['binded_over'] = 0;
  39. }
  40. if($type->isEnd()) {
  41. $ret['is_end'] = 1;
  42. } else {
  43. $ret['is_end'] = 0;
  44. }
  45. $type_sn = $type->getType_sn();
  46. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  47. $ret['url'] = $url;
  48. $detail_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
  49. $ret['detail_url'] = $detail_url;
  50. return $ret;
  51. }
  52. static public function filter_bonus($bonus_info)
  53. {
  54. if(empty($bonus_info['user_name'])) {
  55. $bonus_info['user_name'] = substr_replace($bonus_info['user_mobile'], '****', 3, 4);
  56. }
  57. return $bonus_info;
  58. }
  59. static public function isFixed($send_type) {
  60. return ($send_type == \bonus\type::SendType_Fixed);
  61. }
  62. static public function isRandom($send_type) {
  63. return ($send_type == \bonus\type::SendType_Random);
  64. }
  65. static public function create_type_input($param) {
  66. return \bonus\type::crate_by_input($param);
  67. }
  68. static public function create_by_paramer($param) {
  69. return \bonus\type::create_by_paramer($param);
  70. }
  71. static public function create_type_sn($type_sn) {
  72. return \bonus\type::create_by_sn($type_sn);
  73. }
  74. static public function make_bonus($param, $rate_moneys)
  75. {
  76. $ret = \bonus\factory::make_bonus($param,$rate_moneys);
  77. return $ret;
  78. }
  79. static public function make_vote_type($param, $rate_moneys)
  80. {
  81. $ret = \bonus\factory::make_vote_type($param,$rate_moneys);
  82. return $ret; }
  83. static public function last_invite_type($member_id)
  84. {
  85. $mod = Model('bonus_type');
  86. $items = $mod->get(array('relayer_id' => $member_id, 'make_type' => \bonus\type::MakeInviteType));
  87. if(empty($items)) {
  88. return null;
  89. } else {
  90. return $items[0];
  91. }
  92. }
  93. static public function get_typeinfo($type_sn)
  94. {
  95. $manager = new \bonus\manager();
  96. return $manager->get_typeinfo($type_sn);
  97. }
  98. static public function get_mine_by_typesn($type_sn) {
  99. $manager = new \bonus\manager();
  100. return $manager->get_mine_by_typesn($type_sn);
  101. }
  102. static public function get_mine_by_bonussn($bonus_sn) {
  103. $manager = new \bonus\manager();
  104. return $manager->get_mine_by_bonussn($bonus_sn);
  105. }
  106. static public function grab_bonus($type_sn)
  107. {
  108. $manager = new \bonus\manager();
  109. return $manager->grab_bonus($type_sn);
  110. }
  111. static public function bind_bonus($bonus_sn,$session_id,$mobile,&$new_bonus_sn)
  112. {
  113. try
  114. {
  115. $manager = new \bonus\manager();
  116. return $manager->bind_bonus($bonus_sn,$session_id,$mobile,$new_bonus_sn);
  117. } catch (Exception $ex) {
  118. return array($ex->getCode(),$ex->getMessage());
  119. }
  120. }
  121. static public function shake($bonus_sn,$strength,$direction)
  122. {
  123. $manager = new \bonus\manager();
  124. return $manager->shake($bonus_sn,$strength,$direction);
  125. }
  126. static public function comment($bonus_sn,$comment)
  127. {
  128. try
  129. {
  130. $manager = new \bonus\manager();
  131. return $manager->comment($bonus_sn,$comment);
  132. } catch (Exception $ex) {
  133. return false;
  134. }
  135. }
  136. static public function topup_bonus(predeposit_helper $pred,$mobile)
  137. {
  138. $mod_bonus = Model('user_bonus');
  139. $bind_bonus = $mod_bonus->getBinded($mobile);
  140. if(empty($bind_bonus)) {
  141. return false;
  142. }
  143. $manager = new \bonus\manager();
  144. $bonusex = array();
  145. foreach($bind_bonus as $val)
  146. {
  147. $type_id = $val['type_id'];
  148. $type = \bonus\type::create_by_id($type_id);
  149. $bonus = \bonus\user_bonus::create_by_param($val);
  150. try
  151. {
  152. if($manager->topup($type,$mod_bonus,$val) == true) {
  153. array_push($bonusex,$val);
  154. ranklist_helper::add_money($_SESSION['member_id'],$bonus->bonus_value());
  155. $pred->add_bonus($bonus,$type);
  156. }
  157. } catch (Exception $ex) {
  158. }
  159. }
  160. if(empty($bonusex)) {
  161. return false;
  162. } else {
  163. return $bonusex;
  164. }
  165. }
  166. static public function direct_asc() {
  167. return \bonus\shaker::direct_asc;
  168. }
  169. static public function direct_dec() {
  170. return \bonus\shaker::direct_dec;
  171. }
  172. static public function get_direction($first)
  173. {
  174. if($first) {
  175. return self::direct_asc();
  176. }
  177. else
  178. {
  179. $direct = mt_rand(1,100);
  180. if($direct % 2 == 0) {
  181. return self::direct_asc();
  182. } else {
  183. return self::direct_dec();
  184. }
  185. }
  186. }
  187. static public function check_shake($bonus_sn,&$first)
  188. {
  189. static $shake_expire = 5;
  190. static $shake_maxcount = 5;
  191. if(!isset($_SESSION['bonus_shake'])) {
  192. $_SESSION['bonus_shake'] = [];
  193. }
  194. if(isset($_SESSION['bonus_shake'][$bonus_sn]))
  195. {
  196. $first = false;
  197. $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn];
  198. $tmout = time() - $bonus_shake['time'];
  199. if($tmout <= $shake_expire) {
  200. return array('code' => errcode::ErrBonus, 'msg' => '请不要摇得太快~');
  201. } elseif($bonus_shake['count'] > $shake_maxcount) {
  202. ++$bonus_shake['count'];
  203. return array('code' => errcode::ErrBonus, 'msg' => '该红包只允许被摇' . $shake_maxcount .'次~');
  204. } else {
  205. return true;
  206. }
  207. }
  208. else
  209. {
  210. $_SESSION['bonus_shake'][$bonus_sn] = [];
  211. $bonus_shake = &$_SESSION['bonus_shake'][$bonus_sn];
  212. $bonus_shake['count'] = 1;
  213. $bonus_shake['time'] = time();
  214. $first = true;
  215. return true;
  216. }
  217. }
  218. static public function withold($member_id,$rates,$used_type)
  219. {
  220. $fsuccess = true;
  221. $total = 0.00;
  222. $holder = new \bonus\witholder($member_id,$used_type);
  223. foreach ($rates as $rate => $money)
  224. {
  225. if($holder->withold($rate,$money) == true) {
  226. $total += $money;
  227. } else {
  228. $fsuccess = false;
  229. }
  230. }
  231. if($fsuccess) {
  232. return true;
  233. }
  234. else {
  235. return $total;
  236. }
  237. }
  238. static public function withold_money($member_id,$rate,$money,$used_type)
  239. {
  240. $holder = new \bonus\witholder($member_id,$used_type);
  241. if($holder->withold($rate,$money) == false) {
  242. Log::record("withold user member_id={$member_id} money={$money}.",Log::ERR);
  243. }
  244. return true;
  245. }
  246. static public function withold_bonus($member_id,$bonus_sn,$rate,$money,$used_type)
  247. {
  248. $holder = new \bonus\witholder($member_id,$used_type);
  249. return $holder->withold_bonus($rate,$bonus_sn,$money);
  250. }
  251. static public function send($type_sn,$member_ids)
  252. {
  253. try
  254. {
  255. $manager = new \bonus\manager();
  256. return $manager->send($type_sn,$member_ids);
  257. } catch (Exception $ex) {
  258. return false;
  259. }
  260. }
  261. static public function send_mobile($type_sn, $mobiles,$status)
  262. {
  263. try
  264. {
  265. $manager = new \bonus\manager();
  266. return $manager->send_mobile($type_sn,$mobiles,$status);
  267. } catch (Exception $ex) {
  268. return false;
  269. }
  270. }
  271. static public function get_share($share_id = 0) {
  272. return \bonus\open_sharer::instance()->get($share_id);
  273. }
  274. static public function can_grab(\bonus\type $type,$member_id,$mobile)
  275. {
  276. $grab_type = $type->grab_type();
  277. if($grab_type == \bonus\type::GrabType_All) {
  278. return true;
  279. }
  280. elseif($grab_type == \bonus\type::GrabType_EXSENDER)
  281. {
  282. if($type->sender_id() == $member_id) {
  283. return false;
  284. }
  285. if($type->sender_mobile() == $mobile) {
  286. return false;
  287. }
  288. return true;
  289. }
  290. else
  291. {
  292. $member_id = intval($member_id);
  293. if($member_id > 0 && !empty($mobile)) {
  294. $cond['member_id|member_mobile'] = array('_multi'=>true,$member_id,$mobile);
  295. }
  296. elseif($member_id > 0) {
  297. $cond['member_id'] = $member_id;
  298. }
  299. elseif(!empty($mobile)) {
  300. $cond['member_mobile'] = $mobile;
  301. }
  302. else {
  303. return true;
  304. }
  305. $items = Model('member')->getMemberInfo($cond);
  306. return (empty($items) == true);
  307. }
  308. }
  309. static public function match_price($rate_moneys)
  310. {
  311. if(empty($rate_moneys)) return false;
  312. $scaler = new \bonus\scaler($rate_moneys);
  313. return $scaler->calc();
  314. }
  315. }