LifePackage.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 LifePackage extends Model
  11. {
  12. const ROLE_STATUS = 1;
  13. const IS_DEL_YES = 1;
  14. const IS_DEL_NO = 0;
  15. const GOODS_IS_SHOW = [
  16. self::IS_DEL_YES => '已删除',
  17. self::IS_DEL_NO => '未删除'
  18. ];
  19. /**
  20. * The table associated with the model.
  21. *
  22. * @var string
  23. */
  24. protected $table = 'life_package';
  25. public $timestamps = false;
  26. /**
  27. * Notes:获取套餐列表
  28. * @param string $keywords
  29. * @param int $page
  30. * @param int $limit
  31. * @return array
  32. * User: YCP
  33. * Date: 2022/10/18
  34. */
  35. public static function getPackageList(int $page, int $limit, string $keywords,$package_type)
  36. {
  37. $list = static::select('*')
  38. ->where(['package_is_del'=>static::IS_DEL_NO])
  39. ->when($keywords != '', function ($query) use ($keywords){
  40. $query->where('package_name', 'like', '%' . $keywords . '%');
  41. })
  42. ->when($package_type != '', function ($query) use ($package_type){
  43. $query->where('package_type',$package_type);
  44. })
  45. ->orderBy('package_create_time','DESC')
  46. ->forPage($page, $limit)
  47. ->get();
  48. foreach ($list as &$v) {
  49. $v['package_tags'] = explode(",",$v['package_tags']);
  50. }
  51. $count = static::where(['package_is_del'=>static::IS_DEL_NO])
  52. ->when($keywords != '', function ($query) use ($keywords){
  53. $query->where('package_name', 'like', '%' . $keywords . '%');
  54. })
  55. ->when($package_type != '', function ($query) use ($package_type){
  56. $query->where('package_type',$package_type);
  57. })
  58. ->count();
  59. return [$list, $count];
  60. }
  61. /**
  62. * Notes:获取套餐列表
  63. * @return array
  64. * User: YCP
  65. * Date: 2022/10/18
  66. */
  67. public static function getPackageAll()
  68. {
  69. $list = static::select(['package_id','package_name'])
  70. ->where(['package_is_del'=>static::IS_DEL_NO])
  71. ->orderBy('package_create_time','DESC')
  72. ->get();
  73. return $list;
  74. }
  75. /**
  76. * Notes:获取套餐名称
  77. * @param string $account
  78. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  79. * User: YCP
  80. * Date: 2022/10/18
  81. */
  82. public static function packageMation($admin_package)
  83. {
  84. $where = [];
  85. $where['package_is_del'] = static::IS_DEL_NO;
  86. $mation = static::where($where)
  87. ->when($admin_package != '', function ($query) use ($admin_package){
  88. $query->whereIn('package_id', $admin_package);
  89. })
  90. ->get('package_name');
  91. return $mation;
  92. }
  93. /**
  94. * Notes:检测套餐名是否存在
  95. * @param $doctor_name
  96. * @param $doctor_mobile
  97. * @return bool
  98. * User: YCP
  99. * Date: 2022/10/18
  100. * 验证条件:套餐名存在的情况下
  101. */
  102. public static function checkPackageName($package_name)
  103. {
  104. return static::where(['package_name' => $package_name, 'package_is_del' => static::IS_DEL_NO])->exists();
  105. }
  106. //时间格式
  107. public function getPackageCreateTimeAttribute($value)
  108. {
  109. return date('Y-m-d H:i:s', $value);
  110. }
  111. }