| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\Ulogic;
- use App\Module\Ulogic\Model\UserTime;
- /**
- * 用户计数器
- *
- */
- class Times
- {
- /**
- * 增加计数
- * @param $user_id
- * @param $stype
- * @param $sid
- * @param $times
- * @return int
- */
- static public function add($user_id, $stype, $sid, $times = 1)
- {
- $old = UserTime::query()->where([
- 'user_id' => $user_id,
- 'stype' => $stype,
- 'sid' => $sid
- ])->first();
- if (!$old) {
- $old = new UserTime();
- $old->user_id = $user_id;
- $old->stype = $stype;
- $old->sid = $sid;
- }
- $old->number += $times;
- $old->save();
- // dump($old->stype,$stype);
- return $old->number;
- }
- /**
- * 检查是否超过限制
- * @param $user_id
- * @param $stype
- * @param $sid
- * @param $times
- * @return bool
- */
- static public function check($user_id, $stype, $sid, $times)
- {
- $old = UserTime::query()->where([
- 'user_id' => $user_id,
- 'stype' => $stype,
- 'sid' => $sid
- ])->first();
- if (!$old) {
- return true;
- }
- if ($old->number >= $times) {
- return false;
- }
- return true;
- }
- }
|