LifeFarmGoods.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 绿色蔬菜模型
  7. * Class Users
  8. * @packagegoods app\admin\model
  9. */
  10. class LifeFarmGoods 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_farm_goods';
  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/11/4
  34. */
  35. public static function getFarmGoodsList(int $page, int $limit, string $keywords)
  36. {
  37. $list = static::select('*')
  38. ->where(['goods_is_del'=>static::IS_DEL_NO])
  39. ->with(['Shop','Category','MedicalCarePostage'])
  40. ->when($keywords != '', function ($query) use ($keywords){
  41. $query->where('goods_name', 'like', '%' . $keywords . '%');
  42. })
  43. ->orderBy('goods_sort','DESC')
  44. ->forPage($page, $limit)
  45. ->get();
  46. $count = static::where(['goods_is_del'=>static::IS_DEL_NO])
  47. ->when($keywords != '', function ($query) use ($keywords){
  48. $query->where('goods_name', 'like', '%' . $keywords . '%');
  49. })
  50. ->count();
  51. return [$list, $count];
  52. }
  53. //关联店铺
  54. public function Shop(){
  55. return $this->belongsTo(MerchantShop::class,'goods_shop_id','shop_id');
  56. }
  57. //关联分类
  58. public function Category(){
  59. return $this->belongsTo(Category::class,'goods_category_id','category_id');
  60. }
  61. //关联运费模板
  62. public function MedicalCarePostage(){
  63. return $this->belongsTo(MedicalCarePostage::class,'goods_postage_id','postage_id');
  64. }
  65. //时间格式
  66. public function getGoodsCreateTimeAttribute($value)
  67. {
  68. return date('Y-m-d H:i:s', $value);
  69. }
  70. }