| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Module\Ulogic;
- use App\Module\Ulogic\Models\UserDaytime;
- /**
- * 用户 日计数器
- *
- */
- class DayTimes
- {
- /**
- * 增加计数
- * @param $user_id
- * @param $stype
- * @param $sid
- * @param $times
- * @return int
- */
- static public function add($user_id, $stype, $sid,$day=null, $times = 1)
- {
- if ($day === null) {
- $day = date('Ymd');
- }
- $old = UserDaytime::query()->where([
- 'user_id' => $user_id,
- 'stype' => $stype,
- 'sid' => $sid,
- 'day' => $day
- ])->first();
- if (!$old) {
- $old = new UserDaytime();
- $old->user_id = $user_id;
- $old->stype = $stype;
- $old->sid = $sid;
- $old->day = $day;
- }
- $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, $day = null,$times =0)
- {
- if ($day === null) {
- $day = date('Ymd');
- }
- /**
- * @var UserDaytime $old
- */
- $old = UserDaytime::query()->where([
- 'user_id' => $user_id,
- 'stype' => $stype,
- 'sid' => $sid,
- 'day' => $day
- ])->first();
- if (!$old) {
- return true;
- }
- if ($old->number >= $times) {
- return false;
- }
- return true;
- }
- }
|