1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\models\user;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- class Gacha extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'gacha';
- use ModelTrait;
- public static function createCode($uid)
- {
- do {
- $str = md5($uid . time() . rand(1000000, 9999999)) . md5($uid);
- } while (Gacha::be(['unicode' => $str]));
- return $str;
- }
- public static function getList($where): array
- {
- $model = new self();
- if (isset($where['status']) && $where['status'] != '') {
- if ($where['status'] == 1) {
- $model = $model->where('status', 1);
- } elseif ($where['status'] == 2) {
- $model = $model->where('status', 0);
- $model = $model->where('limit_time', '<', time());
- } elseif ($where['status'] == 0) {
- $model = $model->where('status', 0);
- $model = $model->where('limit_time', '>=', time());
- }
- }
- $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
- foreach ($data as &$v) {
- $user = User::get($v['uid']);
- $v['user'] = $user['nickname'] . "[{$user['uid']}]";
- $v['add_time_text'] = date('Y-m-d H:i:s', $v['add_time']);
- $v['limit_time_text'] = date('Y-m-d H:i:s', $v['limit_time']);
- $v['award_text'] = ($v['award_type'] == 1 ? ($v['award'] . '积分') : $v['award']);
- $v['status_text'] = ($v['status'] == 1 ? "已兑换" : ($v['limit_time'] < time() ? "已过期" : "待兑换"));
- }
- $count = $model->count();
- return compact('count', 'data');
- }
- }
|