链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Market extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_market';
  11. protected $dateFormat = 'U';
  12. public function setImgsAttribute($imgs)
  13. {
  14. if ($imgs){
  15. $this->attributes['imgs'] = implode(',',$imgs);
  16. }
  17. }
  18. public function getImgsAttribute($imgs)
  19. {
  20. return explode(',',$imgs);
  21. }
  22. public function mp(){
  23. return $this->hasOne('\App\Models\LanzuMpInfo','id','mp_id');
  24. }
  25. /**
  26. * 获取市场数组
  27. */
  28. public static function getMarketArray($where = [], $options = [])
  29. {
  30. $model = self::whereNull('deleted_at');
  31. // ->where('status',1)
  32. if(!empty($where)){
  33. $model->where($where);
  34. }
  35. $list = $model->pluck('id','name')->toArray();
  36. if(!empty($options)){
  37. $new = array_merge($options,$list);
  38. return array_flip($new);
  39. }else{
  40. return array_flip($list);
  41. }
  42. }
  43. /**
  44. * 获取单个市场信息
  45. */
  46. public static function getMarketInfo($id,$field = '*')
  47. {
  48. return self::select($field)->find($id);
  49. }
  50. /**
  51. * 获取市场信息
  52. * @return \Illuminate\Http\JsonResponse
  53. */
  54. public static function getMarket()
  55. {
  56. $markets = self::select('id','name')
  57. ->where('status',1)
  58. ->whereNull('deleted_at')
  59. ->get();
  60. $item = [];
  61. foreach ($markets as $market) {
  62. $item[$market->id] = $market->name;
  63. }
  64. return $item;
  65. }
  66. }