Base.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\common\Service\Order\ShippingInfo;
  3. use app\common\Enum\PayEnum;
  4. use app\common\exception\BusinessException;
  5. use app\common\model\pay\Index as PayModel;
  6. use think\helper\Str;
  7. use app\common\Enum\GoodsEnum;
  8. class Base
  9. {
  10. protected $order = null;
  11. //protected $deliveryTypes = [];
  12. public function __construct($order)
  13. {
  14. $this->order = $order;
  15. // $this->deliveryTypes = GoodsEnum::getDeliveryTypeList();
  16. }
  17. /**
  18. * 设置微信支付相关的参数
  19. *
  20. * @param array $uploadParams
  21. * @param \think\Model $wechatPay
  22. * @return array
  23. */
  24. protected function setWechatParams($uploadParams, $wechatPay)
  25. {
  26. $order_key = [
  27. 'order_number_type' => 2,
  28. 'transaction_id' => $wechatPay->transaction_id,
  29. 'out_trade_no' => $wechatPay->pay_sn,
  30. ];
  31. $payer = [
  32. 'openid' => $wechatPay['buyer_info']
  33. ];
  34. foreach ($uploadParams as &$params) {
  35. $params['order_key'] = $order_key;
  36. $params['payer'] = $payer;
  37. }
  38. return $uploadParams;
  39. }
  40. /**
  41. * 获取订单中的微信支付 pay 记录
  42. *
  43. * @return think\Model
  44. */
  45. protected function getWechatPay($type = 1)
  46. {
  47. $wechatPay = PayModel::where('order_type', $type)
  48. ->where('order_id', $this->order['id'])
  49. ->where('status', '<>', PayEnum::PAY_STATUS_UNPAID)
  50. ->where('pay_type', PayEnum::METHOD_WECHAT)
  51. ->order('id', 'desc')->find();
  52. if (!$wechatPay) {
  53. throw new BusinessException('未找到订单微信支付记录');
  54. }
  55. return $wechatPay;
  56. }
  57. /**
  58. * 配送方式转换
  59. *
  60. * @param string $deliveryType
  61. * @return integer
  62. */
  63. protected function getLogisticsType($deliveryType)
  64. {
  65. switch ($deliveryType) {
  66. case 'express':
  67. $logistics_type = 1;
  68. break;
  69. case 'store_delivery':
  70. $logistics_type = 2;
  71. break;
  72. case 'autosend':
  73. $logistics_type = 3;
  74. break;
  75. case 'custom':
  76. $logistics_type = 3;
  77. break;
  78. case 'selfetch':
  79. $logistics_type = 4;
  80. break;
  81. default:
  82. $logistics_type = 1;
  83. break;
  84. }
  85. return $logistics_type;
  86. }
  87. }