UserPoint.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 app\admin\model\user\User;
  13. use app\admin\model\user\UserBill;
  14. use traits\ModelTrait;
  15. use basic\ModelBasic;
  16. use service\PHPExcelService;
  17. class UserPoint extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /*
  21. * 获取积分信息
  22. * */
  23. public static function systemPage($where){
  24. $model= new UserBill();
  25. if($where['status']!='')UserBill::where('status',$where['status']);
  26. if($where['title']!='')UserBill::where('title','like',"%$where[status]%");
  27. $model->where('category','integral')->select();
  28. return $model::page($model);
  29. }
  30. /*
  31. *
  32. * 异步获取积分信息
  33. * */
  34. public static function getpointlist($where){
  35. $list=self::setWhere($where)
  36. ->order('a.add_time desc')
  37. ->field(['a.*','b.nickname'])
  38. ->page((int)$where['page'],(int)$where['limit'])
  39. ->select()
  40. ->toArray();
  41. foreach ($list as $key=>$item){
  42. $list[$key]['add_time']=date('Y-m-d', $item['add_time']);
  43. }
  44. $count=self::setWhere($where)->field(['a.*','b.nickname'])->count();
  45. return ['count'=>$count,'data'=>$list];
  46. }
  47. //生成Excel表格并下载
  48. public static function SaveExport($where){
  49. $list=self::setWhere($where)->field(['a.*','b.nickname'])->select();
  50. $Export=[];
  51. foreach ($list as $key=>$item){
  52. $Export[]=[
  53. $item['id'],
  54. $item['title'],
  55. $item['balance'],
  56. $item['number'],
  57. $item['mark'],
  58. $item['nickname'],
  59. date('Y-m-d H:i:s',$item['add_time']),
  60. ];
  61. }
  62. PHPExcelService::setExcelHeader(['编号','标题','积分余量','明细数字','备注','用户微信昵称','添加时间'])
  63. ->setExcelTile('积分日志','积分日志'.time(),'生成时间:'.date('Y-m-d H:i:s',time()))
  64. ->setExcelContent($Export)
  65. ->ExcelSave();
  66. }
  67. public static function setWhere($where){
  68. $model=UserBill::alias('a')->join('__USER__ b','a.uid=b.uid','left')->where('a.category','integral');
  69. $time['data']='';
  70. if($where['start_time']!='' && $where['end_time']!=''){
  71. $time['data']=$where['start_time'].' - '.$where['end_time'];
  72. }
  73. $model=self::getModelTime($time,$model,'a.add_time');
  74. if($where['nickname']!=''){
  75. $model=$model->where('b.nickname|b.uid','like',$where['nickname']);
  76. }
  77. return $model;
  78. }
  79. //获取积分头部信息
  80. public static function getUserpointBadgelist($where){
  81. return [
  82. [
  83. 'name'=>'总积分',
  84. 'field'=>'个',
  85. 'count'=>self::setWhere($where)->sum('a.number'),
  86. 'background_color'=>'layui-bg-blue',
  87. ],
  88. [
  89. 'name'=>'客户签到次数',
  90. 'field'=>'个',
  91. 'count'=>self::setWhere($where)->where('a.type','sign')->group('a.uid')->count(),
  92. 'background_color'=>'layui-bg-cyan',
  93. ],
  94. [
  95. 'name'=>'签到送出积分',
  96. 'field'=>'个',
  97. 'count'=>self::setWhere($where)->where('a.type','sign')->sum('a.number'),
  98. 'background_color'=>'layui-bg-cyan',
  99. ],
  100. [
  101. 'name'=>'使用积分',
  102. 'field'=>'个',
  103. 'count'=>self::setWhere($where)->where('a.type','deduction')->sum('a.number'),
  104. 'background_color'=>'layui-bg-cyan',
  105. ],
  106. ];
  107. }
  108. }