OrangeSiteRechargeReportCheckContext.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Modules\OrangeSite\Services;
  3. use App\Modules\Trace\TraceContext;
  4. use RuntimeException;
  5. class OrangeSiteRechargeReportCheckContext
  6. {
  7. /**
  8. * @var string 平台,橙子建站
  9. */
  10. public $platform = 'orange';
  11. /**
  12. * @var 订单的用户 表 users 记录
  13. */
  14. public $user;
  15. /**
  16. * @var 订单信息 表 orders 记录
  17. */
  18. public $order;
  19. /**
  20. * @var 订单关联站点的回传配置信息 表 channel_callback_configs 记录
  21. */
  22. public $channelCallbackConfig;
  23. /**
  24. * @var array 判定过程中的附带信息.
  25. * <pre>
  26. * [
  27. * 'configRate' => 32, // 当前站点设置的回传比例为 32%
  28. * 'reportRate' => 43, // 当前站点实际的回传比例[在本单回传之前的比例] 为 43%
  29. * ]
  30. * </pre>
  31. */
  32. public $reportInfo;
  33. /**
  34. * @var array 根据配置,对当前订单的回传与否的判定结果
  35. * <pre>
  36. * [
  37. * 'result' => true|false , // true-表示订单回传,false-订单不回传
  38. * 'type' => 'xxx', // 不回传的原因:amount_filter-金额过滤
  39. * 'content' => 'xxx', // 具体的提示信息
  40. * 'needRecord' => true | false , // true-需要记录到report_user_charge_records表中,false-不记录
  41. * ]
  42. * <pre>
  43. */
  44. public $result;
  45. /**
  46. * @var TraceContext traceInfo 信息
  47. */
  48. public $traceContext;
  49. public function __construct($user, $order, $channelCallbackConfig, $traceContext, $channelSettingRate = 0)
  50. {
  51. $this->user = $user;
  52. $this->order = $order;
  53. $this->channelCallbackConfig = $channelCallbackConfig;
  54. $this->traceContext = $traceContext;
  55. $this->result = [
  56. 'result' => true,
  57. 'needRecord' => true,
  58. ];
  59. $this->reportInfo = [
  60. 'configRate' => $channelSettingRate,
  61. 'reportRate' => 0
  62. ];
  63. }
  64. public function checkNecessaryInfo()
  65. {
  66. if (!$this->user) {
  67. throw new RuntimeException('用户信息不存在');
  68. }
  69. if (!$this->order) {
  70. throw new RuntimeException('订单信息不存在');
  71. }
  72. if (!$this->channelCallbackConfig) {
  73. throw new RuntimeException('站点回传配置信息不存在');
  74. }
  75. }
  76. }