refill_task.model.php 2.0 KB

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