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; } public static function getList($page, $limit, $where) { $model = new \app\common\model\ShopOrder(); foreach ($where as $key => $val) { if ($val[0] == 'status') { $where[$key][0] = 'o.status'; } if ($val[0] == 'created_time') { $where[$key][0] = 'o.created_time'; $where[$key][2] = sr_getcurtime($where[$key][2]); } if ($val[0] == 'order_type') { $where[$key][0] = 'o.order_type'; } } $count = $model ->alias('o') ->with(['goods']) ->where($where) // ->where('o.status', '<>', 3) ->leftJoin('user u', 'u.id = o.user_id') ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id') ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile') ->count(); $list = $model ->alias('o') ->with(['goods']) ->where($where) // ->where('o.status', '<>', 3) ->leftJoin('user u', 'u.id = o.user_id') ->leftJoin('shop_order_shipping s', 's.order_id = o.order_id') ->field('o.*,u.mobile,s.sp_id,s.sp_name,s.sp_mergename,s.sp_mobile') ->order('o.order_id desc') ->withAttr('order_sn', function ($val, $data) { return '编号:' . $val; }) ->page($page, $limit) ->select()->toArray(); foreach ($list as $k => $v) { $goods_id = $v['goods'][0]['goods_id']; $goods_info = ShopGoods::getGoodsById($goods_id); if ($goods_info) { $list[$k]['cost_price'] = $goods_info['cost_price']; } else { $list[$k]['cost_price'] = 0; } if ($v['status'] == 5 || $v['status'] == 6) { // 新的地址 $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find(); $newAddress_info = UserAddress::getUserAddress($ygOrderInfo['address_id']); $list[$k]['sp_id'] = 99999; $list[$k]['sp_mobile'] = $newAddress_info['mobile']; $list[$k]['sp_name'] = $newAddress_info['name']; $list[$k]['sp_mergename'] = $newAddress_info['mergename']; } } return [$count, $list]; } }