RaiseOldGoods.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 养老产品模型
  6. * Class Users
  7. * @package app\admin\model
  8. */
  9. class RaiseOldGoods extends Model
  10. {
  11. const ROLE_STATUS = 1;
  12. const IS_DEL_YES = 1;
  13. const IS_DEL_NO = 0;
  14. const GOODS_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 = 'raise_old_goods';
  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/10/14
  33. */
  34. public static function getGoodsList(int $page, int $limit, string $keywords)
  35. {
  36. $list = static::select(['raise_old_goods.*','category.category_name','merchant_shop.shop_name'])
  37. ->where(['goods_del'=>static::IS_DEL_NO])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('goods_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->leftJoin('category','category_id','=','raise_old_goods.goods_category_id')
  42. ->leftJoin('merchant_shop','shop_id','=','raise_old_goods.goods_shop_id')
  43. ->orderBy('goods_add_time','DESC')
  44. ->orderBy('goods_id','DESC')
  45. ->forPage($page, $limit)
  46. ->get();
  47. $count = static::where(['goods_del'=>static::IS_DEL_NO])
  48. ->when($keywords != '', function ($query) use ($keywords){
  49. $query->where('goods_name', 'like', '%' . $keywords . '%');
  50. })
  51. ->count();
  52. return [$list, $count];
  53. }
  54. /**
  55. * Notes:获取所有养老产品
  56. * @return array
  57. * User: ZQ
  58. * Date: 2022/10/14
  59. */
  60. public static function getGoodsAll()
  61. {
  62. $list = static::select(['goods_id','goods_name'])
  63. ->where(['goods_del'=>static::IS_DEL_NO])
  64. ->orderBy('goods_add_time','DESC')
  65. ->get();
  66. return $list;
  67. }
  68. /**
  69. * Notes:获取养老产品名称
  70. * @param string $account
  71. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  72. * User: ZQ
  73. * Date: 2022/10/14
  74. */
  75. public static function bookMation($admin_cinema)
  76. {
  77. $where = [];
  78. $where['goods_del'] = static::IS_DEL_NO;
  79. $mation = static::where($where)
  80. ->when($admin_cinema != '', function ($query) use ($admin_cinema){
  81. $query->whereIn('goods_id', $admin_cinema);
  82. })
  83. ->get('goods_name');
  84. return $mation;
  85. }
  86. }