bonus_helper.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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/bonus/util.php');
  9. require_once (BASE_ROOT_PATH . '/helper/bonus/type.php');
  10. require_once (BASE_ROOT_PATH . '/helper/bonus/user_bonus.php');
  11. require_once (BASE_ROOT_PATH . '/helper/bonus/generator.php');
  12. require_once (BASE_ROOT_PATH . '/helper/bonus/grab.php');
  13. require_once (BASE_ROOT_PATH . '/helper/bonus/bind.php');
  14. require_once (BASE_ROOT_PATH . '/helper/bonus/factory.php');
  15. require_once (BASE_ROOT_PATH . '/helper/bonus/manager.php');
  16. require_once (BASE_ROOT_PATH . '/helper/field_helper.php');
  17. require_once (BASE_ROOT_PATH . '/helper/predeposit_helper.php');
  18. class bonus_helper
  19. {
  20. static public function filter_type($type_info) {
  21. $type = \bonus\type::crate_by_paramer($type_info);
  22. $fileds = 'type_sn,type_bless,send_type,sender_name,total_amount,total_num,max_amount,grabed_num,binded_num,send_start_date,binded_over,binded_period,grab_lastime';
  23. $ret = array();
  24. field_helper::copy_column($ret,$type_info,$fileds);
  25. $ret['time_out'] = \bonus\manager::grab_period_timeout;
  26. if($type->binded_over()) {
  27. $ret['binded_over'] = 1;
  28. } else {
  29. $ret['binded_over'] = 0;
  30. }
  31. $type_sn = $type->getType_sn();
  32. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}";
  33. $ret['url'] = $url;
  34. return $ret;
  35. }
  36. static public function filter_bonus($bonus_info) {
  37. $fileds = 'bonus_sn,bonus_value,user_name,user_mobile,user_comment,get_time,bonus_status';
  38. $ret = array();
  39. field_helper::copy_column($ret,$bonus_info,$fileds);
  40. if(empty($bonus_info['user_name'])) {
  41. $ret['user_name'] = substr_replace($bonus_info['user_mobile'], '****', 3, 4);
  42. }
  43. return $ret;
  44. }
  45. static public function isFixed($send_type) {
  46. return ($send_type == \bonus\type::fixed_amount);
  47. }
  48. static public function isRandom($send_type) {
  49. return ($send_type == \bonus\type::random_amount);
  50. }
  51. static public function make_bonus($param)
  52. {
  53. $ret = \bonus\factory::make_bonus($param);
  54. return $ret;
  55. }
  56. static public function get_typeinfo($type_sn)
  57. {
  58. $manager = new \bonus\manager();
  59. return $manager->get_typeinfo($type_sn);
  60. }
  61. static public function get_mine_by_typesn($type_sn) {
  62. $manager = new \bonus\manager();
  63. return $manager->get_mine_by_typesn($type_sn);
  64. }
  65. static public function get_mine_by_bonussn($bonus_sn) {
  66. $manager = new \bonus\manager();
  67. return $manager->get_mine_by_bonussn($bonus_sn);
  68. }
  69. static public function grab_bonus($type_sn)
  70. {
  71. $manager = new \bonus\manager();
  72. return $manager->grab_bonus($type_sn);
  73. }
  74. static public function bind_bonus($bonus_sn,$session_id,$mobile,&$new_bonus_sn)
  75. {
  76. try
  77. {
  78. $manager = new \bonus\manager();
  79. return $manager->bind_bonus($bonus_sn,$session_id,$mobile,$new_bonus_sn);
  80. } catch (Exception $ex) {
  81. return array($ex->getCode(),$ex->getMessage());
  82. }
  83. }
  84. static public function comment($bonus_sn,$comment)
  85. {
  86. try
  87. {
  88. $manager = new \bonus\manager();
  89. return $manager->comment($bonus_sn,$comment);
  90. } catch (Exception $ex) {
  91. return false;
  92. }
  93. }
  94. static public function topup_bonus($mobile)
  95. {
  96. $mod_bonus = Model('user_bonus');
  97. $bind_bonus = $mod_bonus->getAllBind($mobile);
  98. if(empty($bind_bonus)) {
  99. return false;
  100. }
  101. $manager = new \bonus\manager();
  102. $pd_helper = new predeposit_helper();
  103. $bonusex = array();
  104. foreach($bind_bonus as $val)
  105. {
  106. $type_id = $val['type_id'];
  107. $type = \bonus\type::create_by_id($type_id);
  108. try
  109. {
  110. $info = sprintf("来自%s的红包.",$val['sender_name']);
  111. Db::beginTransaction();
  112. $pd_helper->bonus_add_money($val['bonus_value'],$val['bonus_sn'],$type->sender_name(),$info);
  113. if($manager->topup($mod_bonus,$val) === false) {
  114. throw new Exception();
  115. } else {
  116. $bonus['mine_bonus'] = $val;
  117. array_push($bonusex,$val);
  118. }
  119. Db::commit();
  120. } catch (Exception $ex) {
  121. Db::rollback();
  122. }
  123. }
  124. if(empty($bonusex)) {
  125. return false;
  126. } else {
  127. return $bonusex;
  128. }
  129. }
  130. }