Baseaftersale.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace addons\shopro\library\express\provider;
  3. use addons\shopro\library\express\contract\ExpressInterface;
  4. use app\admin\model\shopro\order\Aftersale;
  5. use app\admin\model\shopro\order\AftersaleExpressLog;
  6. class Baseaftersale implements ExpressInterface
  7. {
  8. public function __construct()
  9. {
  10. }
  11. /**
  12. * 快递查询
  13. *
  14. * @param array $data
  15. * @param mixed $order_express_id
  16. * @return array
  17. */
  18. public function search(array $data, $orderExpress = 0)
  19. {
  20. return null;
  21. }
  22. /**
  23. * 物流信息订阅
  24. *
  25. * @param array $data
  26. * @return void
  27. */
  28. public function subscribe(array $data)
  29. {
  30. error_stop('当前快递驱动不支持物流信息订阅');
  31. }
  32. /**
  33. * 物流信息推送
  34. *
  35. * @param array $data
  36. * @return array
  37. */
  38. public function push(array $data)
  39. {
  40. error_stop('当前快递驱动不支持接受推送');
  41. }
  42. /**
  43. * 电子面单
  44. *
  45. * @param array $data
  46. * @param array $items
  47. * @return array
  48. */
  49. public function eOrder(array $data, $items)
  50. {
  51. error_stop('当前快递驱动不支持电子面单');
  52. }
  53. /**
  54. * 更新包裹信息
  55. *
  56. * @param array $data
  57. * @param mixed $orderExpress
  58. * @return array
  59. */
  60. protected function updateExpress(array $data, $orderExpress)
  61. {
  62. // 更新包裹状态
  63. if (is_numeric($orderExpress)) {
  64. $orderExpress = Aftersale::find($orderExpress);
  65. }
  66. if ($orderExpress) {
  67. $orderExpress->express_status = $data['status'];
  68. $orderExpress->save();
  69. $this->syncTraces($data['traces'], $orderExpress);
  70. }
  71. }
  72. /**
  73. * 更新物流信息
  74. *
  75. * @param array $traces
  76. * @param mixed $orderExpress
  77. * @return void
  78. */
  79. protected function syncTraces($traces, $orderExpress)
  80. {
  81. // 查询现有轨迹记录
  82. $orderExpressLog = AftersaleExpressLog::where('order_aftersale_id', $orderExpress->id)->select();
  83. $log_count = count($orderExpressLog);
  84. if ($log_count > 0) {
  85. // 移除已经存在的记录
  86. array_splice($traces, 0, $log_count);
  87. }
  88. // 增加包裹记录
  89. foreach ($traces as $k => $trace) {
  90. $orderExpressLog = new AftersaleExpressLog();
  91. $orderExpressLog->user_id = $orderExpress['user_id'];
  92. $orderExpressLog->order_id = $orderExpress['order_id'];
  93. $orderExpressLog->order_aftersale_id = $orderExpress['id'];
  94. $orderExpressLog->content = $trace['content'];
  95. $orderExpressLog->change_date = $trace['change_date'];
  96. $orderExpressLog->status = $trace['status'];
  97. $orderExpressLog->save();
  98. }
  99. }
  100. }