1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\model;
- use support\Model;
- class SmartDevicesCategory extends Model
- {
- protected $table = 'smart_devices_category';
- protected $primaryKey = 'category_id';
- protected $dateFormat = 'U';
- const CREATED_AT = 'category_add_time';
- const UPDATED_AT = 'category_update_time';
- /**
- * @Desc 获取父级
- * @Author Gorden
- * @Date 2024/3/8 9:12
- *
- * @param $pid
- * @return array
- */
- public function getParent($pid)
- {
- $parent = self::where('category_id', $pid)->first();
- return $parent ? $parent->toArray() : [];
- }
- /**
- * @Desc 获取所有子集
- * @Author Gorden
- * @Date 2024/3/8 9:39
- *
- * @param $id
- * @return array
- */
- public function getDirectSub($id)
- {
- return self::where('category_pid', $id)->get()->toArray();
- }
- /**
- * @Desc 更新path
- * @Author Gorden
- * @Date 2024/3/8 9:46
- *
- * @param $id
- * @param $path
- * @return int
- */
- public function updatePath($id, $path)
- {
- return self::where('category_id', $id)->update(['category_path' => $path]);
- }
- }
|