UserPoint.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lofate
  5. * Date: 201/12/20
  6. * Time: 09:08
  7. */
  8. namespace app\models\user;
  9. use crmeb\traits\ModelTrait;
  10. use crmeb\basic\BaseModel;
  11. class UserPoint extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'user_point';
  23. use ModelTrait;
  24. /*
  25. * 获取积分信息
  26. * */
  27. public static function systemPage($where)
  28. {
  29. $model = new UserBill();
  30. if ($where['status'] != '') UserBill::where('status', $where['status']);
  31. if ($where['title'] != '') UserBill::where('title', 'like', "%$where[status]%");
  32. $model->where('category', 'integral')->select();
  33. return $model::page($model);
  34. }
  35. /*
  36. *
  37. * 异步获取积分信息
  38. * */
  39. public static function getpointlist($where)
  40. {
  41. $list = self::setWhere($where)
  42. ->order('a.add_time desc')
  43. ->field(['a.*', 'b.nickname'])
  44. ->page((int)$where['page'], (int)$where['limit'])
  45. ->select()
  46. ->toArray();
  47. foreach ($list as $key => $item) {
  48. $list[$key]['add_time'] = date('Y-m-d', $item['add_time']);
  49. }
  50. $count = self::setWhere($where)->field(['a.*', 'b.nickname'])->count();
  51. return ['count' => $count, 'list' => $list];
  52. }
  53. //查出要导出数据
  54. public static function exportData($where)
  55. {
  56. $list = self::setWhere($where)->field(['a.*', 'b.nickname'])->select();
  57. return $list;
  58. }
  59. public static function setWhere($where)
  60. {
  61. $model = UserBill::alias('a')->join('user b', 'a.uid=b.uid', 'left')->where('a.category', 'integral');
  62. $time['data'] = '';
  63. if ($where['start_time'] != '' && $where['end_time'] != '') {
  64. $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
  65. }
  66. $model = self::getModelTime($time, $model, 'a.add_time');
  67. if ($where['nickname'] != '') {
  68. $model = $model->where('b.nickname|b.uid', 'like', $where['nickname']);
  69. }
  70. if ($where['mer_id'] != '') {
  71. $model = $model->where('b.mer_id', $where['mer_id']);
  72. }
  73. return $model;
  74. }
  75. //获取积分头部信息
  76. public static function getUserpointBadgelist($where)
  77. {
  78. return [
  79. [
  80. 'col'=>6,
  81. 'count' => self::setWhere($where)->sum('a.number'),
  82. 'name' => '总积分(个)',
  83. ],
  84. [
  85. 'col'=>6,
  86. 'count' => self::setWhere($where)->where('a.type', 'sign')->group('a.uid')->count(),
  87. 'name' => '客户签到次数(次)',
  88. ],
  89. [
  90. 'col'=>6,
  91. 'count' => self::setWhere($where)->where('a.type', 'sign')->sum('a.number'),
  92. 'name' => '签到送出积分(个)',
  93. ],
  94. [
  95. 'col'=>6,
  96. 'count' => self::setWhere($where)->where('a.type', 'deduction')->sum('a.number'),
  97. 'name' => '使用积分(个)',
  98. ],
  99. ];
  100. }
  101. }