FissionbonusModel.class.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class FissionbonusModel{
  16. /**
  17. *显示订单状态单位分页
  18. */
  19. public function show_fission_page($search){
  20. $sql = "select * from ".C('DB_PREFIX')."fissionbonus as f ,".C('DB_PREFIX')."member as m
  21. where f.member_id = m.member_id ";
  22. $sql_count = "select count(f.id) as count from ".C('DB_PREFIX')."fissionbonus as f ,".C('DB_PREFIX')."member as m
  23. where f.member_id = m.member_id ";
  24. if(isset($search['name']) && !empty($search['name']) ){
  25. $sql.=" and m.uname like '%".$search['name']."%'";
  26. $sql_count.=" and m.uname like '%".$search['name']."%'";
  27. }
  28. $count_arr = M()->query($sql_count);
  29. $count = $count_arr[0]['count'];
  30. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  31. $show = $Page->show();// 分页显示输出
  32. $sql.=' ORDER BY f.id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  33. $list=M()->query($sql);
  34. foreach($list as $key => $val)
  35. {
  36. $money = M('fissionbonus_order')->where( array('fissionbonus_id' => $val['id']) )->sum('money');
  37. $order_list = M('fissionbonus_order')->where( array('fissionbonus_id' => $val['id']) )->order('id asc')->select();
  38. foreach($order_list as $kk => $vv)
  39. {
  40. $mb_info = M('member')->field('uname,avatar')->where( array('member_id' => $vv['member_id']) )->find();
  41. $vv['mb_info'] = $mb_info;
  42. $order_list[$kk] = $vv;
  43. }
  44. $val['money'] = $money;
  45. $val['order_list'] = $order_list;
  46. $list[$key] = $val;
  47. }
  48. return array(
  49. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  50. 'list'=>$list,
  51. 'page'=>$show
  52. );
  53. }
  54. /**
  55. 开启一个今日签到
  56. **/
  57. public function open_new_bonus($member_id)
  58. {
  59. $end_time = strtotime( date('Y-m-d').' 00:00:00' ) + 86400;
  60. $bonus_game_time_arr = M('config')->where( array('name' =>'bonus_game_time') )->find();
  61. $bonus_count_arr = M('config')->where( array('name' =>'bonus_count') )->find();
  62. $bonus_money_arr = M('config')->where( array('name' =>'bonus_money') )->find();
  63. $bonus_ser_arr = $this->_rand_fen_bonus($bonus_money_arr['value'], $bonus_count_arr['value']);
  64. $fissionbonus_data = array();
  65. $fissionbonus_data['member_id'] = $member_id;
  66. $fissionbonus_data['count'] = $bonus_count_arr['value'];
  67. $fissionbonus_data['bonus_ser'] = serialize($bonus_ser_arr);
  68. $fissionbonus_data['state'] = 0;
  69. $fissionbonus_data['begin_time'] = time();
  70. $fissionbonus_data['end_time'] = $end_time;
  71. //$fissionbonus_data['end_time'] = time()+3600 * $bonus_game_time_arr['value'];
  72. $res = M('fissionbonus')->add($fissionbonus_data);
  73. return $res;
  74. }
  75. /**
  76. 将签到金分拆成等分
  77. **/
  78. private function _rand_fen_bonus($money_total = 1, $personal_num = 2)
  79. {
  80. //$money_total=100;
  81. //$personal_num=10;
  82. $min_money=0.01;
  83. $money_right=$money_total;
  84. $randMoney=[];
  85. for($i=1;$i<=$personal_num;$i++){
  86. if($i== $personal_num){
  87. $money=$money_right;
  88. }else{
  89. $max=$money_right*100 - ($personal_num - $i ) * $min_money *100;
  90. $money= rand($min_money*100,$max) /100;
  91. $money=sprintf("%.2f",$money);
  92. }
  93. $randMoney[]=$money;
  94. $money_right=$money_right - $money;
  95. $money_right=sprintf("%.2f",$money_right);
  96. }
  97. sort($randMoney);
  98. return $randMoney;
  99. }
  100. /**
  101. 对订单开始分红包
  102. **/
  103. public function get_fissionbonus_order($bonus_id, $member_id)
  104. {
  105. $fissionbonus_info = M('fissionbonus')->where( array('id' => $bonus_id) )->find();
  106. if($fissionbonus_info['state'] == 1)
  107. {
  108. return 0;
  109. }else{
  110. $bonus_ser = unserialize($fissionbonus_info['bonus_ser']);
  111. $is_self = 0;
  112. if($fissionbonus_info['member_id'] == $member_id)
  113. {
  114. $is_self = 1;
  115. }
  116. $count_order = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->count();
  117. $money = $bonus_ser[ $count_order ];
  118. $is_notify = 0;
  119. if($is_self == 1)
  120. {
  121. $is_notify = 1;
  122. }
  123. //判断是否两次
  124. $fissionbonus_order_info = M('fissionbonus_order')->where( array('fissionbonus_id' =>$bonus_id,'member_id' =>$member_id ) )->find();
  125. if( !empty($fissionbonus_order_info) )
  126. {
  127. return 0;
  128. }else{
  129. $fissionbonus_order_data = array();
  130. $fissionbonus_order_data['fissionbonus_id'] = $bonus_id;
  131. $fissionbonus_order_data['member_id'] = $member_id;
  132. $fissionbonus_order_data['is_self'] = $is_self;
  133. $fissionbonus_order_data['is_notify'] = $is_notify;
  134. $fissionbonus_order_data['money'] = $money;
  135. $fissionbonus_order_data['addtime'] = time();
  136. M('fissionbonus_order')->add($fissionbonus_order_data);
  137. //开始赠送金额
  138. if( $is_self == 1 )
  139. {
  140. $this->send_member_fissionbonus($member_id,$member_id, $bonus_id, $money,1);
  141. }else{
  142. //$this->send_member_fissionbonus($member_id, $bonus_id, $money,3); send_member_id
  143. $this->send_member_fissionbonus($fissionbonus_info['member_id'],$member_id, $bonus_id, $money,2);
  144. }
  145. $count_order = M('fissionbonus_order')->where( array('fissionbonus_id' => $bonus_id) )->count();
  146. if($fissionbonus_info['count']<=$count_order)
  147. {
  148. M('fissionbonus')->where( array('id' => $bonus_id) )->save( array('state' => 1) );
  149. }
  150. return $money;
  151. }
  152. }
  153. }
  154. /**
  155. 给会员赠送红包金额
  156. 1:自己签到,2:别人帮忙金额得到 3,给别人点赞得到金额
  157. **/
  158. private function send_member_fissionbonus($member_id =0,$send_member_id=0,$fissionbonus_id =0, $money = 0,$type=1)
  159. {
  160. //fissionbonus_flow
  161. $fissionbonus_flow_data = array();
  162. $fissionbonus_flow_data['fissionbonus_id'] = $fissionbonus_id;
  163. $fissionbonus_flow_data['member_id'] = $member_id;
  164. $fissionbonus_flow_data['send_member_id'] = $send_member_id;
  165. $fissionbonus_flow_data['money'] = $money;
  166. $fissionbonus_flow_data['type'] = $type;
  167. $fissionbonus_flow_data['addtime'] = time();
  168. $flow_id = M('fissionbonus_flow')->add($fissionbonus_flow_data);
  169. D('Home/member')->charge_member_account($member_id, $money, 6, $flow_id);
  170. }
  171. }
  172. ?>