ProductService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/4
  6. * Time: 下午2:08
  7. */
  8. namespace App\Modules\Product\Services;
  9. use App\Modules\Product\Models\Product;
  10. class ProductService
  11. {
  12. public static function getChargeProduct($template_type=1){
  13. $res = Product::getChargeProduct($template_type);
  14. return $res;
  15. }
  16. public static function addProduct($params = []) {
  17. $res = Product::create($params);
  18. return $res;
  19. }
  20. public static function getProductSingle($id,$transform=true) {
  21. $res = Product::detail($id);
  22. if($res->type == 'NEW_USER' && $transform){
  23. $res->type = 'TICKET_RECHARGE';
  24. }
  25. return $res;
  26. }
  27. public static function getProductsByIds($ids) {
  28. return Product::getProductsByIds($ids);
  29. }
  30. public static function updateProductDefault($id, $default) {
  31. if($default){
  32. Product::where('id','!=',0)->update(['is_default'=>0]);
  33. Product::where('id',$id)->update(['is_default'=>1]);
  34. }
  35. if($default == 0){
  36. Product::where('id',$id)->update(['is_default'=>$default]);
  37. }
  38. }
  39. public static function updateProductEnabled($id, $enabled) {
  40. if($enabled !== false){
  41. Product::where('id',$id)->update(['is_enabled'=>$enabled]);
  42. }
  43. }
  44. }