| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\admin\logic;
- use app\admin\model\dao\ShopOrder;
- use think\facade\Db;
- class ShopOrderLogic
- {
- // 0待付款 1待发货 2已发货 3取消订单 4.已完成
- private static $statusMap = [
- ['id' => 0, 'name' => '待付款'],
- ['id' => 1, 'name' => '待发货'],
- // ['id' => 2, 'name' => '已发货'],
- ['id' => 3, 'name' => '取消订单'],
- // ['id' => 4, 'name' => '已完成']
- ];
- /**
- * @return array[]
- */
- public static function getStatusMap(): array
- {
- return self::$statusMap;
- }
- public static function editStatus($orderId, $status)
- {
- $shopOrder = ShopOrder::getOrderById($orderId);
- if (empty($shopOrder)) {
- return "订单不存在";
- }
- if ($shopOrder['status'] != $status) {
- Db::startTrans();
- try {
- $result = ShopOrder::editStatus($orderId, $status);
- if (!$result) {
- Db::rollback();
- return "订单更新状态失败";
- }
- Db::commit();
- } catch (\Exception $exception) {
- Db::rollback();
- return "失败:" . $exception->getMessage();
- }
- }
- return true;
- }
- }
|