setting.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/7/25
  6. * Time: 下午8:48
  7. */
  8. namespace ugc;
  9. use bonus\type;
  10. use session_helper;
  11. use bonus_helper;
  12. use predeposit_helper;
  13. class bonus_builder
  14. {
  15. private $rate;
  16. private $amount;
  17. private $num;
  18. private $sendtype;
  19. private $bless;
  20. private $deadline;
  21. public function __construct($content)
  22. {
  23. $this->rate = intval($content['rate']);
  24. $this->amount = $content['amount'];
  25. $this->num = $content['num'];
  26. $this->sendtype = intval($content['bonus_type']);
  27. $this->bless = $content['bless'];
  28. $this->deadline = $content['send_end_date'];
  29. }
  30. private function fill_param()
  31. {
  32. $param['make_type'] = type::MakeVoteType;
  33. $param['type_name'] = $this->bless;
  34. $param['type_bless'] = $this->bless;
  35. $param['send_type'] = $this->sendtype;
  36. $param['grab_type'] = type::GrabType_All;
  37. $param['usable_days'] = type::def_usable_days;
  38. $param['rate_money'][] = ['amount' => $this->amount,'num' => $this->num, 'rate' => $this->rate];
  39. $param['sender_id'] = $_SESSION['member_id'];
  40. $param['sender_mobile'] = $_SESSION['member_mobile'];
  41. $param['sender_name'] = session_helper::nickname();
  42. $param['bonus_rate'] = $this->rate;
  43. $param['share_id'] = $_SESSION['cur_share_id'];
  44. $param['send_end_date'] = $this->deadline;
  45. return $param;
  46. }
  47. public function make()
  48. {
  49. $param = $this->fill_param();
  50. $type = bonus_helper::create_type_input($param);
  51. $pred = new predeposit_helper($_SESSION['member_id']);
  52. if(!$pred->person_enough($type->getTotal_amount(),$this->rate)) {
  53. return false;
  54. }
  55. $rate_moneys = [];
  56. if($type->isFixedAmount()) {
  57. $item['amount'] = $type->fixed_money();
  58. } else {
  59. $item['amount'] = $type->getTotal_amount();
  60. }
  61. $item['hold_amount'] = $type->getTotal_amount();
  62. $item['num'] = $type->getTotal_num();
  63. $item['rate'] = $this->rate;
  64. $rate_moneys[] = $item;
  65. $ret = $pred->make_vote_type($type->get_param(),$rate_moneys);
  66. if($ret === false) {
  67. return false;
  68. }
  69. else
  70. {
  71. $type_sn = $ret['type_sn'];
  72. return $type_sn;
  73. }
  74. }
  75. }
  76. class setting
  77. {
  78. const pub_type = 0;
  79. const friend_type = 1;
  80. const mine_type = 2;
  81. const day_seconds = 86400;
  82. private $mSetting;
  83. private $mSpecial;
  84. public function __construct($content, special $special)
  85. {
  86. $this->mSetting = $content;
  87. $this->mSpecial = $special;
  88. }
  89. private function has_bonus() {
  90. return ($this->mSetting['bonus'] == true);
  91. }
  92. private function bonus_param()
  93. {
  94. $result['amount'] = $this->mSetting['total_amount'];
  95. $result['rate'] = $this->mSetting['rate'];
  96. $result['num'] = 1;
  97. $result['bonus_type'] = \bonus\type::SendType_Fixed;
  98. $result['bless'] = $this->mSpecial->bless();
  99. $deadline = $this->mSpecial->deadline();
  100. if($deadline <= time()) {
  101. $deadline = time() + self::day_seconds * 30;
  102. }
  103. $result['send_end_date'] = $deadline;
  104. return $result;
  105. }
  106. private function per_amount() {
  107. return $this->mSetting['per_amount'];
  108. }
  109. private function make_bonus()
  110. {
  111. if($this->has_bonus())
  112. {
  113. $param = $this->bonus_param();
  114. $builder = new bonus_builder($param);
  115. $result = $builder->make();
  116. return $result;
  117. }
  118. return false;
  119. }
  120. private function submit_rule()
  121. {
  122. $type_sn = $this->make_bonus();
  123. if($type_sn == false) {
  124. $result['bonus'] = false;
  125. }
  126. else {
  127. $result['bonus'] = true;
  128. $result['type_sn'] = $type_sn;
  129. $result['per_amount'] = $this->per_amount();
  130. }
  131. return serialize($result);
  132. }
  133. public function reader_type()
  134. {
  135. if(is_bool($this->mSetting['ispub'])) {
  136. $type = $this->mSetting['ispub'] ? 0 : 1;
  137. } else {
  138. $type = intval($this->mSetting['ispub']);
  139. }
  140. return $type;
  141. }
  142. public function appreciate() {
  143. return $this->mSetting['appreciate'] === true ? 1 : 0;
  144. }
  145. public function category_id() {
  146. return intval($this->mSetting['category_id']);
  147. }
  148. public function format()
  149. {
  150. $result['submit_rule'] = $this->submit_rule();
  151. $result['reader_type'] = $this->reader_type();
  152. $result['appreciate'] = $this->appreciate();
  153. $result['category_id'] = $this->category_id();
  154. return $result;
  155. }
  156. }