SocietyIncomeAction.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class SocietyIncomeAction extends CommonAction
  3. {
  4. public function index(){
  5. $m_config = load_auto_cache('m_config');
  6. $rate = floatval($m_config['society_public_rate']);
  7. $id = intval($_REQUEST['id']);
  8. $name = $_REQUEST['name'];
  9. $model = M('society');
  10. $field = 's.id,s.name,s.logo,s.memo,s.status,(u.ticket-u.refund_ticket) as ticket,((u.ticket-u.refund_ticket)*s.refund_rate) as money';
  11. $table = DB_PREFIX."society as s,".DB_PREFIX."user as u";
  12. $where = 's.user_id=u.id and s.status<>0 and s.status<>4 ';
  13. $parameter = 's.user_id=u.id';
  14. if ($id > 0){
  15. $where .= ' and s.id='.$id;
  16. $parameter .= '&s.id='.$id;
  17. }
  18. if ($name != ''){
  19. $where .= ' and s.name like \'%' . addslashes($name) . '%\'';
  20. $parameter .= '&s.name like \'%' . addslashes($name) . '%\'';
  21. }
  22. $count = $model->table($table)->where($where)->count();
  23. if ($count){
  24. $sql = "select $field from $table where $where order by s.id";
  25. $list = $this->_Sql_list($model,$sql,'&'.$parameter,'',0);
  26. foreach ($list as $key => $value){
  27. $list[$key]['logo'] = get_spec_image($value['logo']);
  28. }
  29. }
  30. $this->assign('list', $list);
  31. $this->display();
  32. }
  33. public function submit_refund(){
  34. $id = intval($_REQUEST['id']);
  35. if ($id == 0){
  36. $this->error("id不能为空");
  37. }
  38. $society_info = M('society')->where("id=".$id)->field('user_id,name,refund_rate')->find();
  39. $refund_exist = M('user_refund')->where('user_id='.$society_info['user_id']." and (is_pay =0 or is_pay=1)")->getField('id');
  40. if ($refund_exist){
  41. $this->error("这个公会还有未处理的提现");
  42. }
  43. //若公会有设置提现比例,则使用设置的提现比例;若没有,使用平台统一的公会提现比例。
  44. if(floatval($society_info['refund_rate']) > 0){
  45. $rate = floatval($society_info['refund_rate']);
  46. }else{
  47. $m_config = load_auto_cache("m_config");//初始化手机端配置
  48. $rate = floatval($m_config['society_public_rate']);
  49. }
  50. $user_info = M('user')->where('id='.$society_info['user_id'])->field('ticket,refund_ticket')->find();
  51. $refund_data = array();
  52. $refund_data['ticket'] = $user_info['ticket'] - $user_info['refund_ticket'];
  53. if ($refund_data['ticket'] > 0){
  54. $refund_data['money'] = floatval($refund_data['ticket'] * $rate);
  55. $refund_data['user_bank_id'] = -1;
  56. $refund_data['user_id'] = $society_info['user_id'];
  57. $refund_data['create_time'] = NOW_TIME;
  58. $refund_data['memo'] = $society_info['name']."公会提现";
  59. $refund_data['withdrawals_type'] = 2;
  60. $refund_data['is_pay'] = 0;
  61. $res = M('user_refund')->add($refund_data);
  62. if ($res){
  63. save_log($society_info['name'] . "公会提现" . $refund_data['money'] . "成功", 1);
  64. $this->success("提现成功");
  65. }else{
  66. save_log($society_info['name'] . "公会提现" . $refund_data['money'] . "失败", 0);
  67. $this->success("提现失败");
  68. }
  69. }else{
  70. $this->error("此公会可提现余额为0");
  71. }
  72. }
  73. }