Progress.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\api\model\order;
  3. use app\api\model\BaseModel;
  4. class Progress extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'order_progress';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'clock_in_time_text'
  18. ];
  19. public function getTypeList()
  20. {
  21. return ['take' => __('Take'), 'depart' => __('Depart'), 'arrive' => __('Arrive'), 'start' => __('Start'), 'over' => __('Over')];
  22. }
  23. public function getTypeTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  26. $list = $this->getTypeList();
  27. return isset($list[$value]) ? $list[$value] : '';
  28. }
  29. public function getClockInTimeTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['clock_in_time']) ? $data['clock_in_time'] : '');
  32. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  33. }
  34. protected function setClockInTimeAttr($value)
  35. {
  36. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  37. }
  38. public function findByOrderAndType($order_id, $type)
  39. {
  40. return $this->where([
  41. "order_id" => $order_id,
  42. "type" => $type,
  43. ])->find();
  44. }
  45. }