MemberRecord.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\user;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\admin\model\user\MemberCard as MemberCardMode;
  15. use app\admin\model\user\MemberCardBatch;
  16. use app\admin\model\order\StoreOrder;
  17. /**
  18. * 会员设置 model
  19. * Class User
  20. * @package app\admin\model\user
  21. */
  22. class MemberRecord extends ModelBasic
  23. {
  24. use ModelTrait;
  25. public static function getPurchaseRecordList($where){
  26. $model = self::setWherePage(self::setWhere($where), $where, ['u.nickname', 'u.uid'], ['p.uid']);
  27. $model=$model->alias('p')->join('user u', 'p.uid=u.uid', 'left')->field('p.*,u.nickname');
  28. $list = $model ->page((int)$where['page'], (int)$where['limit'])
  29. ->order('p.add_time DESC')
  30. ->select()
  31. ->each(function ($item) {
  32. $item['overdue_time'] = date('Y-m-d H:i:s', $item['overdue_time']);
  33. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  34. if($item['type']==1){
  35. $item['price'] ='无';
  36. }
  37. if(!$item['type']){
  38. switch ($item['validity']){
  39. case 30:
  40. $item['title'] = '月卡';
  41. break;
  42. case 90:
  43. $item['title'] = '季卡';
  44. break;
  45. case 365:
  46. $item['title'] = '年卡';
  47. break;
  48. case -1:
  49. $item['title'] = '终身卡';
  50. break;
  51. default:
  52. $item['title'] = '免费';
  53. }
  54. }else{
  55. $item['title'] = '卡密';
  56. }
  57. if (!$item['code']) {
  58. $item['code'] = '无';
  59. }
  60. if($item['nickname']){
  61. $item['uid'] =$item['nickname'].'/'.$item['uid'];
  62. }else{
  63. $item['uid'] ='用户被删除/'.$item['uid'];
  64. }
  65. if($item['oid']){
  66. $order=StoreOrder::where('id',$item['oid'])->where('type',1)->field('pay_type')->find();
  67. if($order['pay_type']=='yue'){
  68. $item['source'] = '赠送';
  69. }else{
  70. $item['source'] = '购买';
  71. }
  72. }else{
  73. $item['source'] = '会员卡';
  74. }
  75. })->toArray();
  76. $count = self::setWherePage(self::setWhere($where), $where,['u.nickname', 'u.uid'], ['p.uid'])->alias('p')->join('user u', 'p.uid=u.uid', 'left')->count();
  77. return ['count' => $count, 'data' => $list];
  78. }
  79. /**
  80. * 设置搜索条件
  81. *
  82. */
  83. public static function setWhere($where)
  84. {
  85. $model=new self;
  86. if ($where['title'] != '') {
  87. $model = $model->where('p.uid|u.nickname','like',"%$where[title]%");
  88. }
  89. if ($where['type'] != '') {
  90. switch ($where['type']){
  91. case 1:
  92. $model=$model->where('p.validity',30)->where('p.type',0);
  93. break;
  94. case 2:
  95. $model=$model->where('p.validity',90)->where('p.type',0);
  96. break;
  97. case 3:
  98. $model=$model->where('p.validity',365)->where('p.type',0);
  99. break;
  100. case 4:
  101. $model=$model->where('p.validity','<',0)->where('p.type',0);
  102. break;
  103. case 5:
  104. $model=$model->where('p.type',1);
  105. break;
  106. case 6:
  107. $model=$model->where('p.type',0)->where('p.is_free',1);
  108. break;
  109. }
  110. }
  111. return $model;
  112. }
  113. public static function userOneRecord($uid=0){
  114. $model = new self;
  115. $model = $model->where('a.uid',$uid);
  116. $model = $model->alias('a');
  117. $model = $model->field('a.*,b.nickname');
  118. $model = $model->join('__USER__ b', 'b.uid=a.uid', 'LEFT');
  119. $model = $model->order('a.id desc');
  120. return self::page($model,function ($item){
  121. $item['overdue_time'] = date('Y-m-d H:i:s', $item['overdue_time']);
  122. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  123. if($item['type']==1){
  124. $item['price'] ='无';
  125. }
  126. if(!$item['type']){
  127. switch ($item['validity']){
  128. case 30:
  129. $item['title'] = '月卡';
  130. break;
  131. case 90:
  132. $item['title'] = '季卡';
  133. break;
  134. case 365:
  135. $item['title'] = '年卡';
  136. break;
  137. case -1:
  138. $item['title'] = '终身卡';
  139. break;
  140. default:
  141. $item['title'] = '免费';
  142. }
  143. }else{
  144. $item['title'] = '卡密';
  145. }
  146. if (!$item['code']) {
  147. $item['code'] = '无';
  148. }
  149. });
  150. }
  151. }