__('Normal'), 'use' => __('Use'), 'expire' => __('Expire')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getExpiretimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['expiretime']) ? $data['expiretime'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setExpiretimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } public function user() { return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** * 过期 * @param $user_id */ public function passVoucher($user_id) { $this->where([ "user_id" => $user_id, "status" => \E_VOUCHER_STATUS::Normal, ])->where("expiretime", "<=", time()) ->update(["status" => \E_VOUCHER_STATUS::Expire]); } public function fetchVoucher($user_id, $status, $page = 1, $size = 10) { return $this->where([ "user_id" => $user_id, ]) ->where("status", "<>", \E_VOUCHER_STATUS::Use) ->where("status", "in", $status) ->page($page) ->paginate($size); } public function fetchVoucherCount($user_id) { return $this->where([ "user_id" => $user_id, ]) ->where("status", "<>", \E_VOUCHER_STATUS::Use) ->count(); } }