Product.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Models\Product;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Product extends Model
  5. {
  6. protected $table = 'products';
  7. protected $fillable = ['price', 'type','name','name_desc','price_desc','angle_sign_text','template_id', 'given', 'is_default', 'is_enabled', 'sequence','template_type'];
  8. public static function getChargeProduct($template_type)
  9. {
  10. return self::whereIn('products.type', ['WEEK', 'MONTH','QUARTER','HALF_YEAR','YEAR', 'RECHARGE'])
  11. ->where('is_enabled', 1)
  12. ->where('template_type', $template_type)
  13. ->select(
  14. 'products.id',
  15. 'products.price',
  16. 'products.price_desc',
  17. 'products.name',
  18. 'products.name_desc',
  19. 'products.type',
  20. 'products.given',
  21. 'products.is_default',
  22. 'products.sequence',
  23. 'products.angle_sign_text'
  24. )
  25. ->orderBy('sequence')->get();
  26. }
  27. /**
  28. * 获取id下对应的充值和赠送额
  29. * @param $product_id
  30. * @return mixed
  31. */
  32. public static function getProductGivenAmount($product_id)
  33. {
  34. return self::where('id', $product_id)->select('given','price')->first();
  35. }
  36. static function detail($id)
  37. {
  38. return self::find($id);
  39. }
  40. static function getProductsByIds($ids)
  41. {
  42. return self::whereIn('id', $ids)->get();
  43. }
  44. }