MemberModel.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. class MemberModel extends Model{
  5. //结算页面中新增用户
  6. function add_member(){
  7. $d['uname']=I('uname');
  8. $d['name']=I('name');
  9. $d['email']=I('email');
  10. $d['pwd'] =think_ucenter_encrypt($_POST['password'],C('PWD_KEY'));
  11. $d['telephone']=I('telephone');
  12. $d['status']=1;
  13. $d['create_time']=time();
  14. $id=$this->add($d);
  15. if($id){
  16. //写入地址表
  17. $a['member_id']=$id;
  18. $a['address']=I('address');
  19. $a['city_id']=I('city_id');
  20. $a['name']=I('name');
  21. $a['telephone']=I('telephone');
  22. $a['country_id']=I('country_id');
  23. $a['province_id']=I('province_id');
  24. $aid=M('Address')->add($a);
  25. //会员表更新地址
  26. if($aid){
  27. $address['address_id']=$aid;
  28. $address['member_id']=$id;
  29. $this->save($address);
  30. }
  31. }
  32. return $id;
  33. }
  34. function add_address(){
  35. //写入地址表
  36. $a['member_id']=session('user_auth.uid');
  37. $a['address']=I('address');
  38. $a['city_id']=I('city_id');
  39. $a['name']=I('name');
  40. $a['telephone']=I('telephone');
  41. $a['country_id']=I('country_id');
  42. $a['province_id']=I('province_id');
  43. $aid=M('Address')->add($a);
  44. //会员表更新地址
  45. if($aid){
  46. $address['address_id']=$aid;
  47. $address['member_id']=session('user_auth.uid');
  48. M('Member')->save($address);
  49. }
  50. return $aid;
  51. }
  52. function get_address_id($uid){
  53. $aid=$this->field('address_id')->where('member_id='.$uid)->find();
  54. return $aid['address_id'];
  55. }
  56. /**
  57. 给会员充值
  58. **/
  59. public function charge_member_account($member_id, $money, $type, $trans_id)
  60. {
  61. $member_charge_flow_data = array();
  62. $member_charge_flow_data['member_id'] = $member_id;
  63. $member_charge_flow_data['trans_id'] = $trans_id;
  64. $member_charge_flow_data['money'] = $money;
  65. $member_charge_flow_data['state'] = 6;
  66. $member_charge_flow_data['charge_time'] = time();
  67. $member_charge_flow_data['add_time'] = time();
  68. M('member_charge_flow')->add($member_charge_flow_data);
  69. M('member')->where( array('member_id' => $member_id) )->setInc('account_money', $money);
  70. }
  71. /**
  72. 计算用户佣金
  73. **/
  74. function sum_member_commiss($where = array())
  75. {
  76. $total_commiss = M('member_commiss_order')->where($where)->sum('money');
  77. return $total_commiss;
  78. }
  79. /**
  80. 计算用户佣金
  81. **/
  82. function sum_member_fen_commiss($where = array())
  83. {
  84. $total_commiss = M('member_sharing_order')->where($where)->sum('money');
  85. return $total_commiss;
  86. }
  87. function getAddress($uid) {
  88. if(!isset($uid)){
  89. return false;
  90. }
  91. $sql="SELECT DISTINCT province_id,city_id,country_id FROM ".C('DB_PREFIX')."address WHERE member_id=".$uid;
  92. $area_id=M()->query($sql);
  93. foreach ($area_id as $k => $v) {
  94. foreach ($v as $key => $value) {
  95. $area[]=$value;
  96. }
  97. }
  98. if(!isset($area)){
  99. return;
  100. }
  101. //地区的id,去除重复的
  102. $arr=array_unique($area);
  103. $aid=implode(',',$arr);
  104. $sql="SELECT area_name,area_id FROM ".C('DB_PREFIX')."area WHERE area_id IN (".$aid.")";
  105. //地区的名字
  106. $area_name=M()->query($sql);
  107. //取得会员的所有地址
  108. $address=M('Address')->where('member_id='.$uid)->select();
  109. foreach ($address as $key => $v) {
  110. $a[$v['address_id']]=$v;
  111. }
  112. foreach ($a as $k => $v) {
  113. foreach ($area_name as $key => $value) {
  114. if($v['province_id']==$value['area_id']){
  115. $a[$k]['province']=$value['area_name'];
  116. }
  117. if($v['city_id']==$value['area_id']){
  118. $a[$k]['city']=$value['area_name'];
  119. }
  120. if($v['country_id']==$value['area_id']){
  121. $a[$k]['country']=$value['area_name'];
  122. }
  123. }
  124. }
  125. return $a;
  126. }
  127. }