Gacha.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\models\user;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. class Gacha extends BaseModel
  6. {
  7. /**
  8. * 数据表主键
  9. * @var string
  10. */
  11. protected $pk = 'id';
  12. /**
  13. * 模型名称
  14. * @var string
  15. */
  16. protected $name = 'gacha';
  17. use ModelTrait;
  18. public static function createCode($uid)
  19. {
  20. do {
  21. $str = md5($uid . time() . rand(1000000, 9999999)) . md5($uid);
  22. } while (Gacha::be(['unicode' => $str]));
  23. return $str;
  24. }
  25. public static function getList($where): array
  26. {
  27. $model = new self();
  28. if (isset($where['status']) && $where['status'] != '') {
  29. if ($where['status'] == 1) {
  30. $model = $model->where('status', 1);
  31. } elseif ($where['status'] == 2) {
  32. $model = $model->where('status', 0);
  33. $model = $model->where('limit_time', '<', time());
  34. } elseif ($where['status'] == 0) {
  35. $model = $model->where('status', 0);
  36. $model = $model->where('limit_time', '>=', time());
  37. }
  38. }
  39. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  40. foreach ($data as &$v) {
  41. $user = User::get($v['uid']);
  42. $v['user'] = $user['nickname'] . "[{$user['uid']}]";
  43. $v['add_time_text'] = date('Y-m-d H:i:s', $v['add_time']);
  44. $v['limit_time_text'] = date('Y-m-d H:i:s', $v['limit_time']);
  45. $v['award_text'] = ($v['award_type'] == 1 ? ($v['award'] . '积分') : $v['award']);
  46. $v['status_text'] = ($v['status'] == 1 ? "已兑换" : ($v['limit_time'] < time() ? "已过期" : "待兑换"));
  47. }
  48. $count = $model->count();
  49. return compact('count', 'data');
  50. }
  51. }