Order.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\controller;
  13. use think\response\Json;
  14. use app\api\model\Order as OrderModel;
  15. use app\api\model\Setting as SettingModel;
  16. use app\api\service\User as UserService;
  17. use app\api\service\Order as OrderService;
  18. use cores\exception\BaseException;
  19. /**
  20. * 我的订单控制器
  21. * Class Order
  22. * @package app\api\controller
  23. */
  24. class Order extends Controller
  25. {
  26. /**
  27. * 我的订单列表
  28. * @param string $dataType 订单类型
  29. * @return Json
  30. * @throws BaseException
  31. * @throws \think\db\exception\DbException
  32. */
  33. public function list(string $dataType): Json
  34. {
  35. $model = new OrderModel;
  36. $list = $model->getList($dataType);
  37. return $this->renderSuccess(compact('list'));
  38. }
  39. /**
  40. * 订单详情信息
  41. * @param int $orderId 订单ID
  42. * @return Json
  43. * @throws BaseException
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function detail(int $orderId): Json
  49. {
  50. // 订单详情
  51. $model = OrderModel::getUserOrderDetail($orderId);
  52. return $this->renderSuccess([
  53. 'order' => $model, // 订单详情
  54. 'setting' => [
  55. // 积分名称
  56. 'points_name' => SettingModel::getPointsName(),
  57. ],
  58. ]);
  59. }
  60. /**
  61. * 获取物流跟踪信息
  62. * @param int $orderId 订单ID
  63. * @return Json
  64. * @throws BaseException
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. */
  69. public function express(int $orderId): Json
  70. {
  71. $service = new OrderService;
  72. $express = $service->express($orderId);
  73. return $this->renderSuccess(compact('express'));
  74. }
  75. /**
  76. * 取消订单
  77. * @param int $orderId
  78. * @return Json
  79. * @throws BaseException
  80. */
  81. public function cancel(int $orderId): Json
  82. {
  83. $model = OrderModel::getDetail($orderId);
  84. if ($model->cancel()) {
  85. return $this->renderSuccess($model->getMessage());
  86. }
  87. return $this->renderError($model->getError() ?: '订单取消失败');
  88. }
  89. /**
  90. * 确认收货
  91. * @param int $orderId
  92. * @return Json
  93. * @throws BaseException
  94. */
  95. public function receipt(int $orderId): Json
  96. {
  97. $model = OrderModel::getDetail($orderId);
  98. if ($model->receipt()) {
  99. return $this->renderSuccess('确认收货成功');
  100. }
  101. return $this->renderError($model->getError());
  102. }
  103. /**
  104. * 获取当前用户待处理的订单数量
  105. * @return Json
  106. * @throws BaseException
  107. */
  108. public function todoCounts(): Json
  109. {
  110. $model = new OrderModel;
  111. $counts = $model->getTodoCounts();
  112. return $this->renderSuccess(compact('counts'));
  113. }
  114. }