PayTemplateService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2018/9/18
  6. * Time: 18:30
  7. */
  8. namespace App\Modules\Channel\Services;
  9. use App\Modules\Channel\Models\PayTemplate;
  10. class PayTemplateService
  11. {
  12. /**
  13. * 获取支付列表类型
  14. * @param int $distribution_channel_id
  15. * @return int
  16. */
  17. public static function getPayTemplate(int $distribution_channel_id){
  18. $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->select('product_template_type')->first();
  19. $template_type = 2;
  20. if($res){
  21. return $template_type = $res->product_template_type;
  22. }
  23. if(in_array($template_type,[1,2])){
  24. return $template_type;
  25. }
  26. return 2;
  27. }
  28. /**
  29. * 更新或者设置类型
  30. * @param int $distribution_channel_id
  31. * @param int $type
  32. * @return bool
  33. */
  34. public static function setPayTemplate(int $distribution_channel_id,int $type){
  35. if(!in_array($type,[1,2])){
  36. return false;
  37. }
  38. $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->first();
  39. if($res){
  40. if($res->product_template_type == $type){
  41. return false;
  42. }
  43. $res->product_template_type = $type;
  44. $res->save();
  45. return true;
  46. }
  47. PayTemplate::create([
  48. 'product_template_type'=>$type,
  49. 'distribution_channel_id'=>$distribution_channel_id
  50. ]);
  51. return true;
  52. }
  53. }