Package.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Package extends Model
  11. {
  12. const PACKAGE_PUT_SHELVES = '1';
  13. const PACKAGE_LOWER_SHELF = '2';
  14. const PACKAGE_STATUS = [
  15. self::PACKAGE_PUT_SHELVES => '上架',
  16. self::PACKAGE_LOWER_SHELF => '下架'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'package';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取角色列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: QJF
  32. * Date: 2022/9/19
  33. */
  34. public static function getPackageList(int $page, int $limit, $keywords)
  35. {
  36. $list = static::select('*')
  37. ->where(['package_is_del'=>0])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('package_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->orderBy('package_update_time','DESC')
  42. ->forPage($page, $limit)
  43. ->get();
  44. $count = static::where(['package_is_del'=>0])
  45. ->when($keywords != '', function ($query) use ($keywords){
  46. $query->where('package_name', 'like', '%' . $keywords . '%');
  47. })->count();
  48. return [$list, $count];
  49. }
  50. public function getPackageCreateTimeAttribute($value)
  51. {
  52. return date('Y-m-d H:i:s', $value);
  53. }
  54. public function getPackageUpdateTimeAttribute($value)
  55. {
  56. return date('Y-m-d H:i:s', $value);
  57. }
  58. public function setPackageUpdateTimeAttribute($value)
  59. {
  60. return strtotime($value);
  61. }
  62. public function getPackagePriceAttribute($value)
  63. {
  64. $id = json_decode($this->package_product_ids);
  65. $price = PackageGoods::whereIn('goods_id',$id)->sum('goods_price');
  66. return $price;
  67. }
  68. /**
  69. * Notes:获取单个套餐包详情
  70. * @param int $package_id
  71. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  72. * User: yym
  73. * Date: 2022/9/22
  74. */
  75. public static function getInfo(int $package_id)
  76. {
  77. $info = static::where(['package_id' => $package_id])->first();
  78. $info['goods'] = PackageGoods::getPackageGoodsListNew(json_decode($info['package_product_ids'], true));
  79. return $info;
  80. }
  81. }