PayTemplateService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. use App\Modules\OfficialAccount\Models\OfficialAccount;
  11. class PayTemplateService
  12. {
  13. /**
  14. * 获取支付列表类型
  15. * @param int $distribution_channel_id
  16. * @return int
  17. */
  18. public static function getPayTemplate(int $distribution_channel_id){
  19. //没有授权服务号的站点 充值模板默认是1
  20. $offical = OfficialAccount::where('distribution_channel_id',$distribution_channel_id)->where('is_auth',1)->count();
  21. if(!$offical){
  22. return 1;
  23. }
  24. $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->select('product_template_type')->first();
  25. $template_type = 2;
  26. if($res){
  27. $template_type = $res->product_template_type;
  28. }
  29. if(in_array($template_type,[1,2])){
  30. //return $template_type;
  31. }
  32. return $template_type;
  33. }
  34. /**
  35. * 更新或者设置类型
  36. * @param int $distribution_channel_id
  37. * @param int $type
  38. * @return bool
  39. */
  40. public static function setPayTemplate(int $distribution_channel_id,int $type){
  41. if(!in_array($type,[1,2])){
  42. return false;
  43. }
  44. $res = PayTemplate::where('distribution_channel_id',$distribution_channel_id)->first();
  45. if($res){
  46. if($res->product_template_type == $type){
  47. return false;
  48. }
  49. $res->product_template_type = $type;
  50. $res->save();
  51. return true;
  52. }
  53. PayTemplate::create([
  54. 'product_template_type'=>$type,
  55. 'distribution_channel_id'=>$distribution_channel_id
  56. ]);
  57. return true;
  58. }
  59. }