QappPushTask.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Modules\Push\Models;
  3. use App\Consts\PushConst;
  4. use Illuminate\Database\Eloquent\Model;
  5. class QappPushTask extends Model
  6. {
  7. protected $table = 'qapp_push_task';
  8. protected $fillable = ['uid', 'package_id', 'type', 'title', 'content', 'url', 'num',
  9. 'status', 'providers', 'push_time', 'push_filter', 'push_result', 'select_user_status'];
  10. /**
  11. * @param $id
  12. * @return array
  13. */
  14. public static function getPushTaskById($id)
  15. {
  16. if (empty($id)) {
  17. return [];
  18. }
  19. return self::where('id', $id)->first();
  20. }
  21. /**
  22. * @param $id
  23. * @param $data
  24. * @return bool
  25. */
  26. public static function updatePushTask($id, $data): bool
  27. {
  28. if (empty($id) || empty($data)) {
  29. return false;
  30. }
  31. return self::where('id', $id)->update($data);
  32. }
  33. /**
  34. * 更新主任务状态
  35. * @param $id
  36. * @param $status
  37. * @param string $pushResult
  38. * @return bool
  39. */
  40. public static function updatePushTaskStatus($id, $status, string $pushResult = ''): bool
  41. {
  42. if (empty($id)) {
  43. return false;
  44. }
  45. $data = ['status' => $status, 'push_result' => $pushResult, 'updated_at' => date('Y-m-d H:i:s')];
  46. return self::where('id', $id)->update($data);
  47. }
  48. /**
  49. * @return mixed
  50. */
  51. public static function getValidTask()
  52. {
  53. return self::where('status', PushConst::STATUS_TODO)
  54. ->where('select_user_status', PushConst::SELECT_USER_OK)
  55. ->where('push_time', '<=', date('Y-m-d H:i:s'))
  56. ->orderBy('push_time', 'ASC')
  57. ->first();
  58. }
  59. }