QappPushTask.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 $result
  38. * @return bool
  39. */
  40. public static function updateMainTaskStatus($id, $status, $result = ''): bool
  41. {
  42. if (empty($id)) {
  43. return false;
  44. }
  45. $pushResult = is_string($result) ? $result : json_encode(compact('result'), JSON_UNESCAPED_UNICODE);
  46. $data = ['status' => $status, 'push_result' => $pushResult, 'updated_at' => date('Y-m-d H:i:s')];
  47. return self::where('id', $id)->update($data);
  48. }
  49. /**
  50. * @return mixed
  51. */
  52. public static function getValidTask()
  53. {
  54. return self::where('status', PushConst::STATUS_TODO)
  55. ->where('select_user_status', PushConst::SELECT_USER_OK)
  56. ->where('push_time', '<=', date('Y-m-d H:i:s'))
  57. ->orderBy('push_time', 'ASC')
  58. ->first();
  59. }
  60. }