12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- defined('InShopNC') or exit('Access Invalid!');
- class taskModel extends Model
- {
- const DisposeState = 2;
- const FinishState = 3;
- const ErrState = 4;
- public function __construct()
- {
- parent::__construct('task');
- }
- public function getList($condition, $pagesize = '', $field = '*', $order = 'add_time desc', $limit = '', $master = false): array
- {
- $list = $this->field($field)->where($condition)->page($pagesize)->order($order)->limit($limit)->master($master)->select();
- if (empty($list)) return [];
- return $list;
- }
- public function getByHash($hash)
- {
- $condition['task_hash'] = $hash;
- return $this->where($condition)->find();
- }
- public function UnDispose(): array
- {
- $condition['is_del'] = 0;
- $condition['task_state'] = 1;
- $task = $this->where($condition)->order('add_time asc')->find();
- if (empty($task)) return [];
- return $task;
- }
- public function Dispose($task_id)
- {
- $condition['is_del'] = 0;
- $condition['task_id'] = $task_id;
- return $this->where($condition)->update(
- ['task_state' => self::DisposeState, 'dispose_time' => time()]
- );
- }
- public function DisposeErr($task_id, $err_msg)
- {
- $condition['is_del'] = 0;
- $condition['task_id'] = $task_id;
- return $this->where($condition)->update(
- ['task_state' => self::ErrState, 'task_result' => $err_msg, 'finish_time' => time()]
- );
- }
- public function DisposeFinish($task_id, $result)
- {
- $condition['is_del'] = 0;
- $condition['task_id'] = $task_id;
- return $this->where($condition)->update(
- ['task_state' => self::FinishState, 'task_result' => $result, 'finish_time' => time()]
- );
- }
- public function Del($task_id)
- {
- $condition['task_id'] = $task_id;
- return $this->where($condition)->update(
- ['is_del' => 1]
- );
- }
- }
|