| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Services;
- use App\Constants\HttpStatus;
- use App\Models\ActivityReward;
- use App\Models\Role;
- use Exception;
- class ActivityRewardService extends BaseService
- {
- public static string $MODEL = ActivityReward::class;
- /**
- * @description: 查询单条数据
- * @param array $search
- * @return ActivityReward|null
- */
- public static function findOne(array $search): ActivityReward|null
- {
- return static::$MODEL::where(static::getWhere($search))->first();
- }
- public static function getWhere(array $search = []): array
- {
- $where = [];
- if (isset($search['title']) && !empty($search['title'])) {
- $where[] = ['title', 'like', "%{$search['title']}%"];
- }
- return $where;
- }
- public static function deleteAll(array $search = []): bool
- {
- $count = static::$MODEL::where(static::getWhere($search))->delete();
- if ($count < 1) throw new Exception('删除失败',HttpStatus::CUSTOM_ERROR);
- return true;
- }
- /**
- * Update or create
- * @param array $params
- * @return bool
- * @throws Exception
- */
- public static function submit(array $params = []): bool
- {
- if (isset($params['start_time']))
- $params['start_time'] = strtotime($params['start_time'] . " 00:00:00");
- if (isset($params['end_time']))
- $params['end_time'] = strtotime($params['end_time'] . " 23:59:59");
- if (!empty($params['id'])) {
- $info = static::findOne(['id' => $params['id']]);
- if (!$info) throw new Exception("操作失败",HttpStatus::CUSTOM_ERROR);
- $info->update($params);
- } else {
- static::$MODEL::create($params);
- }
- return true;
- }
- }
|