task.model.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. defined('InShopNC') or exit('Access Invalid!');
  3. class taskModel extends Model
  4. {
  5. const DisposeState = 2;
  6. const FinishState = 3;
  7. const ErrState = 4;
  8. public function __construct()
  9. {
  10. parent::__construct('task');
  11. }
  12. public function getList($condition, $pagesize = '', $field = '*', $order = 'add_time desc', $limit = '', $master = false): array
  13. {
  14. $list = $this->field($field)->where($condition)->page($pagesize)->order($order)->limit($limit)->master($master)->select();
  15. if (empty($list)) return [];
  16. return $list;
  17. }
  18. public function getByHash($hash)
  19. {
  20. $condition['task_hash'] = $hash;
  21. return $this->where($condition)->find();
  22. }
  23. public function UnDispose(): array
  24. {
  25. $condition['is_del'] = 0;
  26. $condition['task_state'] = 1;
  27. $task = $this->where($condition)->order('add_time asc')->find();
  28. if (empty($task)) return [];
  29. return $task;
  30. }
  31. public function Dispose($task_id)
  32. {
  33. $condition['is_del'] = 0;
  34. $condition['task_id'] = $task_id;
  35. return $this->where($condition)->update(
  36. ['task_state' => self::DisposeState, 'dispose_time' => time()]
  37. );
  38. }
  39. public function DisposeErr($task_id, $err_msg)
  40. {
  41. $condition['is_del'] = 0;
  42. $condition['task_id'] = $task_id;
  43. return $this->where($condition)->update(
  44. ['task_state' => self::ErrState, 'task_result' => $err_msg, 'finish_time' => time()]
  45. );
  46. }
  47. public function DisposeFinish($task_id, $result)
  48. {
  49. $condition['is_del'] = 0;
  50. $condition['task_id'] = $task_id;
  51. return $this->where($condition)->update(
  52. ['task_state' => self::FinishState, 'task_result' => $result, 'finish_time' => time()]
  53. );
  54. }
  55. public function Del($task_id)
  56. {
  57. $condition['task_id'] = $task_id;
  58. return $this->where($condition)->update(
  59. ['is_del' => 1]
  60. );
  61. }
  62. }