Express.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\shopro\controller\order;
  3. use addons\shopro\controller\Common;
  4. use app\admin\model\shopro\order\Express as OrderExpressModel;
  5. use addons\shopro\library\express\Express as ExpressLib;
  6. use think\Db;
  7. //物流
  8. class Express extends Common
  9. {
  10. protected $noNeedLogin = ['push'];
  11. protected $noNeedRight = ['*'];
  12. public function index()
  13. {
  14. $user = auth_user();
  15. $order_sn = $this->request->param('order_sn');
  16. $order_id = Db::name('shopro_order')->where('order_sn',$order_sn)->value('id');
  17. // 更新包裹信息(5分钟缓存)
  18. (new ExpressLib)->updateOrderExpress($order_id);
  19. $expresses = OrderExpressModel::with(['logs'/*, 'items' => function ($query) use ($order_id) {
  20. return $query->where('order_id', $order_id);
  21. }*/])->where('user_id', $user->id)->where('order_id', $order_id)->select();
  22. $address = Db::name('shopro_order_address')->where('order_id',$order_id)->find();
  23. $items = Db::name('shopro_order_item')->where('order_id',$order_id)->column('goods_image');
  24. $items = array_domain_image($items);
  25. $result = [
  26. 'order_sn' => $order_sn,
  27. 'address' => $address,
  28. 'expresses' => $expresses,
  29. 'goods_image' => $items
  30. ];
  31. $this->success('获取成功', $result);
  32. }
  33. public function detail()
  34. {
  35. $user = auth_user();
  36. $id = $this->request->param('id');
  37. $order_id = $this->request->param('order_id');
  38. // 更新包裹信息(5分钟缓存)
  39. (new ExpressLib)->updateOrderExpress($order_id);
  40. $express = OrderExpressModel::with(['logs', 'items' => function ($query) use ($order_id) {
  41. return $query->where('order_id', $order_id);
  42. }])->where('user_id', $user->id)->where('order_id', $order_id)->where('id', $id)->find();
  43. $this->success('获取成功', $express);
  44. }
  45. /**
  46. * 接受物流推送
  47. *
  48. * @param Request $request
  49. * @return void
  50. */
  51. public function push()
  52. {
  53. //Callback区分 发货寄出 与 退货寄回
  54. $data = $this->request->param();
  55. $expressLib = new ExpressLib();
  56. $result = $expressLib->push($data);
  57. return response($result, 200, [], 'json');
  58. }
  59. }