QappPushTask.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 'qapp_account', 'pv', 'uv'];
  11. /**
  12. * @param $id
  13. * @return array
  14. */
  15. public static function getPushTaskById($id)
  16. {
  17. if (empty($id)) {
  18. return [];
  19. }
  20. return self::where('id', $id)->first();
  21. }
  22. /**
  23. * @param $id
  24. * @param $data
  25. * @return bool
  26. */
  27. public static function updatePushTask($id, $data): bool
  28. {
  29. if (empty($id) || empty($data)) {
  30. return false;
  31. }
  32. return self::where('id', $id)->update($data);
  33. }
  34. /**
  35. * 更新主任务状态
  36. * @param $id
  37. * @param $status
  38. * @param $result
  39. * @return bool
  40. */
  41. public static function updateMainTaskStatus($id, $status, $result = ''): bool
  42. {
  43. if (empty($id)) {
  44. return false;
  45. }
  46. $pushResult = is_string($result) ? $result : json_encode(compact('result'), JSON_UNESCAPED_UNICODE);
  47. $data = ['status' => $status, 'push_result' => $pushResult, 'updated_at' => date('Y-m-d H:i:s')];
  48. return self::where('id', $id)->update($data);
  49. }
  50. /**
  51. * @return mixed
  52. */
  53. public static function getValidTask()
  54. {
  55. return self::where('status', PushConst::STATUS_TODO)
  56. ->where('select_user_status', PushConst::SELECT_USER_OK)
  57. ->where('push_time', '<=', date('Y-m-d H:i:s'))
  58. ->orderBy('push_time', 'ASC')
  59. ->first();
  60. }
  61. /**
  62. * @return mixed
  63. */
  64. public static function getAllValidTasks()
  65. {
  66. $result = self::where('status', PushConst::STATUS_SUCCESS)
  67. ->where('select_user_status', PushConst::SELECT_USER_OK)
  68. ->where('push_time', '<=', date('Y-m-d H:i:s'))
  69. ->orderBy('push_time', 'ASC')
  70. ->get();
  71. return $result ? $result->toArray() : [];
  72. }
  73. }