StoreBargainUser.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\activity\bargain;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 参与砍价Model
  18. * Class StoreBargainUser
  19. * @package app\model\activity\bargain
  20. */
  21. class StoreBargainUser extends BaseModel
  22. {
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'store_bargain_user';
  33. use ModelTrait;
  34. /**
  35. * 一对一关联
  36. * 商品关联商品商品详情
  37. * @return \think\model\relation\HasOne
  38. */
  39. public function getBargain()
  40. {
  41. return $this->hasOne(StoreBargain::class, 'id', 'bargain_id')->bind(['title', 'image', 'datatime' => 'stop_time', 'people_num']);
  42. }
  43. /**
  44. * 一对一关联
  45. * 获取砍价用户
  46. * @return \think\model\relation\HasOne
  47. */
  48. public function getUser()
  49. {
  50. return $this->hasOne(User::class, 'uid', 'uid', false)->bind(['avatar', 'nickname', 'delete_time']);
  51. }
  52. /**
  53. * 用户搜索器
  54. * @param Model $query
  55. * @param $value
  56. * @param $data
  57. */
  58. public function searchUidAttr($query, $value, $data)
  59. {
  60. $query->where('uid', $value);
  61. }
  62. /**
  63. * 商品ID搜索器
  64. * @param Model $query
  65. * @param $value
  66. * @param $data
  67. */
  68. public function searchBargainIdAttr($query, $value, $data)
  69. {
  70. $query->where('bargain_id', $value);
  71. }
  72. /**
  73. * 状态搜索器
  74. * @param Model $query
  75. * @param $value
  76. * @param $data
  77. */
  78. public function searchStatusAttr($query, $value, $data)
  79. {
  80. if ($value != '') $query->where('status', $value);
  81. }
  82. /**
  83. * 是否删除搜索器
  84. * @param Model $query
  85. * @param $value
  86. * @param $data
  87. */
  88. public function searchIsDelAttr($query, $value, $data)
  89. {
  90. $query->where('is_del', $value);
  91. }
  92. }