UserPoint.php 3.9 KB

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