MoneyLogModel.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * 用户模型
  4. */
  5. namespace app\common\model;
  6. use think\Model;
  7. class MoneyLogModel extends Model
  8. {
  9. protected $name = "money_log";
  10. /**
  11. * 记录
  12. * @param $param
  13. * @return array
  14. * @throws \think\db\exception\DbException
  15. */
  16. public function getLog ($param, $type = 0)
  17. {
  18. $type_conf = config('type.money');
  19. $where = [];
  20. if ($type > 0){
  21. $where[] = ['type', '=', $type];
  22. }
  23. $list = self::where('uid', $param->uid)
  24. ->where($where)
  25. ->withAttr('type', function ($value, $data) use ($type_conf) {
  26. return isset($type_conf[$value]) ? $type_conf[$value] : '未知类型';
  27. })
  28. ->order('id', 'desc')
  29. ->paginate($param->data['limit'])
  30. ->toArray();
  31. return $list['data'];
  32. return compact('list', 'history');
  33. }
  34. /**
  35. * 团队奖金
  36. * @param $param
  37. * @return array
  38. * @throws \think\db\exception\DbException
  39. */
  40. public function getTeamMoneyLog($param){
  41. $type_conf = config('type.money');
  42. $total = self::where('uid', $param->uid)
  43. ->whereIn('type', [5,7])->sum('money');
  44. $list = self::where('uid', $param->uid)
  45. ->whereIn('type', [5,7])
  46. ->withAttr('type', function ($value, $data) use ($type_conf) {
  47. return isset($type_conf[$value]) ? $type_conf[$value] : '未知类型';
  48. })
  49. ->order('id', 'desc')
  50. ->paginate($param->data['limit'])
  51. ->toArray();
  52. return ['list'=>$list['data'],'total'=>$total,'count'=>$list['total']];
  53. }
  54. }