UserCollect.php 727 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\model;
  3. use fast\Asset;
  4. use fast\Http;
  5. use fast\Random;
  6. use think\Cache;
  7. use think\Log;
  8. use think\Model;
  9. use think\Request;
  10. class UserCollect extends Model
  11. {
  12. protected $name = "user_collect";
  13. //设置用户收藏
  14. public static function setUserCollect(int $uid, int $marketId)
  15. {
  16. $rows = self::where('user_id', $uid)->where('product_id', $marketId)->find();
  17. if($rows){
  18. return $rows->delete();
  19. }else{
  20. return self::create(['user_id'=>$uid, 'product_id'=>$marketId]);
  21. }
  22. }
  23. //用户
  24. public function users()
  25. {
  26. return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  27. }
  28. }