1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Modules\Push\Models;
- use App\Consts\PushConst;
- use Illuminate\Database\Eloquent\Model;
- class QappPushTask extends Model
- {
- protected $table = 'qapp_push_task';
- protected $fillable = ['uid', 'package_id', 'type', 'title', 'content', 'url', 'num',
- 'status', 'providers', 'push_time', 'push_filter', 'push_result', 'select_user_status',
- 'qapp_account', 'pv', 'uv'];
- /**
- * @param $id
- * @return array
- */
- public static function getPushTaskById($id)
- {
- if (empty($id)) {
- return [];
- }
- return self::where('id', $id)->first();
- }
- /**
- * @param $id
- * @param $data
- * @return bool
- */
- public static function updatePushTask($id, $data): bool
- {
- if (empty($id) || empty($data)) {
- return false;
- }
- return self::where('id', $id)->update($data);
- }
- /**
- * 更新主任务状态
- * @param $id
- * @param $status
- * @param $result
- * @return bool
- */
- public static function updateMainTaskStatus($id, $status, $result = ''): bool
- {
- if (empty($id)) {
- return false;
- }
- $pushResult = is_string($result) ? $result : json_encode(compact('result'), JSON_UNESCAPED_UNICODE);
- $data = ['status' => $status, 'push_result' => $pushResult, 'updated_at' => date('Y-m-d H:i:s')];
- return self::where('id', $id)->update($data);
- }
- /**
- * @return mixed
- */
- public static function getValidTask()
- {
- return self::where('status', PushConst::STATUS_TODO)
- ->where('select_user_status', PushConst::SELECT_USER_OK)
- ->where('push_time', '<=', date('Y-m-d H:i:s'))
- ->orderBy('push_time', 'ASC')
- ->first();
- }
- /**
- * @return mixed
- */
- public static function getAllValidTasks()
- {
- $result = self::where('status', PushConst::STATUS_SUCCESS)
- ->where('select_user_status', PushConst::SELECT_USER_OK)
- ->where('push_time', '<=', date('Y-m-d H:i:s'))
- ->orderBy('push_time', 'ASC')
- ->get();
- return $result ? $result->toArray() : [];
- }
- }
|