DataCollectionLog.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\data\model;
  3. use app\data\controller\api\User;
  4. use think\admin\Model;
  5. use think\db\Query;
  6. use think\facade\Db;
  7. /**
  8. * 收藏模型
  9. * Class DataCollectionLog
  10. * @package app\data\model
  11. * @method static static|Query hasShipyard
  12. */
  13. class DataCollectionLog extends Model
  14. {
  15. public function scopeShow(Query $query,$type='',$uuid,$link_id='',$cate=1)
  16. {
  17. $query->when($type,function ($query) use ($type){
  18. $query->where('type',$type);
  19. })->where('uuid',$uuid)->when($link_id,function ($query) use ($link_id){
  20. $query->where('link_id',$link_id);
  21. })->where('cate',$cate);
  22. }
  23. public function recruitment(){
  24. return $this->belongsTo(DataRecruitment::class,'link_id');
  25. }
  26. public function teachingknowledge(){
  27. return $this->belongsTo(DataTeachingKnowledge::class,'link_id');
  28. }
  29. public function bestknowledge(){
  30. return $this->belongsTo(DataBestKnowledge::class,'link_id');
  31. }
  32. public function joblist(){
  33. return $this->belongsTo(DataUserApplyJobInfo::class,'link_id');
  34. }
  35. public function shipyard(){
  36. return $this->belongsTo(DataShipyard::class,'link_id');
  37. }
  38. public function scopeHasShipyard(Query $query){
  39. $query
  40. ->where('type',5)
  41. ->whereExists(
  42. DataShipyard::where('id',Db::raw("{$this->getTable()}.link_id"))->buildSql()
  43. );
  44. }
  45. public function user(){
  46. return $this->belongsTo(DataUser::class,'uuid');
  47. }
  48. public static function isFav($uuid,$type,$id,$cate=1){
  49. return (bool)self::where('uuid',$uuid)
  50. ->where('cate',$cate)
  51. ->where('type',$type)
  52. ->where('link_id',$id)
  53. ->value('id');
  54. }
  55. public static function saveFav($uuid,$type,$id,$cate=1,$save=true){
  56. if($save==false){
  57. return self::where('uuid',$uuid)
  58. ->where('cate',$cate)
  59. ->where('type',$type)
  60. ->where('link_id',$id)
  61. ->delete();
  62. }
  63. if(self::isFav($uuid,$type,$id,$cate)){
  64. return true;
  65. }
  66. return self::create([
  67. 'uuid'=>$uuid,
  68. 'type'=>$type,
  69. 'link_id'=>$id,
  70. 'cate'=>$cate,
  71. ]);
  72. }
  73. }