| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\api\model\service;
- use app\api\model\BaseModel;
- use think\Model;
- class Category extends BaseModel
- {
- // 表名
- protected $name = 'service_category';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'type_text',
- 'status_text'
- ];
- public function getTypeList()
- {
- return ['app' => __('App'), 'store' => __('Store')];
- }
- public function getStatusList()
- {
- return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
- }
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function store()
- {
- return $this->belongsTo('app\admin\model\Store', 'store_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function fetchServiceCategory($type, $store_id = null)
- {
- $where = [
- "status" => \E_BASE_STATUS::Normal,
- "type" => $type,
- ];
- if ($store_id)
- $where['store_id'] = $store_id;
- return $this->where($where)
- ->order("sort", "desc")
- ->limit(4)
- ->select();
- }
- }
|