ProductService.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 updateProductDefault($id, $default) {
  28. if($default){
  29. Product::where('id','!=',0)->update(['is_default'=>0]);
  30. Product::where('id',$id)->update(['is_default'=>1]);
  31. }
  32. if($default == 0){
  33. Product::where('id',$id)->update(['is_default'=>$default]);
  34. }
  35. }
  36. public static function updateProductEnabled($id, $enabled) {
  37. if($enabled !== false){
  38. Product::where('id',$id)->update(['is_enabled'=>$enabled]);
  39. }
  40. }
  41. }