ShopOrderLogic.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\admin\logic;
  3. use app\admin\model\dao\ShopOrder;
  4. use think\facade\Db;
  5. class ShopOrderLogic
  6. {
  7. // 0待付款 1待发货 2已发货 3取消订单 4.已完成
  8. private static $statusMap = [
  9. ['id' => 0, 'name' => '待付款'],
  10. ['id' => 1, 'name' => '待发货'],
  11. // ['id' => 2, 'name' => '已发货'],
  12. ['id' => 3, 'name' => '取消订单'],
  13. // ['id' => 4, 'name' => '已完成']
  14. ];
  15. /**
  16. * @return array[]
  17. */
  18. public static function getStatusMap(): array
  19. {
  20. return self::$statusMap;
  21. }
  22. public static function editStatus($orderId, $status)
  23. {
  24. $shopOrder = ShopOrder::getOrderById($orderId);
  25. if (empty($shopOrder)) {
  26. return "订单不存在";
  27. }
  28. if ($shopOrder['status'] != $status) {
  29. Db::startTrans();
  30. try {
  31. $result = ShopOrder::editStatus($orderId, $status);
  32. if (!$result) {
  33. Db::rollback();
  34. return "订单更新状态失败";
  35. }
  36. Db::commit();
  37. } catch (\Exception $exception) {
  38. Db::rollback();
  39. return "失败:" . $exception->getMessage();
  40. }
  41. }
  42. return true;
  43. }
  44. }