Store.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\admin\model\store;
  3. use app\admin\model\Area;
  4. use think\Model;
  5. class Store extends Model
  6. {
  7. // 表名
  8. protected $name = 'store';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'integer';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'status_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['hidden' => __('Hidden'), 'checking' => __('Checking'), 'normal' => __('Normal')];
  22. }
  23. public function getStatusTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  26. $list = $this->getStatusList();
  27. return isset($list[$value]) ? $list[$value] : '';
  28. }
  29. public function fetchByAgency($admin)
  30. {
  31. return $this
  32. ->where("status", \E_BASE_STATUS::Normal)
  33. ->where("city_code", "in", explode(",", $admin["city_codes"]))
  34. ->select();
  35. }
  36. public function area()
  37. {
  38. return $this->belongsTo(Area::class, 'city_code', 'area_code', [], 'LEFT')->setEagerlyType(0);
  39. }
  40. }