MiniOrderService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace crmeb\services\easywechat\orderShipping;
  3. use crmeb\services\easywechat\Application;
  4. use crmeb\services\SystemConfigService;
  5. use EasyWeChat\Core\Exceptions\HttpException;
  6. class MiniOrderService
  7. {
  8. /**
  9. * @var Application
  10. */
  11. protected static $instance;
  12. /**
  13. * @param array $config
  14. * @return array[]
  15. *
  16. * @date 2023/05/09
  17. * @author yyw
  18. */
  19. protected static function options(array $config = [])
  20. {
  21. $payment = SystemConfigService::more(['routine_appId', 'routine_appsecret', 'pay_weixin_mchid', 'pay_new_weixin_open', 'pay_new_weixin_mchid', 'wechat_token', 'wechat_encodingaeskey']);
  22. return [
  23. 'mini_program' => [
  24. 'app_id' => $payment['routine_appId'] ?? '',
  25. 'secret' => $payment['routine_appsecret'] ?? '',
  26. 'merchant_id' => empty($payment['pay_new_weixin_open']) ? trim($payment['pay_weixin_mchid']) : trim($payment['pay_new_weixin_mchid']),
  27. ]
  28. ];
  29. }
  30. /**
  31. * 初始化
  32. * @param bool $cache
  33. * @return Application
  34. */
  35. protected static function application($cache = false)
  36. {
  37. (self::$instance === null || $cache === true) && (self::$instance = new Application(self::options()));
  38. return self::$instance;
  39. }
  40. protected static function order()
  41. {
  42. return self::application()->order_ship;
  43. }
  44. /**
  45. * 上传订单
  46. * @param string $out_trade_no 订单号(商城订单好)
  47. * @param int $logistics_type 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
  48. * @param array $shipping_list 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10]
  49. * @param string $payer_openid 支付者,支付者信息
  50. * @param int $delivery_mode 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
  51. * @param bool $is_all_delivered 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false
  52. * @return array
  53. *
  54. * @throws HttpException
  55. * @date 2023/05/09
  56. * @author yyw
  57. */
  58. public static function shippingByTradeNo(string $out_trade_no, int $logistics_type, array $shipping_list, string $payer_openid, string $path, int $delivery_mode = 1, bool $is_all_delivered = true)
  59. {
  60. return self::order()->shippingByTradeNo($out_trade_no, $logistics_type, $shipping_list, $payer_openid, $path, $delivery_mode, $is_all_delivered);
  61. }
  62. /**
  63. * 合单
  64. * @param string $out_trade_no
  65. * @param int $logistics_type
  66. * @param array $sub_orders
  67. * @param string $payer_openid
  68. * @param int $delivery_mode
  69. * @param bool $is_all_delivered
  70. * @return array
  71. * @throws HttpException
  72. *
  73. * @date 2023/05/10
  74. * @author yyw
  75. */
  76. public static function combinedShippingByTradeNo(string $out_trade_no, int $logistics_type, array $sub_orders, string $payer_openid, int $delivery_mode = 2, bool $is_all_delivered = false)
  77. {
  78. return self::order()->combinedShippingByTradeNo($out_trade_no, $logistics_type, $sub_orders, $payer_openid, $delivery_mode, $is_all_delivered);
  79. }
  80. /**
  81. * 签收通知
  82. * @param string $merchant_trade_no
  83. * @param string $received_time
  84. * @return array
  85. *
  86. * @date 2023/05/09
  87. * @author yyw
  88. */
  89. public static function notifyConfirmByTradeNo(string $merchant_trade_no, string $received_time)
  90. {
  91. return self::order()->notifyConfirmByTradeNo($merchant_trade_no, $received_time);
  92. }
  93. /**
  94. * 判断是否开通
  95. * @return bool
  96. * @throws HttpException
  97. *
  98. * @date 2023/05/17
  99. * @author yyw
  100. */
  101. public static function isManaged()
  102. {
  103. return self::order()->checkManaged();
  104. }
  105. /**
  106. * 设置小修跳转路径
  107. * @param $path
  108. * @return array
  109. * @throws HttpException
  110. *
  111. * @date 2023/05/10
  112. * @author yyw
  113. */
  114. public static function setMesJumpPathAndCheck($path)
  115. {
  116. return self::order()->setMesJumpPathAndCheck($path);
  117. }
  118. }