Base.php 2.3 KB

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