UserRelatives.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 用户亲属模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class UserRelatives extends Model
  11. {
  12. const IS_DEL_YES = 1;
  13. const IS_DEL_NO = 0;
  14. const RELATIVES_IS_SHOW = [
  15. self::IS_DEL_YES => '已删除',
  16. self::IS_DEL_NO => '未删除'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'user_relatives';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取会员亲属列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: ZQ
  32. * Date: 2022/11/11
  33. */
  34. public static function getrelativesList(int $page, int $limit, string $keywords)
  35. {
  36. $list = static::select(['user_relatives.*','user.user_real_name'])
  37. ->where(['relatives_del'=>static::IS_DEL_NO])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('relatives_user_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->leftJoin('user','user_id','=','user_relatives.relatives_user_id')
  42. ->orderBy('relatives_add_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get()
  45. ->toArray();
  46. $count = static::where(['relatives_del'=>static::IS_DEL_NO])
  47. ->when($keywords != '', function ($query) use ($keywords){
  48. $query->where('relatives_user_name', 'like', '%' . $keywords . '%');
  49. })
  50. ->count();
  51. return [$list, $count];
  52. }
  53. }