Base.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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)->where('order_id', $this->order['id'])
  45. ->where('status', '<>', PayEnum::PAY_STATUS_UNPAID)
  46. ->where('pay_type', PayEnum::METHOD_WECHAT)->order('id', 'desc')->find();
  47. if (!$wechatPay) {
  48. throw new BusinessException('未找到订单微信支付记录');
  49. }
  50. return $wechatPay;
  51. }
  52. /**
  53. * 配送方式转换
  54. *
  55. * @param string $dispatch_type
  56. * @return integer
  57. */
  58. protected function getLogisticsType($dispatch_type)
  59. {
  60. switch ($dispatch_type) {
  61. case 'express':
  62. $logistics_type = 1;
  63. break;
  64. case 'store_delivery':
  65. $logistics_type = 2;
  66. break;
  67. case 'autosend':
  68. $logistics_type = 3;
  69. break;
  70. case 'custom':
  71. $logistics_type = 3;
  72. break;
  73. case 'selfetch':
  74. $logistics_type = 4;
  75. break;
  76. default:
  77. $logistics_type = 1;
  78. break;
  79. }
  80. return $logistics_type;
  81. }
  82. }