12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\data\model;
- use app\data\controller\api\User;
- use think\admin\Model;
- use think\db\Query;
- use think\facade\Db;
- /**
- * 收藏模型
- * Class DataCollectionLog
- * @package app\data\model
- * @method static static|Query hasShipyard
- */
- class DataCollectionLog extends Model
- {
- public function scopeShow(Query $query,$type='',$uuid,$link_id='',$cate=1)
- {
- $query->when($type,function ($query) use ($type){
- $query->where('type',$type);
- })->where('uuid',$uuid)->when($link_id,function ($query) use ($link_id){
- $query->where('link_id',$link_id);
- })->where('cate',$cate);
- }
- public function recruitment(){
- return $this->belongsTo(DataRecruitment::class,'link_id');
- }
- public function teachingknowledge(){
- return $this->belongsTo(DataTeachingKnowledge::class,'link_id');
- }
- public function bestknowledge(){
- return $this->belongsTo(DataBestKnowledge::class,'link_id');
- }
- public function joblist(){
- return $this->belongsTo(DataUserApplyJobInfo::class,'link_id');
- }
- public function shipyard(){
- return $this->belongsTo(DataShipyard::class,'link_id');
- }
- public function scopeHasShipyard(Query $query){
- $query
- ->where('type',5)
- ->whereExists(
- DataShipyard::where('id',Db::raw("{$this->getTable()}.link_id"))->buildSql()
- );
- }
- public function user(){
- return $this->belongsTo(DataUser::class,'uuid');
- }
- public static function isFav($uuid,$type,$id,$cate=1){
- return (bool)self::where('uuid',$uuid)
- ->where('cate',$cate)
- ->where('type',$type)
- ->where('link_id',$id)
- ->value('id');
- }
- public static function saveFav($uuid,$type,$id,$cate=1,$save=true){
- if($save==false){
- return self::where('uuid',$uuid)
- ->where('cate',$cate)
- ->where('type',$type)
- ->where('link_id',$id)
- ->delete();
- }
- if(self::isFav($uuid,$type,$id,$cate)){
- return true;
- }
- return self::create([
- 'uuid'=>$uuid,
- 'type'=>$type,
- 'link_id'=>$id,
- 'cate'=>$cate,
- ]);
- }
- }
|