Base.php 2.3 KB

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