|
|
@@ -0,0 +1,61 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Services;
|
|
|
+
|
|
|
+use App\Constants\HttpStatus;
|
|
|
+use App\Constants\Util;
|
|
|
+use App\Models\ActivityReward;
|
|
|
+use App\Models\ActivityUser;
|
|
|
+use Exception;
|
|
|
+use Illuminate\Database\Eloquent\Builder;
|
|
|
+
|
|
|
+class ActivityUserService extends BaseService
|
|
|
+{
|
|
|
+ public static string $MODEL = ActivityUser::class;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static function getWhere(array $search = []): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ if (isset($search['id']) && !empty($search['id'])) {
|
|
|
+ $where[] = ['id', '=', $search['id']];
|
|
|
+ }
|
|
|
+ if (isset($search['title']) && !empty($search['title'])) {
|
|
|
+ $where[] = ['title', 'like', "%{$search['title']}%"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($search['status']) && !empty($search['status'])) {
|
|
|
+ $where[] = ['status', '=', $search['status']];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return $where;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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 (isset($params['detail_image']))
|
|
|
+ $params['detail_image'] = Util::replacePartInUrl($params['detail_image']);
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($params['id'])) {
|
|
|
+ $info = static::findOne(['id' => $params['id']]);
|
|
|
+ if (!$info) throw new Exception("操作失败", HttpStatus::CUSTOM_ERROR);
|
|
|
+ $info->update($params);
|
|
|
+ } else {
|
|
|
+ $info = static::$MODEL::create($params);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|